2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 POSIX.1-2008 chown() function
8 #include <aros/debug.h>
10 #include <proto/dos.h>
14 #include "__posixc_intbase.h"
17 /*****************************************************************************
30 Change the user and group ownership of a file.
33 path - the path to file
38 0 on success and -1 on error. If an error occurred, the global
39 variable errno is set.
42 This implementation was done by looking at Olaf 'Olsen' Barthels
53 ******************************************************************************/
55 struct PosixCIntBase
*PosixCBase
=
56 (struct PosixCIntBase
*)__aros_getbase_PosixCBase();
59 struct FileInfoBlock
*fib
= NULL
;
62 /* check for empty path before potential conversion from "." to "" */
63 if (PosixCBase
->doupath
&& path
&& *path
== '\0')
69 path
= __path_u2a(path
);
73 /* should some id not be changed */
74 if (owner
== -1 || group
== -1)
76 if (!(fib
= AllocDosObject(DOS_FIB
, NULL
)))
78 errno
= __stdc_ioerr2errno(IoErr());
82 if (!(lock
= Lock(path
, SHARED_LOCK
)) || !Examine(lock
, fib
))
84 errno
= __stdc_ioerr2errno(IoErr());
88 /* set to previous id */
90 owner
= fib
->fib_OwnerUID
;
93 group
= fib
->fib_OwnerGID
;
95 if (owner
== fib
->fib_OwnerUID
&& group
== fib
->fib_OwnerGID
)
99 if (owner
> 65535 || group
> 65535)
105 if (changed
&& !SetOwner(path
, owner
<< 16 | group
))
107 errno
= __stdc_ioerr2errno(IoErr());
116 FreeDosObject(DOS_FIB
, fib
);