123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "libbb.h"
- char* FAST_FUNC
- xrealloc_getcwd_or_warn(char *cwd)
- {
- #define PATH_INCR 64
- char *ret;
- unsigned path_max;
- path_max = 128;
- while (1) {
- path_max += PATH_INCR;
- cwd = xrealloc(cwd, path_max);
- ret = getcwd(cwd, path_max);
- if (ret == NULL) {
- if (errno == ERANGE)
- continue;
- free(cwd);
- bb_perror_msg("getcwd");
- return NULL;
- }
- cwd = xrealloc(cwd, strlen(cwd) + 1);
- return cwd;
- }
- }
|