Cygwin: lockf: Fix adding a new lock over multiple locks
[newlib-cygwin.git] / libgloss / mt / access.c
blob980682ef3b9626196c9f668e7dc4f4139cfe1ac8
1 /* This is file ACCESS.C */
2 /*
3 * Copyright (C) 1993 DJ Delorie
4 * All rights reserved.
6 * Redistribution, modification, 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.
10 * This file is distributed WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 #include <fcntl.h>
15 #include <sys/stat.h>
16 #include <unistd.h>
18 int access(const char *fn, int flags)
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)
27 if (s.st_mode & S_IWRITE)
28 return 0;
29 return -1;
31 return 0;