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

  1. /* stat.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdlib.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <time.h>
  8. #include <errno.h>
  9. #include <io.h>
  10. #include <string.h>
  11.  
  12. int stat (const char *name, struct stat *buffer)
  13. {
  14.   int rc, i, slash;
  15.   char *tmp;
  16.  
  17.   slash = FALSE;
  18.   i = strlen (name);
  19.   if (i > 1 && (name[i-1] == '\\' || name[i-1] == '/') &&
  20.       (name[i-2] != '\\' && name[i-2] != '/' && name[i-2] != ':'))
  21.     {
  22.       slash = TRUE;
  23.       tmp = alloca (i);
  24.       memcpy (tmp, name, i);
  25.       tmp[i-1] = 0;
  26.       name = tmp;
  27.     }
  28.   rc = __stat (name, buffer);
  29.   if (rc == 0)
  30.     {
  31.       if (slash && ((buffer->st_mode & S_IFMT) != S_IFDIR))
  32.         {
  33.           errno = ENOTDIR;
  34.           return (-1);
  35.         }
  36.       if (!_tzset_flag) tzset ();
  37.       buffer->st_atime += timezone;
  38.       buffer->st_mtime += timezone;
  39.       buffer->st_ctime += timezone;
  40.       if ((buffer->st_mode & S_IFMT) == S_IFREG)
  41.         {
  42.           tmp = _getext (name);
  43.           if (tmp != NULL &&
  44.               (stricmp (tmp, ".exe") == 0 ||
  45.                stricmp (tmp, ".com") == 0 ||
  46.                stricmp (tmp, ".cmd") == 0 ||
  47.                stricmp (tmp, ".bat") == 0))
  48.             buffer->st_mode |= (S_IEXEC >> 6) * 0111;
  49.         }
  50.     }
  51.   return (rc);
  52. }
  53.