Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (C) KolibriOS team 2024. All rights reserved.
  3.  * Distributed under terms of the GNU General Public License
  4. */
  5.  
  6. #include <dirent.h>
  7. #include <errno.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <sys/ksys.h>
  11.  
  12. /* TODO: Add thread safety */
  13.  
  14. DIR *
  15. _DEFUN(opendir, (name),
  16.        const char *name)
  17. {
  18.     ksys_file_info_t info;
  19.     if (_ksys_file_info(name, &info))
  20.     {
  21.         errno = ENOENT;
  22.         return NULL;
  23.     }
  24.  
  25.     if (!(info.attr & (KSYS_FILE_ATTR_DIR | KSYS_FILE_ATTR_VOL_LABEL)))
  26.     {
  27.         errno = ENOTDIR;
  28.         return NULL;
  29.     }
  30.  
  31.     DIR* dir = malloc(sizeof(DIR));
  32.     if (!dir)
  33.         return NULL;
  34.  
  35.     dir->path = strdup(name);
  36.     if (!dir->path)
  37.         return NULL;
  38.  
  39.     dir->pos = 0;
  40.  
  41.     return dir;
  42. }
  43.