muimaster.library: support Listview_List in List
[AROS.git] / compiler / posixc / lstat.c
blobbeafc6da1ef71c909a3f8fe14239369b0c6ed692
1 /*
2 Copyright © 1995-2013, 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 "__posixc_intbase.h"
13 #include "__stat.h"
14 #include "__upath.h"
16 /* like Dos_Lock() but no automatic soft link resolution */
17 static BPTR __lock(
18 const char* name,
19 LONG accessMode);
21 /*****************************************************************************
23 NAME */
25 #include <sys/stat.h>
27 int lstat(
29 /* SYNOPSIS */
30 const char *path,
31 struct stat *sb)
33 /* FUNCTION
34 Returns information about a file like stat does except that lstat
35 does not follow symbolic links. Information is stored in stat
36 structure. Consult stat() documentation for detailed description
37 of that structure.
39 INPUTS
40 path - Pathname of the file
41 sb - Pointer to stat structure that will be filled by the lstat() call.
43 RESULT
44 0 on success and -1 on error. If an error occurred, the global
45 variable errno is set.
47 NOTES
49 EXAMPLE
51 BUGS
53 SEE ALSO
54 stat(), fstat()
56 INTERNALS
57 Consult stat() documentation for details.
59 ******************************************************************************/
61 struct PosixCIntBase *PosixCBase =
62 (struct PosixCIntBase *)__aros_getbase_PosixCBase();
63 int res = 0;
64 BPTR lock;
66 /* check for empty path before potential conversion from "." to "" */
67 if (PosixCBase->doupath && path && *path == '\0')
69 errno = ENOENT;
70 return -1;
73 path = __path_u2a(path);
74 if (path == NULL)
75 return -1;
77 lock = __lock(path, SHARED_LOCK);
78 if (!lock)
80 if ( IoErr() == ERROR_IS_SOFT_LINK
81 || IoErr() == ERROR_OBJECT_IN_USE)
83 /* either the file is already locked exclusively
84 or it is a soft link, in both cases only way
85 to get info about it is to find it in the
86 parent directory with the ExNext() function
89 SetIoErr(0);
90 return __stat_from_path(path, sb);
93 errno = __stdc_ioerr2errno(IoErr());
94 return -1;
96 else
97 res = __stat(lock, sb, FALSE);
99 UnLock(lock);
101 return res;
104 static BPTR __lock(
105 const char* name,
106 LONG accessMode)
108 return Lock(name, accessMode);