Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/xgetcwd.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/xgetcwd.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * xgetcwd.c -- return current directory with unlimited length … … 7 8 */ 8 9 9 #include <stdlib.h>10 #include <errno.h>11 #include <unistd.h>12 #include <limits.h>13 #include <sys/param.h>14 10 #include "libbb.h" 15 11 … … 23 19 24 20 char * 25 x getcwd(char *cwd)21 xrealloc_getcwd_or_warn(char *cwd) 26 22 { 27 28 23 char *ret; 24 unsigned path_max; 29 25 30 31 26 path_max = (unsigned) PATH_MAX; 27 path_max += 2; /* The getcwd docs say to do this. */ 32 28 33 if(cwd==0)34 cwd = xmalloc(path_max);29 if (cwd == NULL) 30 cwd = xmalloc(path_max); 35 31 36 while ((ret = getcwd(cwd, path_max)) == NULL && errno == ERANGE) {37 38 cwd = xrealloc(cwd, path_max);39 32 while ((ret = getcwd(cwd, path_max)) == NULL && errno == ERANGE) { 33 path_max += PATH_INCR; 34 cwd = xrealloc(cwd, path_max); 35 } 40 36 41 42 free(cwd);43 bb_perror_msg("getcwd()");44 45 37 if (ret == NULL) { 38 free(cwd); 39 bb_perror_msg("getcwd"); 40 return NULL; 41 } 46 42 47 43 return cwd; 48 44 }
Note:
See TracChangeset
for help on using the changeset viewer.