2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 ANSI C function chdir().
8 #include "__arosc_privdata.h"
10 #include <exec/types.h>
12 #include <proto/dos.h>
13 #include <aros/symbolsets.h>
18 /*****************************************************************************
29 Change the current working directory to the one specified by path.
32 path - Path of the directory to change to.
35 If the current directory was changed successfully, zero is returned.
36 Otherwise, -1 is returned and errno set apropriately.
39 At program exit, the current working directory will be changed back
40 to the one that was current when the program first started. If you
41 do not desire this behaviour, use dos.library/CurrentDir() instead.
42 The path given to chdir can be translated so that getcwd gives back
43 a string that is not the same but points to th same directory. For
44 example, assigns are replaced by the path where the assign points to
45 and device names (like DH0:) are replaced with the volume name
56 ******************************************************************************/
61 path
= __path_u2a(path
);
66 newlock
= Lock( path
, SHARED_LOCK
);
70 errno
= IoErr2errno( IoErr() );
74 if( SetCurrentDirName( path
) != DOSTRUE
)
80 oldlock
= CurrentDir( newlock
);
82 if( __startup_cd_changed
)
88 __startup_cd_changed
= TRUE
;
89 __startup_cd_lock
= oldlock
;
95 if( newlock
!= NULL
) UnLock( newlock
);
100 int __init_chdir(void)
102 __startup_cd_changed
= FALSE
;
107 void __exit_chdir(void)
109 if( __startup_cd_changed
)
111 TEXT buffer
[256]; /* Longest string supported by SetCurrentDirName() */
113 if( NameFromLock( __startup_cd_lock
, buffer
, 256 ) )
115 SetCurrentDirName(buffer
);
119 lock
= CurrentDir( __startup_cd_lock
);
125 ADD2INIT(__init_chdir
, 110);
126 ADD2EXIT(__exit_chdir
, 110);