Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/xreadlink.c

    r821 r1765  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 *  xreadlink.c - safe implementation of readlink.
     
    45 */
    56
    6 #include <stdio.h>
     7#include "libbb.h"
    78
    89/*
     
    1011 * yourself. You have been warned.
    1112 */
    12 
    13 #include <unistd.h>
    14 #include "libbb.h"
    15 
    16 char *xreadlink(const char *path)
     13char *xmalloc_readlink(const char *path)
    1714{
    1815    enum { GROWBY = 80 }; /* how large we will grow strings by */
     
    2320    do {
    2421        buf = xrealloc(buf, bufsize += GROWBY);
    25         readsize = readlink(path, buf, bufsize); /* 1st try */
     22        readsize = readlink(path, buf, bufsize);
    2623        if (readsize == -1) {
    27             bb_perror_msg("%s", path);
    2824            free(buf);
    2925            return NULL;
    3026        }
    31     }
    32     while (bufsize < readsize + 1);
     27    } while (bufsize < readsize + 1);
    3328
    3429    buf[readsize] = '\0';
     
    3631    return buf;
    3732}
     33
     34char *xmalloc_readlink_or_warn(const char *path)
     35{
     36    char *buf = xmalloc_readlink(path);
     37    if (!buf) {
     38        /* EINVAL => "file: Invalid argument" => puzzled user */
     39        bb_error_msg("%s: cannot read link (not a symlink?)", path);
     40    }
     41    return buf;
     42}
     43
     44/* UNUSED */
     45#if 0
     46char *xmalloc_realpath(const char *path)
     47{
     48#if defined(__GLIBC__) && !defined(__UCLIBC__)
     49    /* glibc provides a non-standard extension */
     50    return realpath(path, NULL);
     51#else
     52    char buf[PATH_MAX+1];
     53
     54    /* on error returns NULL (xstrdup(NULL) ==NULL) */
     55    return xstrdup(realpath(path, buf));
     56#endif
     57}
     58#endif
Note: See TracChangeset for help on using the changeset viewer.