Changeset 1954


Ignore:
Timestamp:
May 2, 2005, 5:57:51 AM (20 years ago)
Author:
bird
Message:

Quick rewrite.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/io/access.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1953 r1954  
    55#include <io.h>
    66#include <errno.h>
     7#include <sys/stat.h>
    78#include <emx/io.h>
    89#include <emx/syscalls.h>
    910
     11
     12/** @todo Reimplement access and eaccess using the actual UID/GID stuff from the file and SPM. */
    1013int _STD(access) (const char *name, int mode)
    1114{
    12   int a, slash;
    13   size_t len;
    14   char *tmp;
     15    struct stat s;
     16    if (stat(name, &s))
     17        return -1;
    1518
    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))
    2323    {
    24       tmp = alloca (len);
    25       memcpy (tmp, name, len - 1);
    26       tmp[len-1] = 0;
    27       name = tmp;
     24        errno = ENOTDIR;
     25        return -1;
    2826    }
    2927
    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)
    4030    {
    41       errno = ENOTDIR;
    42       return -1;
     31        errno = ENOENT;
     32        return -1;
    4333    }
    4434
    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))
    4837    {
    49       errno = ENOENT;
    50       return -1;
     38        errno = EACCES;
     39        return -1;
    5140    }
    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;
    6142}
Note: See TracChangeset for help on using the changeset viewer.