compiler/clib: Don't hide access to aroscbase behind a #define.
[AROS.git] / compiler / clib / lstat.c
blob21cf298c1038ec8590278ac8e0090fe92119e8ca
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include <proto/dos.h>
10 #include <errno.h>
12 #include "__arosc_privdata.h"
13 #include "__errno.h"
14 #include "__filesystem_support.h"
15 #include "__stat.h"
16 #include "__upath.h"
18 /* like Dos_Lock() but no automatic soft link resolution */
19 static BPTR __lock(
20 const char* name,
21 LONG accessMode);
23 /*****************************************************************************
25 NAME */
27 #include <sys/stat.h>
29 int lstat(
31 /* SYNOPSIS */
32 const char *path,
33 struct stat *sb)
35 /* FUNCTION
36 Returns information about a file like stat does except that lstat
37 does not follow symbolic links. Information is stored in stat
38 structure. Consult stat() documentation for detailed description
39 of that structure.
41 INPUTS
42 path - Pathname of the file
43 sb - Pointer to stat structure that will be filled by the lstat() call.
45 RESULT
46 0 on success and -1 on error. If an error occurred, the global
47 variable errno is set.
49 NOTES
51 EXAMPLE
53 BUGS
55 SEE ALSO
56 stat(), fstat()
58 INTERNALS
59 Consult stat() documentation for details.
61 ******************************************************************************/
63 struct aroscbase *aroscbase = __GM_GetBase();
64 int res = 0;
65 BPTR lock;
67 /* check for empty path before potential conversion from "." to "" */
68 if (aroscbase->acb_doupath && path && *path == '\0')
70 errno = ENOENT;
71 return -1;
74 path = __path_u2a(path);
75 if (path == NULL)
76 return -1;
78 lock = __lock(path, SHARED_LOCK);
79 if (!lock)
81 if ( IoErr() == ERROR_IS_SOFT_LINK
82 || IoErr() == ERROR_OBJECT_IN_USE)
84 /* either the file is already locked exclusively
85 or it is a soft link, in both cases only way
86 to get info about it is to find it in the
87 parent directory with the ExNext() function
90 SetIoErr(0);
91 return __stat_from_path(path, sb);
94 errno = IoErr2errno(IoErr());
95 return -1;
97 else
98 res = __stat(lock, sb, FALSE);
100 UnLock(lock);
102 return res;
105 static BPTR __lock(
106 const char* name,
107 LONG accessMode)
109 return Lock(name, accessMode);