2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 POSIX.1-2008 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
];
63 lock
= CurrentDir(BNULL
);
65 if (NameFromLock (lock
, pathname
, FILENAME_MAX
) == 0)
67 errno
= __stdc_ioerr2errno (IoErr ());
71 tpath
= __path_a2u(pathname
);
72 strcpy(pathname
, tpath
);
76 if (strlen(pathname
) < size
)
78 strcpy (buf
, pathname
);
91 len
= strlen(pathname
);
100 newbuf
= (char *)malloc (size
*sizeof(char));
101 strcpy (newbuf
, pathname
);