Subversion Repositories Kolibri OS

Rev

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

  1. /* stat.c -- Get the status of a file.
  2.  *
  3.  * Copyright (c) 1995 Cygnus Support
  4.  *
  5.  * The authors hereby grant permission to use, copy, modify, distribute,
  6.  * and license this software and its documentation for any purpose, provided
  7.  * that existing copyright notices are retained in all copies and that this
  8.  * notice is included verbatim in any distributions. No written agreement,
  9.  * license, or royalty fee is required for any of the authorized uses.
  10.  * Modifications to this software may be copyrighted by their authors
  11.  * and need not follow the licensing terms described here, provided that
  12.  * the new terms are clearly indicated on the first page of each file where
  13.  * they apply.
  14.  */
  15. #include <sys/stat.h>
  16. #include <sys/kos_io.h>
  17. #include <errno.h>
  18. #include <time.h>
  19. #include <string.h>
  20. #include "glue.h"
  21.  
  22. /*
  23.  * stat -- Since we have no file system, we just return an error.
  24.  */
  25. int
  26. _DEFUN (stat, (path, buf),
  27.        const char *path _AND
  28.        struct stat *buf)
  29. {
  30.  
  31.     fileinfo_t info;
  32.     struct tm time;
  33.  
  34.     printf("%s %s\n", __FUNCTION__, path);
  35.  
  36.     if( get_fileinfo(path, &info))
  37.     {
  38.         errno = ENOENT;
  39.         return (-1);
  40.     };
  41.  
  42.     memset (buf, 0, sizeof (* buf));
  43.  
  44.     buf->st_size = info.size;
  45.  
  46.     if (info.attr & 0x10)
  47.         buf->st_mode = S_IFDIR;
  48.     else
  49.     {
  50.         if (info.attr & 0x07)
  51.             buf->st_mode = S_IFREG|S_IRUSR|S_IXUSR;
  52.         else
  53.             buf->st_mode = S_IFREG|S_IRUSR|S_IWUSR|S_IXUSR;
  54.     }
  55.  
  56.     buf->st_blksize = 4096;
  57.  
  58.     time.tm_sec   = info.atime.sec;
  59.     time.tm_min   = info.atime.min;
  60.     time.tm_hour  = info.atime.hour;
  61.     time.tm_mday  = info.adate.day;
  62.     time.tm_mon   = info.adate.month;
  63.     time.tm_year  = info.adate.year - 1900;
  64.     time.tm_isdst = -1;
  65.     buf->st_atime = mktime(&time);
  66.  
  67.     time.tm_sec   = info.ctime.sec;
  68.     time.tm_min   = info.ctime.min;
  69.     time.tm_hour  = info.ctime.hour;
  70.     time.tm_mday  = info.cdate.day;
  71.     time.tm_mon   = info.cdate.month;
  72.     time.tm_year  = info.cdate.year - 1900;
  73.     time.tm_isdst = -1;
  74.     buf->st_ctime = mktime(&time);
  75.  
  76.     time.tm_sec   = info.mtime.sec;
  77.     time.tm_min   = info.mtime.min;
  78.     time.tm_hour  = info.mtime.hour;
  79.     time.tm_mday  = info.mdate.day;
  80.     time.tm_mon   = info.mdate.month;
  81.     time.tm_year  = info.mdate.year - 1900;
  82.     time.tm_isdst = -1;
  83.     buf->st_mtime = mktime(&time);
  84.  
  85.     return (0);
  86. }
  87.  
  88.  
  89. int
  90. _DEFUN (lstat, (path, buf),
  91.        const char *path _AND
  92.        struct stat *buf)
  93. {
  94.     return stat(path, buf);
  95. }
  96.  
  97.