Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <libc/stubs.h>
  2. #include <stdlib.h>
  3. #include <stddef.h>
  4. #include <unistd.h>
  5. #include <time.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9. #include <errno.h>
  10. #include <fcntl.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <dos.h>
  14. #include <dir.h>
  15. #include <libc/farptrgs.h>
  16. #include <libc/bss.h>
  17.  
  18. #include "xstat.h"
  19.  
  20. int stat(const char *path, struct stat *statbuf)
  21. {
  22.         int nslash=0;
  23.         const char* p;
  24.         char* q;
  25.         struct systree_info2 finf;
  26.         struct bdfe_item attr;
  27.  
  28.         memset(statbuf,0,sizeof(*statbuf));
  29. // "/<base>/<number>" is special case
  30.         for (p=path;*p;p++) if (*p=='/') ++nslash;
  31.         while (p>path && p[-1]=='/') {--nslash;--p;}
  32.         if (nslash <= 2)
  33.         {
  34.                 statbuf->st_mode = S_IFDIR;
  35.                 return 0;
  36.         }
  37.         finf.command = 5;
  38.         finf.file_offset_low = 0;
  39.         finf.file_offset_high = 0;
  40.         finf.size = 0;
  41.         finf.data_pointer = (__u32)&attr;
  42.         _fixpath(path,finf.name);
  43.         for (q=finf.name+strlen(finf.name)-1;q>=finf.name && *q=='/';q--) ;
  44.         q[1]=0;
  45.         if (__kolibri__system_tree_access2(&finf))
  46.         {
  47.                 errno = EFAULT;
  48.                 return -1;
  49.         }
  50.         memset(statbuf,0,sizeof(*statbuf));
  51.         statbuf->st_size = attr.filesize_low;
  52.         if (attr.attr & 0x10)
  53.                 statbuf->st_mode = S_IFDIR;
  54.         struct tm time;
  55.         time.tm_sec = attr.atime.seconds;
  56.         time.tm_min = attr.atime.minutes;
  57.         time.tm_hour = attr.atime.hours;
  58.         time.tm_mday = attr.adate.day;
  59.         time.tm_mon = attr.adate.month;
  60.         time.tm_year = attr.adate.year - 1900;
  61.         time.tm_isdst = -1;
  62.         statbuf->st_atime = mktime(&time);
  63.         time.tm_sec = attr.ctime.seconds;
  64.         time.tm_min = attr.ctime.minutes;
  65.         time.tm_hour = attr.ctime.hours;
  66.         time.tm_mday = attr.cdate.day;
  67.         time.tm_mon = attr.cdate.month;
  68.         time.tm_year = attr.cdate.year - 1900;
  69.         time.tm_isdst = -1;
  70.         statbuf->st_ctime = mktime(&time);
  71.         time.tm_sec = attr.mtime.seconds;
  72.         time.tm_min = attr.mtime.minutes;
  73.         time.tm_hour = attr.mtime.hours;
  74.         time.tm_mday = attr.mdate.day;
  75.         time.tm_mon = attr.mdate.month;
  76.         time.tm_year = attr.mdate.year - 1900;
  77.         time.tm_isdst = -1;
  78.         statbuf->st_mtime = mktime(&time);
  79.         return 0;
  80. }
  81.