Rev 9952 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5141 | serge | 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 |
||
9952 | turbocat | 16 | #include |
5141 | serge | 17 | #include |
5215 | serge | 18 | #include |
19 | #include |
||
5141 | serge | 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 | { |
||
9952 | turbocat | 30 | ksys_file_info_t info; |
5215 | serge | 31 | struct tm time; |
32 | |||
9952 | turbocat | 33 | if (_ksys_file_info(path, &info)) |
5215 | serge | 34 | { |
35 | errno = ENOENT; |
||
36 | return (-1); |
||
9952 | turbocat | 37 | } |
5215 | serge | 38 | |
9952 | turbocat | 39 | memset(buf, 0, sizeof (*buf)); |
5215 | serge | 40 | |
41 | buf->st_size = info.size; |
||
42 | |||
9954 | turbocat | 43 | if (info.attr & (KSYS_FILE_ATTR_DIR | KSYS_FILE_ATTR_VOL_LABEL)) |
5215 | serge | 44 | buf->st_mode = S_IFDIR; |
45 | else |
||
46 | { |
||
9954 | turbocat | 47 | if (info.attr & (KSYS_FILE_ATTR_SYS | KSYS_FILE_ATTR_HIDDEN | KSYS_FILE_ATTR_RO)) |
5215 | serge | 48 | buf->st_mode = S_IFREG|S_IRUSR|S_IXUSR; |
49 | else |
||
50 | buf->st_mode = S_IFREG|S_IRUSR|S_IWUSR|S_IXUSR; |
||
51 | } |
||
52 | |||
53 | buf->st_blksize = 4096; |
||
54 | |||
55 | time.tm_sec = info.atime.sec; |
||
56 | time.tm_min = info.atime.min; |
||
57 | time.tm_hour = info.atime.hour; |
||
58 | time.tm_mday = info.adate.day; |
||
59 | time.tm_mon = info.adate.month; |
||
60 | time.tm_year = info.adate.year - 1900; |
||
61 | time.tm_isdst = -1; |
||
62 | buf->st_atime = mktime(&time); |
||
63 | |||
64 | time.tm_sec = info.ctime.sec; |
||
65 | time.tm_min = info.ctime.min; |
||
66 | time.tm_hour = info.ctime.hour; |
||
67 | time.tm_mday = info.cdate.day; |
||
68 | time.tm_mon = info.cdate.month; |
||
69 | time.tm_year = info.cdate.year - 1900; |
||
70 | time.tm_isdst = -1; |
||
71 | buf->st_ctime = mktime(&time); |
||
72 | |||
73 | time.tm_sec = info.mtime.sec; |
||
74 | time.tm_min = info.mtime.min; |
||
75 | time.tm_hour = info.mtime.hour; |
||
76 | time.tm_mday = info.mdate.day; |
||
77 | time.tm_mon = info.mdate.month; |
||
78 | time.tm_year = info.mdate.year - 1900; |
||
79 | time.tm_isdst = -1; |
||
80 | buf->st_mtime = mktime(&time); |
||
81 | |||
82 | return (0); |
||
5141 | serge | 83 | } |
84 | |||
5215 | serge | 85 | |
86 | int |
||
87 | _DEFUN (lstat, (path, buf), |
||
88 | const char *path _AND |
||
89 | struct stat *buf) |
||
90 | { |
||
91 | return stat(path, buf); |
||
92 | } |