realpath.c 501 B

1234567891011121314151617181920212223242526272829
  1. #include <errno.h>
  2. #include <limits.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. int main(void) {
  7. char* path = realpath("stdlib/realpath.c", NULL);
  8. if (!path) {
  9. perror("realpath");
  10. return -1;
  11. }
  12. puts(path);
  13. free(path);
  14. path = malloc(PATH_MAX);
  15. memset(path, 0, PATH_MAX);
  16. realpath("stdlib/realpath.c", path);
  17. if (!path) {
  18. perror("realpath");
  19. free(path);
  20. return -1;
  21. }
  22. puts(path);
  23. free(path);
  24. }