compiler/clib: Rename IoErr2errno() to __arosc_ioerr2errno(); function is now defined...
[AROS.git] / compiler / clib / stat.c
blobf3b37010f59304f9160a8f02f1c24fef9cf82d0e
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 "__stat.h"
13 #include "__upath.h"
15 /*****************************************************************************
17 NAME */
19 #include <sys/stat.h>
21 int stat(
23 /* SYNOPSIS */
24 const char *path,
25 struct stat *sb)
27 /* FUNCTION
28 Returns information about a file. Information is stored in stat
29 structure having the following fields:
31 dev_t st_dev; - ID of device containing the file
32 ino_t st_ino; - inode number
33 mode_t st_mode; - protection mode
34 nlink_t st_nlink; - number of hard links
35 uid_t st_uid; - user ID of the file's owner
36 gid_t st_gid; - group ID of the file's group
37 dev_t st_rdev; - device ID (if the file is character
38 or block special file)
39 off_t st_size; - file size, in bytes
40 time_t st_atime; - time of last acces
41 time_t st_mtime; - time of last data modification
42 time_t st_ctime; - time of last file status change
43 blksize_t st_blksize; - optimal blocksize for I/O
44 blkcnt_t st_blocks; - number of blocks allocated for file
46 INPUTS
47 path - Pathname of the file
48 sb - Pointer to stat structure that will be filled by the stat() call.
50 RESULT
51 0 on success and -1 on error. If an error occurred, the global
52 variable errno is set.
54 NOTES
56 EXAMPLE
58 BUGS
60 SEE ALSO
61 lstat(), fstat()
63 INTERNALS
64 Value of st_ino field is computed as hash from the canonical path of
65 the file.
67 Values of st_atime, st_mtime and st_ctime fields are always set to
68 the last modification date of the file.
70 There are no special files in AROS, so the st_rdev field is never
71 filled.
73 If the given file cannot be examined because of FSA_EXAMINE not
74 implemented in the handler, stat structure is filled with some
75 default values. It's necessary to allow calling stat() on NIL:.
77 ******************************************************************************/
79 struct aroscbase *aroscbase = __GM_GetBase();
80 int res = 0;
81 BPTR lock;
83 /* check for empty path before potential conversion from "." to "" */
84 if (aroscbase->acb_doupath && path && *path == '\0')
86 errno = ENOENT;
87 return -1;
90 path = __path_u2a(path);
91 if (path == NULL)
92 return -1;
94 lock = Lock(path, SHARED_LOCK);
95 if (!lock)
97 if (IoErr() == ERROR_OBJECT_IN_USE)
99 /* the file is already locked exclusively, so the only way to get
100 info about it is to find it in the parent directory with the ExNext() function
103 SetIoErr(0);
104 return __stat_from_path(path, sb);
107 errno = __arosc_ioerr2errno(IoErr());
108 return -1;
110 else
111 res = __stat(lock, sb, FALSE);
113 UnLock(lock);
115 return res;