compiler/clib: Don't hide access to aroscbase behind a #define.
[AROS.git] / compiler / clib / stat.c
blobdb3ac3f9ecf4a40dcbb5c65895864c83d13a566e
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dos/dos.h>
7 #include <proto/dos.h>
9 #include <errno.h>
11 #include "__time.h"
12 #include "__errno.h"
13 #include "__stat.h"
14 #include "__upath.h"
16 /*****************************************************************************
18 NAME */
20 #include <sys/stat.h>
22 int stat(
24 /* SYNOPSIS */
25 const char *path,
26 struct stat *sb)
28 /* FUNCTION
29 Returns information about a file. Information is stored in stat
30 structure having the following fields:
32 dev_t st_dev; - ID of device containing the file
33 ino_t st_ino; - inode number
34 mode_t st_mode; - protection mode
35 nlink_t st_nlink; - number of hard links
36 uid_t st_uid; - user ID of the file's owner
37 gid_t st_gid; - group ID of the file's group
38 dev_t st_rdev; - device ID (if the file is character
39 or block special file)
40 off_t st_size; - file size, in bytes
41 time_t st_atime; - time of last acces
42 time_t st_mtime; - time of last data modification
43 time_t st_ctime; - time of last file status change
44 blksize_t st_blksize; - optimal blocksize for I/O
45 blkcnt_t st_blocks; - number of blocks allocated for file
47 INPUTS
48 path - Pathname of the file
49 sb - Pointer to stat structure that will be filled by the stat() call.
51 RESULT
52 0 on success and -1 on error. If an error occurred, the global
53 variable errno is set.
55 NOTES
57 EXAMPLE
59 BUGS
61 SEE ALSO
62 lstat(), fstat()
64 INTERNALS
65 Value of st_ino field is computed as hash from the canonical path of
66 the file.
68 Values of st_atime, st_mtime and st_ctime fields are always set to
69 the last modification date of the file.
71 There are no special files in AROS, so the st_rdev field is never
72 filled.
74 If the given file cannot be examined because of FSA_EXAMINE not
75 implemented in the handler, stat structure is filled with some
76 default values. It's necessary to allow calling stat() on NIL:.
78 ******************************************************************************/
80 struct aroscbase *aroscbase = __GM_GetBase();
81 int res = 0;
82 BPTR lock;
84 /* check for empty path before potential conversion from "." to "" */
85 if (aroscbase->acb_doupath && path && *path == '\0')
87 errno = ENOENT;
88 return -1;
91 path = __path_u2a(path);
92 if (path == NULL)
93 return -1;
95 lock = Lock(path, SHARED_LOCK);
96 if (!lock)
98 if (IoErr() == ERROR_OBJECT_IN_USE)
100 /* the file is already locked exclusively, so the only way to get
101 info about it is to find it in the parent directory with the ExNext() function
104 SetIoErr(0);
105 return __stat_from_path(path, sb);
108 errno = IoErr2errno(IoErr());
109 return -1;
111 else
112 res = __stat(lock, sb, FALSE);
114 UnLock(lock);
116 return res;