[uClibc-cvs] uClibc/libc/sysdeps/linux/common getcwd.c,1.2,1.3
Erik Andersen
andersen at codepoet.org
Wed Dec 4 00:08:56 UTC 2002
Update of /var/cvs/uClibc/libc/sysdeps/linux/common
In directory winder:/tmp/cvs-serv17346/libc/sysdeps/linux/common
Modified Files:
getcwd.c
Log Message:
Properly allocate memory when size is 0, but so is buf
Index: getcwd.c
===================================================================
RCS file: /var/cvs/uClibc/libc/sysdeps/linux/common/getcwd.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- getcwd.c 22 Jul 2002 17:10:09 -0000 1.2
+++ getcwd.c 4 Dec 2002 00:08:52 -0000 1.3
@@ -17,33 +17,36 @@
char *getcwd(char *buf, int size)
{
- int olderrno, ret;
- char *allocbuf;
-
- if (size == 0) {
- __set_errno(EINVAL);
- return NULL;
- }
- if (size < 3) {
- __set_errno(ERANGE);
- return NULL;
- }
- allocbuf=NULL;
- olderrno = errno;
- if (buf == NULL) {
- buf = allocbuf = malloc (size);
- if (buf == NULL)
- return NULL;
+ int olderrno, ret;
+ char *allocbuf;
+
+ if (size == 0) {
+ if (buf != NULL) {
+ __set_errno(EINVAL);
+ return NULL;
}
- ret = INLINE_SYSCALL(getcwd, 2, buf, size);
- if (ret < 0) {
- if (allocbuf) {
- free(allocbuf);
- }
+ size = PATH_MAX;
+ }
+ if (size < 3) {
+ __set_errno(ERANGE);
+ return NULL;
+ }
+ allocbuf=NULL;
+ olderrno = errno;
+ if (buf == NULL) {
+ buf = allocbuf = malloc (size);
+ if (buf == NULL)
return NULL;
- }
- __set_errno(olderrno);
- return buf;
+ }
+ ret = INLINE_SYSCALL(getcwd, 2, buf, size);
+ if (ret < 0) {
+ if (allocbuf) {
+ free(allocbuf);
+ }
+ return NULL;
+ }
+ __set_errno(olderrno);
+ return buf;
}
#else
More information about the uClibc-cvs
mailing list