canonicalize.c 811 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * canonicalize.c -- Return a malloc'd string containing the canonical
  3. * absolute name of the named file. The last file name component need
  4. * not exist, and may be a symlink to a nonexistent file.
  5. * Copyright (C) 2009 STMicroelectronics
  6. * Author: Salvatore Cro <salvatore.cro@st.com>
  7. *
  8. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  9. */
  10. #include <stdlib.h>
  11. #include <limits.h>
  12. #ifdef __USE_GNU
  13. #ifndef PATH_MAX
  14. # ifdef _POSIX_VERSION
  15. # define PATH_MAX _POSIX_PATH_MAX
  16. # else
  17. # ifdef MAXPATHLEN
  18. # define PATH_MAX MAXPATHLEN
  19. # else
  20. # define PATH_MAX 1024
  21. # endif
  22. # endif
  23. #endif
  24. char * canonicalize_file_name (const char *name)
  25. {
  26. char *buf = (char *) malloc(PATH_MAX);
  27. if(unlikely(buf == NULL))
  28. return NULL;
  29. *buf='\0';
  30. return realpath (name, buf);
  31. }
  32. #endif