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