2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 ANSI C function getcwd().
14 #include <proto/exec.h>
15 #include <proto/dos.h>
17 /*****************************************************************************
29 Get the current working directory.
32 buf - Pointer of the buffer where the path is to be stored
33 size - The size of the above buffer
36 Copies the absolute pathname of the current working directory
37 to the buffer. If the pathname is longer than the buffer
38 (with lenght "size") NULL is returned and errno set to ERANGE.
39 Otherwise the pointer to the buffer is returned.
42 If buf is NULL this function will allocate the buffer itself
43 using malloc() and the specified size "size". If size is
44 0, too, the buffer is allocated to hold the whole path.
45 It is possible and recommended to free() this buffer yourself!
46 The path returned does not have to be literally the same as the
47 one given to chdir. See NOTES from chdir for more explanation.
58 ******************************************************************************/
60 char pathname
[FILENAME_MAX
];
64 lock
= CurrentDir(NULL
);
66 if (NameFromLock (lock
, pathname
, FILENAME_MAX
) == 0)
68 errno
= IoErr2errno (IoErr ());
72 tpath
= __path_a2u(pathname
);
73 strcpy(pathname
, tpath
);
77 if (strlen(pathname
) < size
)
79 strcpy (buf
, pathname
);
92 len
= strlen(pathname
);
101 newbuf
= (char *)malloc (size
*sizeof(char));
102 strcpy (newbuf
, pathname
);