2
0

tmpnam.c 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "test_helpers.h"
  5. int main(void) {
  6. char *first_null = tmpnam(NULL);
  7. if(first_null == NULL) {
  8. // NOTE: assuming that we can at least get one file name
  9. puts("tmpnam(NULL) returned NULL on first try");
  10. exit(EXIT_FAILURE);
  11. }
  12. printf("%s\n", first_null);
  13. char *second_null = tmpnam(NULL);
  14. if(second_null == NULL) {
  15. // NOTE: assuming that we can at least get one file name
  16. puts("tmpnam(NULL) returned NULL on second try");
  17. exit(EXIT_FAILURE);
  18. }
  19. printf("%s\n", second_null);
  20. if(first_null != second_null) {
  21. puts("tmpnam(NULL) returns different addresses");
  22. exit(EXIT_FAILURE);
  23. }
  24. char buffer[L_tmpnam + 1];
  25. char *buf_result = tmpnam(buffer);
  26. if(buf_result == NULL) {
  27. puts("tmpnam(buffer) failed");
  28. exit(EXIT_FAILURE);
  29. } else if(buf_result != buffer) {
  30. puts("tmpnam(buffer) did not return buffer's address");
  31. exit(EXIT_FAILURE);
  32. }
  33. printf("%s\n", buffer);
  34. return 0;
  35. }