1 /*
2 Low Level Interface Library
3
4 Copyright 1983-2000 Green Hills Software,Inc.
5
6 * This program is the property of Green Hills Software, Inc,
7 * its contents are proprietary information and no part of it
8 * is to be disclosed to anyone except employees of Green Hills
9 * Software, Inc., or as agreed in writing signed by the President
10 * of Green Hills Software, Inc.
11 */
12 /* ind_stat.c: NON-ANSI access(), fstat(), and stat() facilities. */
13
14 #include "indos.h"
15
16 #if defined(EMBEDDED)
17 /******************************************************************************/
18 /* #include <unistd.h> */
19 /* int access(const char *name, int mode) */
20 /* name is the name of a file, prot is the Logical Or of the following flags */
21 /* R_OK 4: readable */
22 /* W_OK 2: writable */
23 /* X_OK 1: executable or directory searchable (Unused) */
24 /* F_OK 0: file exists */
25 /* If mode is zero then test only for file existence. */
26 /* Return 0 if all of the specified operations are possible on the file. */
27 /* Return -1 if any of the specified operations are not possible on the file */
28 /* and set errno appropriately. */
29 /******************************************************************************/
access(const char * name,int mode)30 int access(const char *name, int mode) {
31 #pragma ghs nowarning 1547 /* Syscall prototypes might not match */
32 return __ghs_syscall(SYSCALL_ACCESS, name, mode);
33 #pragma ghs endnowarning 1547
34 }
35
36 /******************************************************************************/
37 /* #include <stat.h> */
38 /* int fstat(int fno, struct stat *statptr); */
39 /* */
40 /* fno is a file number returned by open() or creat(). In the two fields */
41 /* st_dev and st_ino place values which uniquely identify the file or device */
42 /* opened on file number fno. In unix these are the device number and the */
43 /* inode (file) number on the device. */
44 /* The field st_size is set to the size of the file in bytes, -1 if the size */
45 /* is unknown. */
46 /* */
47 /* Return 0 if the file status is correctly returned. Return -1 if no file */
48 /* is opened on file number fno, and set errno appropriately. */
49 /******************************************************************************/
fstat(int fno,struct stat * statptr)50 int fstat(int fno, struct stat *statptr) {
51 /*
52 * If no other implementation is provided, return device and inode number 0.
53 */
54 unsigned int tmp[2];
55
56 statptr->st_dev = 0;
57 statptr->st_ino = 0;
58 statptr->st_size = -1; /* Don't know size of file */
59 statptr->st_mode = 0;
60
61 #pragma ghs nowarning 1547 /* Syscall prototypes might not match */
62 if (__ghs_syscall(SYSCALL_GETFDATTR, fno, &tmp,
63 (sizeof(tmp[0]))|SYSCALL_ATTR_SIZE|SYSCALL_ATTR_MODE) == -1)
64 return -1;
65 #pragma ghs endnowarning 1547
66
67 #if (SYSCALL_ATTR_SIZE >= SYSCALL_ATTR_MODE)
68 # error misordered attributes
69 #endif
70
71 statptr->st_size = tmp[0];
72 statptr->st_mode = tmp[1];
73
74 return(0);
75 }
76
77 /******************************************************************************/
78 /* #include <stat.h> */
79 /* int stat(char *name, struct stat *statptr); */
80 /* */
81 /* name is the name of a file. In the two fields st_dev and st_ino place */
82 /* values which uniquely identify the named file or device. In unix, these */
83 /* are the device number and the inode (file) number on the device. */
84 /* The field st_size is set to the size of the file in bytes, -1 if the size */
85 /* is unknown. */
86 /* */
87 /* Return 0 if the file status is correctly returned. Return -1 if no file */
88 /* with that name exists, and set errno appropriately. */
89 /******************************************************************************/
stat(char * name,struct stat * statptr)90 int stat(char *name, struct stat *statptr) {
91 /*
92 * If no other implementation provided, return device and inode number 0.
93 */
94 unsigned int tmp[2];
95
96 statptr->st_dev = 0;
97 statptr->st_ino = 0;
98 statptr->st_size = -1; /* Don't know size of file */
99 statptr->st_mode = 0;
100
101 #pragma ghs nowarning 1547 /* Syscall prototypes might not match */
102 if (__ghs_syscall(SYSCALL_GETFNATTR, name, &tmp,
103 (sizeof(tmp[0]))|SYSCALL_ATTR_SIZE|SYSCALL_ATTR_MODE) == -1)
104 return -1;
105 #pragma ghs endnowarning 1547
106
107 #if (SYSCALL_ATTR_SIZE >= SYSCALL_ATTR_MODE)
108 # error misordered attributes
109 #endif
110
111 statptr->st_size = tmp[0];
112 statptr->st_mode = tmp[1];
113
114 return(0);
115 }
116 #else
117 int _K_empty_file_illegal;
118 #endif
119