alsa.audio: limit the supported frequencies to common set
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / stat.c
blob3128489c4f9672c91b5b50a797fe30d404685442
1 /* $Id$
3 * stat.c - stat() for the netlib
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
7 * All rights reserved.
8 */
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <errno.h>
14 #include <string.h>
15 #include <stdlib.h>
17 /* DOS 3.0 and MuFS extensions to file info block */
18 #include "fibex.h"
19 #include "netlib.h"
20 #include <proto/dos.h>
21 #include <proto/utility.h>
23 int stat(const char *name, struct stat *st)
25 short found;
26 register int rc = -1;
27 BPTR lock;
29 if (st == NULL || ((1 & (long)st) == 1)) {
30 errno = EFAULT;
31 return -1;
34 lock = Lock((STRPTR)name, SHARED_LOCK);
36 if (found = lock != NULL) {
37 if (Examine(lock, __dostat_fib)) {
38 __dostat(__dostat_fib, st);
39 st->st_dev = (dev_t)((struct FileLock *)BADDR(lock))->fl_Task;
40 rc = 0;
41 } else {
42 errno = EIO;
44 } else {
45 UBYTE errcode = IoErr();
47 if (errcode == ERROR_OBJECT_IN_USE) {
48 rc = lstat(name, st);
49 } else {
50 set_errno(errcode);
54 if (lock)
55 UnLock(lock);
57 return rc;
60 int lstat(const char *name, struct stat *st)
62 /* Cannot lock - do examine via Examine()/ExNext() */
63 int rc = -1;
64 char *cname;
66 if (st == NULL || ((1 & (long)st) == 1)) {
67 errno = EFAULT;
68 return -1;
71 cname = malloc(strlen(name) + 1);
73 if (cname) {
74 BPTR lock;
75 char *pp = PathPart(strcpy(cname, name));
76 *pp = '\0';
78 if (lock = Lock(cname, SHARED_LOCK)) {
79 pp = FilePart((STRPTR)name);
81 if (Examine(lock, __dostat_fib)) {
82 while (ExNext(lock, __dostat_fib)) {
83 if (Stricmp(pp, __dostat_fib->fib_FileName) == 0) {
84 __dostat(__dostat_fib, st);
85 st->st_dev = (dev_t)((struct FileLock *)BADDR(lock))->fl_Task;
86 rc = 0;
87 break;
91 if (rc != 0)
92 errno = ENOENT;
93 } else {
94 set_errno(IoErr());
97 free(cname);
98 } else {
99 errno = ENOMEM;
102 return rc;