Make alternative sigcontextpath a little more generic.
[AROS.git] / compiler / clib / stat.c
blob002c223ae351109967f36d2b3785d689222c8496
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 "__stat.h"
12 #include "__upath.h"
13 #include "__arosc_privdata.h"
15 /*****************************************************************************
17 NAME */
18 #include <sys/stat.h>
20 int stat(
22 /* SYNOPSIS */
23 const char *path,
24 struct stat *sb)
26 /* FUNCTION
27 Returns information about a file. Information is stored in stat
28 structure having the following fields:
30 dev_t st_dev; - ID of device containing the file
31 ino_t st_ino; - inode number
32 mode_t st_mode; - protection mode
33 nlink_t st_nlink; - number of hard links
34 uid_t st_uid; - user ID of the file's owner
35 gid_t st_gid; - group ID of the file's group
36 dev_t st_rdev; - device ID (if the file is character
37 or block special file)
38 off_t st_size; - file size, in bytes
39 time_t st_atime; - time of last acces
40 time_t st_mtime; - time of last data modification
41 time_t st_ctime; - time of last file status change
42 blksize_t st_blksize; - optimal blocksize for I/O
43 blkcnt_t st_blocks; - number of blocks allocated for file
45 INPUTS
46 path - Pathname of the file
47 sb - Pointer to stat structure that will be filled by the stat() call.
49 RESULT
50 0 on success and -1 on error. If an error occurred, the global
51 variable errno is set.
53 NOTES
55 EXAMPLE
57 BUGS
59 SEE ALSO
60 lstat(), fstat()
62 INTERNALS
63 Value of st_ino field is computed as hash from the canonical path of
64 the file.
66 Values of st_atime, st_mtime and st_ctime fields are always set to
67 the last modification date of the file.
69 There are no special files in AROS, so the st_rdev field is never
70 filled.
72 If the given file cannot be examined because of FSA_EXAMINE not
73 implemented in the handler, stat structure is filled with some
74 default values. It's necessary to allow calling stat() on NIL:.
76 ******************************************************************************/
78 struct aroscbase *aroscbase = __GM_GetBase();
79 int res = 0;
80 BPTR lock;
82 /* check for empty path before potential conversion from "." to "" */
83 if (aroscbase->acb_doupath && path && *path == '\0')
85 errno = ENOENT;
86 return -1;
89 path = __path_u2a(path);
90 if (path == NULL)
91 return -1;
93 lock = Lock(path, SHARED_LOCK);
94 if (!lock)
96 if (IoErr() == ERROR_OBJECT_IN_USE)
98 /* the file is already locked exclusively, so the only way to get
99 info about it is to find it in the parent directory with the ExNext() function
102 SetIoErr(0);
103 return __stat_from_path(path, sb);
106 errno = __arosc_ioerr2errno(IoErr());
107 return -1;
109 else
110 res = __stat(lock, sb, FALSE);
112 UnLock(lock);
114 return res;