error.c 495 B

12345678910111213141516171819202122
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include "test_helpers.h"
  6. int main(void) {
  7. chdir("nonexistent");
  8. int err = errno;
  9. printf("errno: %d = %s\n", err, strerror(errno));
  10. perror("perror");
  11. char buf1[256];
  12. int ret1 = strerror_r(err, buf1, 256);
  13. printf("errno: %d = %s, return: %d\n", err, buf1, ret1);
  14. char buf2[3];
  15. int ret2 = strerror_r(err, buf2, 3);
  16. printf("errno: %d = %s, return: %d\n", err, buf2, ret2);
  17. }