2
0

error.c 624 B

1234567891011121314151617181920212223242526
  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. char buf3[256] = {0};
  18. int ret3 = strerror_r(err, buf3, 0);
  19. printf("errno: %d = %s, return: %d\n", err, buf3, ret3);
  20. }