version 1.1.1.2, 1995/02/25 09:11:43 |
version 1.3.4.1, 1995/05/02 19:34:46 |
|
|
/* |
/* |
* Copyright (c) 1989, 1991, 1993 |
* Copyright (c) 1989, 1991 The Regents of the University of California. |
* The Regents of the University of California. All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
*/ |
*/ |
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
#if defined(LIBC_SCCS) && !defined(lint) |
static char sccsid[] = "@(#)getcwd.c 8.1 (Berkeley) 6/4/93"; |
/*static char *sccsid = "from: @(#)getcwd.c 5.11 (Berkeley) 2/24/91";*/ |
|
static char *rcsid = "$Id$"; |
#endif /* LIBC_SCCS and not lint */ |
#endif /* LIBC_SCCS and not lint */ |
|
|
|
#include "namespace.h" |
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
#include <errno.h> |
#include <errno.h> |
#include <dirent.h> |
#include <dirent.h> |
#include <stdio.h> |
#include <stdio.h> |
|
|
ptsize = 0; |
ptsize = 0; |
if (!size) { |
if (!size) { |
errno = EINVAL; |
errno = EINVAL; |
return (NULL); |
return((char *)NULL); |
} |
} |
ept = pt + size; |
ept = pt + size; |
} else { |
} else { |
if ((pt = malloc(ptsize = 1024 - 4)) == NULL) |
if (!(pt = (char *)malloc(ptsize = 1024 - 4))) |
return (NULL); |
return((char *)NULL); |
ept = pt + ptsize; |
ept = pt + ptsize; |
} |
} |
bpt = ept - 1; |
bpt = ept - 1; |
|
|
* Should always be enough (it's 340 levels). If it's not, allocate |
* Should always be enough (it's 340 levels). If it's not, allocate |
* as necessary. Special * case the first stat, it's ".", not "..". |
* as necessary. Special * case the first stat, it's ".", not "..". |
*/ |
*/ |
if ((up = malloc(upsize = 1024 - 4)) == NULL) |
if (!(up = (char *)malloc(upsize = 1024 - 4))) |
goto err; |
goto err; |
eup = up + MAXPATHLEN; |
eup = up + MAXPATHLEN; |
bup = up; |
bup = up; |
Line 126 getcwd(pt, size) |
|
Line 127 getcwd(pt, size) |
|
*/ |
*/ |
(void)bcopy(bpt, pt, ept - bpt); |
(void)bcopy(bpt, pt, ept - bpt); |
free(up); |
free(up); |
return (pt); |
return(pt); |
} |
} |
|
|
/* |
/* |
Line 135 getcwd(pt, size) |
|
Line 136 getcwd(pt, size) |
|
* possible component name, plus a trailing NULL. |
* possible component name, plus a trailing NULL. |
*/ |
*/ |
if (bup + 3 + MAXNAMLEN + 1 >= eup) { |
if (bup + 3 + MAXNAMLEN + 1 >= eup) { |
if ((up = realloc(up, upsize *= 2)) == NULL) |
if (!(up = (char *)realloc(up, upsize *= 2))) |
goto err; |
goto err; |
bup = up; |
|
eup = up + upsize; |
eup = up + upsize; |
} |
} |
*bup++ = '.'; |
*bup++ = '.'; |
Line 196 getcwd(pt, size) |
|
Line 196 getcwd(pt, size) |
|
} |
} |
off = bpt - pt; |
off = bpt - pt; |
len = ept - bpt; |
len = ept - bpt; |
if ((pt = realloc(pt, ptsize *= 2)) == NULL) |
if (!(pt = (char *)realloc(pt, ptsize *= 2))) |
goto err; |
goto err; |
bpt = pt + off; |
bpt = pt + off; |
ept = pt + ptsize; |
ept = pt + ptsize; |
|
|
if (ptsize) |
if (ptsize) |
free(pt); |
free(pt); |
free(up); |
free(up); |
return (NULL); |
return((char *)NULL); |
} |
} |