Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/coreutils/pwd.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/coreutils/pwd.c

    r2725 r3232  
    88 */
    99
     10//usage:#define pwd_trivial_usage
     11//usage:       ""
     12//usage:#define pwd_full_usage "\n\n"
     13//usage:       "Print the full filename of the current working directory"
     14//usage:
     15//usage:#define pwd_example_usage
     16//usage:       "$ pwd\n"
     17//usage:       "/root\n"
     18
    1019#include "libbb.h"
    1120
    1221/* This is a NOFORK applet. Be very careful! */
     22
     23static int logical_getcwd(void)
     24{
     25    struct stat st1;
     26    struct stat st2;
     27    char *wd;
     28    char *p;
     29
     30    wd = getenv("PWD");
     31    if (!wd || wd[0] != '/')
     32        return 0;
     33
     34    p = wd;
     35    while (*p) {
     36        /* doing strstr(p, "/.") by hand is smaller and faster... */
     37        if (*p++ != '/')
     38            continue;
     39        if (*p != '.')
     40            continue;
     41        /* we found "/.", skip to next char */
     42        p++;
     43        if (*p == '.')
     44            p++; /* we found "/.." */
     45        if (*p == '\0' || *p == '/')
     46            return 0; /* "/./" or "/../" component: bad */
     47    }
     48
     49    if (stat(wd, &st1) != 0)
     50        return 0;
     51    if (stat(".", &st2) != 0)
     52        return 0;
     53    if (st1.st_ino != st2.st_ino)
     54        return 0;
     55    if (st1.st_dev != st2.st_dev)
     56        return 0;
     57
     58    puts(wd);
     59    return 1;
     60}
    1361
    1462int pwd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    1765    char *buf;
    1866
     67    if (ENABLE_DESKTOP) {
     68        /* TODO: assume -L if $POSIXLY_CORRECT? (coreutils does that)
     69         * Rationale:
     70         * POSIX requires a default of -L, but most scripts expect -P
     71         */
     72        unsigned opt = getopt32(argv, "LP");
     73        if ((opt & 1) && logical_getcwd())
     74            return fflush_all();
     75    }
     76
    1977    buf = xrealloc_getcwd_or_warn(NULL);
    20     if (buf != NULL) {
     78
     79    if (buf) {
    2180        puts(buf);
    2281        free(buf);
Note: See TracChangeset for help on using the changeset viewer.