home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / local / stat.c < prev    next >
Text File  |  1992-03-06  |  2KB  |  86 lines

  1. #define INCL_DOSFILEMGR
  2. #define INCL_DOSERRORS
  3. #include <os2.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <time.h>
  7. #include <errno.h>
  8.  
  9. ULONG Dos32QueryPathInfo() asm ("Dos32QueryPathInfo");
  10.  
  11. int stat (const char *path, struct stat *buf)
  12. {
  13.    FILESTATUS fs;
  14.    ULONG rc;
  15.    struct tm tim;
  16.    ULONG HandType;
  17.    ULONG FlagWord;
  18.  
  19.    rc = Dos32QueryPathInfo ((PSZ)path, 1, (PBYTE)&fs, sizeof (FILESTATUS));
  20.  
  21.    if (rc)
  22.    {
  23.       if (rc == ERROR_PATH_NOT_FOUND || rc == ERROR_FILE_NOT_FOUND)
  24.       {
  25.          errno = ENOENT;
  26.          return (-1);
  27.       }
  28.  
  29.       if (rc == ERROR_ACCESS_DENIED)
  30.       {
  31.          errno = EACCES;
  32.          return (-1);
  33.       }
  34.  
  35.       if (rc == ERROR_INVALID_HANDLE)
  36.       {
  37.          errno = EBADF;
  38.          return (-1);
  39.       }
  40.  
  41.       errno = EIO;
  42.       return (-1);
  43.    }
  44.  
  45.    tim.tm_sec  = fs.ftimeCreation.twosecs;
  46.    tim.tm_min  = fs.ftimeCreation.minutes;
  47.    tim.tm_hour = fs.ftimeCreation.hours;
  48.    tim.tm_mday = fs.fdateCreation.day;
  49.    tim.tm_mon  = fs.fdateCreation.month;
  50.    tim.tm_year = fs.fdateCreation.year;
  51.  
  52.    buf -> st_ctime = mktime (&tim);
  53.  
  54.    tim.tm_sec  = fs.ftimeLastAccess.twosecs;
  55.    tim.tm_min  = fs.ftimeLastAccess.minutes;
  56.    tim.tm_hour = fs.ftimeLastAccess.hours;
  57.    tim.tm_mday = fs.fdateLastAccess.day;
  58.    tim.tm_mon  = fs.fdateLastAccess.month;
  59.    tim.tm_year = fs.fdateLastAccess.year;
  60.  
  61.    buf -> st_atime = mktime (&tim);
  62.  
  63.    tim.tm_sec  = fs.ftimeLastWrite.twosecs;
  64.    tim.tm_min  = fs.ftimeLastWrite.minutes;
  65.    tim.tm_hour = fs.ftimeLastWrite.hours;
  66.    tim.tm_mday = fs.fdateLastWrite.day;
  67.    tim.tm_mon  = fs.fdateLastWrite.month;
  68.    tim.tm_year = fs.fdateLastWrite.year;
  69.  
  70.    buf -> st_mtime = mktime (&tim);
  71.  
  72.    buf -> st_size = fs.cbFile;
  73.    buf -> st_blksize = 4096;
  74.  
  75.    buf -> st_mode = fs.attrFile & FILE_DIRECTORY ? S_IFDIR : S_IFREG;
  76.  
  77.    buf -> st_ino = 0;
  78.    buf -> st_nlink = 1;
  79.    buf -> st_uid = 0;
  80.    buf -> st_gid = 0;
  81.  
  82.    return (0);
  83. }
  84.  
  85.  
  86.