Last change
on this file since 2896 was 2725, checked in by Bruno Cornec, 13 years ago |
- Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
|
File size:
1015 bytes
|
Rev | Line | |
---|
[1765] | 1 | /* vi: set sw=4 ts=4: */
|
---|
[821] | 2 | /*
|
---|
| 3 | * xgetcwd.c -- return current directory with unlimited length
|
---|
| 4 | * Copyright (C) 1992, 1996 Free Software Foundation, Inc.
|
---|
| 5 | * Written by David MacKenzie <djm@gnu.ai.mit.edu>.
|
---|
| 6 | *
|
---|
| 7 | * Special function for busybox written by Vladimir Oleynik <dzo@simtreas.ru>
|
---|
[2725] | 8 | *
|
---|
| 9 | * Licensed under GPLv2, see file LICENSE in this source tree.
|
---|
| 10 | */
|
---|
[821] | 11 |
|
---|
| 12 | #include "libbb.h"
|
---|
| 13 |
|
---|
| 14 | /* Return the current directory, newly allocated, arbitrarily long.
|
---|
| 15 | Return NULL and set errno on error.
|
---|
| 16 | If argument is not NULL (previous usage allocate memory), call free()
|
---|
| 17 | */
|
---|
| 18 |
|
---|
[2725] | 19 | char* FAST_FUNC
|
---|
[1765] | 20 | xrealloc_getcwd_or_warn(char *cwd)
|
---|
[821] | 21 | {
|
---|
[2725] | 22 | #define PATH_INCR 64
|
---|
| 23 |
|
---|
[1765] | 24 | char *ret;
|
---|
| 25 | unsigned path_max;
|
---|
[821] | 26 |
|
---|
[2725] | 27 | path_max = 128; /* 128 + 64 should be enough for 99% of cases */
|
---|
[821] | 28 |
|
---|
[2725] | 29 | while (1) {
|
---|
[1765] | 30 | path_max += PATH_INCR;
|
---|
| 31 | cwd = xrealloc(cwd, path_max);
|
---|
[2725] | 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;
|
---|
[1765] | 42 | }
|
---|
[821] | 43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.