Don't call ReadArgs() if started from WB.
[tangerine.git] / compiler / clib / chdir.c
blobb2fd526fa6788f63f23bfdc8811e369cd9a311ba
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function chdir().
6 */
8 #include "__arosc_privdata.h"
10 #include <exec/types.h>
11 #include <dos/dos.h>
12 #include <proto/dos.h>
13 #include <aros/symbolsets.h>
14 #include <errno.h>
15 #include "__errno.h"
16 #include "__upath.h"
18 /*****************************************************************************
20 NAME */
21 #include <unistd.h>
23 int chdir(
25 /* SYNOPSIS */
26 const char *path )
28 /* FUNCTION
29 Change the current working directory to the one specified by path.
31 INPUTS
32 path - Path of the directory to change to.
34 RESULT
35 If the current directory was changed successfully, zero is returned.
36 Otherwise, -1 is returned and errno set apropriately.
38 NOTES
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
46 (e.g. Workbench:).
48 EXAMPLE
50 BUGS
52 SEE ALSO
54 INTERNALS
56 ******************************************************************************/
58 BPTR oldlock;
59 BPTR newlock;
61 path = __path_u2a(path);
63 if (path == NULL)
64 return -1;
66 newlock = Lock( path, SHARED_LOCK );
68 if( newlock == NULL )
70 errno = IoErr2errno( IoErr() );
71 goto error;
74 if( SetCurrentDirName( path ) != DOSTRUE )
76 errno = ENAMETOOLONG;
77 goto error;
80 oldlock = CurrentDir( newlock );
82 if( __startup_cd_changed )
84 UnLock( oldlock );
86 else
88 __startup_cd_changed = TRUE;
89 __startup_cd_lock = oldlock;
92 return 0;
94 error:
95 if( newlock != NULL ) UnLock( newlock );
97 return -1;
100 int __init_chdir(void)
102 __startup_cd_changed = FALSE;
104 return 1;
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);
118 BPTR
119 lock = CurrentDir( __startup_cd_lock );
121 UnLock( lock );
125 ADD2INIT(__init_chdir, 110);
126 ADD2EXIT(__exit_chdir, 110);