Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/xgetcwd.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/xgetcwd.c
r1765 r2725 6 6 * 7 7 * Special function for busybox written by Vladimir Oleynik <dzo@simtreas.ru> 8 */ 8 * 9 * Licensed under GPLv2, see file LICENSE in this source tree. 10 */ 9 11 10 12 #include "libbb.h" 11 12 /* Amount to increase buffer size by in each try. */13 #define PATH_INCR 3214 13 15 14 /* Return the current directory, newly allocated, arbitrarily long. … … 18 17 */ 19 18 20 char *19 char* FAST_FUNC 21 20 xrealloc_getcwd_or_warn(char *cwd) 22 21 { 22 #define PATH_INCR 64 23 23 24 char *ret; 24 25 unsigned path_max; 25 26 26 path_max = (unsigned) PATH_MAX; 27 path_max += 2; /* The getcwd docs say to do this. */ 27 path_max = 128; /* 128 + 64 should be enough for 99% of cases */ 28 28 29 if (cwd == NULL) 30 cwd = xmalloc(path_max); 31 32 while ((ret = getcwd(cwd, path_max)) == NULL && errno == ERANGE) { 29 while (1) { 33 30 path_max += PATH_INCR; 34 31 cwd = xrealloc(cwd, path_max); 32 ret = getcwd(cwd, path_max); 33 if (ret == NULL) { 34 if (errno == ERANGE) 35 continue; 36 free(cwd); 37 bb_perror_msg("getcwd"); 38 return NULL; 39 } 40 cwd = xrealloc(cwd, strlen(cwd) + 1); 41 return cwd; 35 42 } 36 37 if (ret == NULL) {38 free(cwd);39 bb_perror_msg("getcwd");40 return NULL;41 }42 43 return cwd;44 43 }
Note:
See TracChangeset
for help on using the changeset viewer.