2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 POSIX.1-2008 function chdir().
8 #include "__posixc_intbase.h"
10 #include <exec/types.h>
12 #include <proto/dos.h>
13 #include <aros/symbolsets.h>
17 /*****************************************************************************
28 Change the current working directory to the one specified by path.
31 path - Path of the directory to change to.
34 If the current directory was changed successfully, zero is returned.
35 Otherwise, -1 is returned and errno set apropriately.
38 At program exit, the current working directory will be changed back
39 to the one that was current when the program first started. If you
40 do not desire this behaviour, use dos.library/CurrentDir() instead.
41 The path given to chdir can be translated so that getcwd gives back
42 a string that is not the same but points to th same directory. For
43 example, assigns are replaced by the path where the assign points to
44 and device names (like DH0:) are replaced with the volume name
55 ******************************************************************************/
57 struct PosixCIntBase
*PosixCBase
=
58 (struct PosixCIntBase
*)__aros_getbase_PosixCBase();
62 path
= __path_u2a(path
);
67 newlock
= Lock( path
, SHARED_LOCK
);
69 if( newlock
== BNULL
)
71 errno
= __stdc_ioerr2errno( IoErr() );
75 oldlock
= CurrentDir( newlock
);
77 if( PosixCBase
->cd_changed
)
83 PosixCBase
->cd_changed
= TRUE
;
84 PosixCBase
->cd_lock
= oldlock
;
90 if( newlock
!= BNULL
) UnLock( newlock
);
95 int __init_chdir(struct PosixCIntBase
*PosixCBase
)
97 PosixCBase
->cd_changed
= FALSE
;
102 void __exit_chdir(struct PosixCIntBase
*PosixCBase
)
104 if( PosixCBase
->cd_changed
)
106 BPTR lock
= CurrentDir( PosixCBase
->cd_lock
);
112 ADD2OPENLIB(__init_chdir
, -100);
113 ADD2CLOSELIB(__exit_chdir
, -100);