Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/xgetcwd.c


Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • 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:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/libbb/xgetcwd.c

    r1765 r2725  
    66 *
    77 * 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 */
    911
    1012#include "libbb.h"
    11 
    12 /* Amount to increase buffer size by in each try. */
    13 #define PATH_INCR 32
    1413
    1514/* Return the current directory, newly allocated, arbitrarily long.
     
    1817*/
    1918
    20 char *
     19char* FAST_FUNC
    2120xrealloc_getcwd_or_warn(char *cwd)
    2221{
     22#define PATH_INCR 64
     23
    2324    char *ret;
    2425    unsigned path_max;
    2526
    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 */
    2828
    29     if (cwd == NULL)
    30         cwd = xmalloc(path_max);
    31 
    32     while ((ret = getcwd(cwd, path_max)) == NULL && errno == ERANGE) {
     29    while (1) {
    3330        path_max += PATH_INCR;
    3431        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;
    3542    }
    36 
    37     if (ret == NULL) {
    38         free(cwd);
    39         bb_perror_msg("getcwd");
    40         return NULL;
    41     }
    42 
    43     return cwd;
    4443}
Note: See TracChangeset for help on using the changeset viewer.