Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #ifndef _NO_GETCWD
  2.  
  3. /*
  4.  * Copyright (C) KolibriOS team 2024. All rights reserved.
  5.  * Distributed under terms of the GNU General Public License
  6. */
  7.  
  8. #include <stdlib.h>
  9. #include <limits.h>
  10.  
  11. #include <sys/errno.h>
  12. #include <sys/unistd.h>
  13. #include <sys/ksys.h>
  14.  
  15. #ifndef _REENT_ONLY
  16.  
  17. char *
  18. _DEFUN (getcwd, (buf, size),
  19.     char *buf _AND
  20.     size_t size)
  21. {
  22.     if (buf != NULL && size == 0)
  23.     {
  24.         errno = EINVAL;
  25.         return NULL;
  26.     }
  27.  
  28.     if (buf == NULL)
  29.     {
  30.         if (size == 0)
  31.             size = PATH_MAX;
  32.  
  33.         buf = malloc(size);
  34.         if (buf == NULL)
  35.         {
  36.             errno = ENOMEM;
  37.             return NULL;
  38.         }
  39.     }
  40.  
  41.     _ksys_getcwd(buf, size);
  42.  
  43.     if (access(buf, R_OK) == -1)
  44.     {
  45.         errno = EACCES;
  46.         return NULL;
  47.     }
  48.  
  49.     return buf;
  50. }
  51.  
  52. #endif /* _REENT_ONLY */
  53. #endif /* !_NO_GETCWD  */
  54.