OSDN Git Service

8e08b3a7f0a2eb9aaf5643f242e63e816f299e77
[pf3gnuchains/pf3gnuchains4x.git] / libgloss / ms1 / access.c
1 /* This is file ACCESS.C */
2 /*
3  * Copyright (C) 1993 DJ Delorie
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms is permitted
7  * provided that the above copyright notice and following paragraph are
8  * duplicated in all such forms.
9  *
10  * This file is distributed WITHOUT ANY WARRANTY; without even the implied
11  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  */
13
14 #include <fcntl.h>
15 #include <sys/stat.h>
16 #include <unistd.h>
17
18 int access(const char *fn, int flags)
19 {
20   struct stat s;
21   if (stat(fn, &s))
22     return -1;
23   if (s.st_mode & S_IFDIR)
24     return 0;
25   if (flags & W_OK)
26   {
27     if (s.st_mode & S_IWRITE)
28       return 0;
29     return -1;
30   }
31   return 0;
32 }
33