home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / SYS / STAT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.8 KB  |  65 lines

  1. /* sys/stat.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <os2emx.h>
  5. #include <string.h>
  6. #include <errno.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include "syscalls.h"
  10.  
  11. int __stat (const char *name, struct stat *buf)
  12. {
  13.   ULONG rc;
  14.   FILESTATUS3 info;
  15.  
  16.   memset (buf, 0, sizeof (*buf));
  17.   if ((name[0] == '/' || name[0] == '\\') && strlen (name) >= 6 &&
  18.       memicmp (name+1, "pipe", 4) == 0 && (name[5] == '/' || name[5] == '\\'))
  19.     {
  20.       errno = ENOENT;
  21.       return (-1);
  22.     }
  23.   rc = DosQueryPathInfo (name, FIL_STANDARD, &info, sizeof (info));
  24.   if (rc != 0)
  25.     {
  26.       _sys_set_errno (rc);
  27.       return (-1);
  28.     }
  29.   buf->st_attr = info.attrFile;
  30.   buf->st_reserved = 0;
  31.   buf->st_mtime = _sys_p2t (info.ftimeLastWrite, info.fdateLastWrite);
  32.   if (FTIMEZEROP (info.ftimeCreation) &&
  33.       FDATEZEROP (info.fdateCreation))
  34.     buf->st_ctime = buf->st_mtime;
  35.   else
  36.     buf->st_ctime = _sys_p2t (info.ftimeCreation, info.fdateCreation);
  37.   if (FTIMEZEROP (info.ftimeLastAccess) &&
  38.       FDATEZEROP (info.fdateLastAccess))
  39.     buf->st_atime = buf->st_mtime;
  40.   else
  41.     buf->st_atime = _sys_p2t (info.ftimeLastAccess, info.fdateLastAccess);
  42.   if (info.attrFile & 0x10)     /* directory */
  43.     {
  44.       buf->st_mode = S_IFDIR;
  45.       buf->st_mode |= ((S_IREAD|S_IWRITE|S_IEXEC) >> 6) * 0111;
  46.       buf->st_size = 0;
  47.     }
  48.   else
  49.     {
  50.       buf->st_size = info.cbFile;
  51.       buf->st_mode = S_IFREG;
  52.       if (info.attrFile & 1)
  53.         buf->st_mode |= (S_IREAD >> 6) * 0111;
  54.       else
  55.         buf->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
  56.     }
  57.   buf->st_uid = 0;
  58.   buf->st_gid = 0;
  59.   buf->st_ino = _sys_ino++;
  60.   buf->st_dev = 0;
  61.   buf->st_rdev = 0;
  62.   buf->st_nlink = 1;
  63.   return (0);
  64. }
  65.