alsa.audio: limit the supported frequencies to common set
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / access.c
blob6845dd00bbf5529eaf89397ffa3f4612eaecc7de
1 /* $Id$
3 * access.c - check access to a file or a directory
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
7 * All rights reserved.
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <dos.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <dos/dos.h>
16 #include <proto/dos.h>
17 #include <proto/exec.h>
18 #include <exec/memory.h>
20 #include <bsdsocket.h>
23 * I know, the goto's are ugly, but they make the code smaller and help
24 * to prevent duplicating code.
26 int
27 access(const char *name, int mode)
29 BPTR lock, parentLock;
30 LONG prot;
31 UBYTE bytes[sizeof(struct FileInfoBlock) + sizeof(struct InfoData) + 3];
32 struct FileInfoBlock *fib;
33 struct InfoData *info;
36 * align the data areas
38 fib = (struct FileInfoBlock *) (((ULONG) bytes+3) & (0xFFFFFFFF-3));
39 info = (struct InfoData *) (ULONG)(fib + 1);
42 * Lock the file (or directory)
44 if ((lock = Lock((STRPTR)name, SHARED_LOCK)) == NULL)
45 goto osfail;
47 if (!Examine(lock, fib))
48 goto osfail;
50 prot = fib->fib_Protection;
53 * Check each access mode
55 if (mode & R_OK && prot & FIBF_READ) {
56 errno = EACCES;
57 goto fail;
59 if (mode & W_OK) {
61 * Check for write protected disks
63 if (!Info(lock, info))
64 goto osfail;
66 if (info->id_DiskState == ID_WRITE_PROTECTED) {
67 errno = EROFS;
68 goto fail;
72 * not write protected: Check if the lock is to the root of the
73 * disk, if it is, force writing to be allowed.
74 * Check if the lock is a directory before taking ParentDir()
76 if (fib->fib_DirEntryType >= 0) { /* lock is a directory */
77 parentLock = ParentDir(lock);
78 if (parentLock != NULL)
79 UnLock(parentLock); /* not the root, prot is valid */
80 else
81 prot &= ~FIBF_WRITE; /* the root, force writing to be allowed */
83 if (prot & FIBF_WRITE) {
84 errno = EACCES;
85 goto fail;
88 if (mode & X_OK && prot & FIBF_EXECUTE) {
89 errno = EACCES;
90 goto fail;
93 /* F_OK */
95 UnLock(lock);
96 return 0;
98 osfail:
99 #if __SASC
100 errno = __io2errno(_OSERR = IoErr());
101 #else
102 _ug_set_errno(IoErr());
103 #endif
105 fail:
106 if (lock != NULL)
107 UnLock(lock);
109 return -1;