Changeset 1954
- Timestamp:
- May 2, 2005, 5:57:51 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/lib/io/access.c
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r1953 r1954 5 5 #include <io.h> 6 6 #include <errno.h> 7 #include <sys/stat.h> 7 8 #include <emx/io.h> 8 9 #include <emx/syscalls.h> 9 10 11 12 /** @todo Reimplement access and eaccess using the actual UID/GID stuff from the file and SPM. */ 10 13 int _STD(access) (const char *name, int mode) 11 14 { 12 int a, slash;13 size_t len;14 char *tmp;15 struct stat s; 16 if (stat(name, &s)) 17 return -1; 15 18 16 /* If there is a trailing slash or backslash, remove it and set 17 `slash' to true. Make a local copy of the string to remove the 18 slash or backslash. */ 19 20 len = strlen (name); 21 slash = _trslash (name, len, 1); 22 if (slash) 19 /* Check if directory spec, don't trust stat to do that right yet. */ 20 char *psz = strchr(name, 0); 21 if ( (psz[-1] == '/' || psz[-1] == '\\') 22 && !(s.st_attr & _A_SUBDIR)) 23 23 { 24 tmp = alloca (len); 25 memcpy (tmp, name, len - 1); 26 tmp[len-1] = 0; 27 name = tmp; 24 errno = ENOTDIR; 25 return -1; 28 26 } 29 27 30 /* Query the attributes of the file or directory. */ 31 32 a = __chmod (name, 0, 0); 33 if (a < 0) 34 return -1; 35 36 /* Fail if the name ends with a slash or backslash and is not a 37 directory. */ 38 39 if (slash && !(a & _A_SUBDIR)) 28 /* Volume IDs are not accessible. */ 29 if (s.st_attr & _A_VOLID) 40 30 { 41 errno = ENOTDIR;42 return -1;31 errno = ENOENT; 32 return -1; 43 33 } 44 34 45 /* Volume IDs are not accessible. */ 46 47 if (a & _A_VOLID) 35 /* When testing for write permission, check the read-only bit. */ 36 if ((mode & 2) && (s.st_attr & _A_RDONLY)) 48 37 { 49 errno = ENOENT;50 return -1;38 errno = EACCES; 39 return -1; 51 40 } 52 53 /* When testing for write permission, check the read-only bit. */ 54 55 if ((mode & 2) && (a & _A_RDONLY)) 56 { 57 errno = EACCES; 58 return -1; 59 } 60 return 0; 41 return 0; 61 42 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.