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/miscutils/mountpoint.c

    r821 r1765  
    1010 */
    1111
    12 #include "busybox.h"
    13 #include <sys/stat.h>
    14 #include <errno.h> /* errno */
    15 #include <string.h> /* strerror */
    16 #include <getopt.h> /* optind */
     12#include "libbb.h"
    1713
     14int mountpoint_main(int argc, char **argv);
    1815int mountpoint_main(int argc, char **argv)
    1916{
    20     int opt = bb_getopt_ulflags(argc, argv, "qdx");
     17    struct stat st;
     18    char *arg;
     19    int opt = getopt32(argv, "qdx");
    2120#define OPT_q (1)
    2221#define OPT_d (2)
     
    2524    if (optind != argc - 1)
    2625        bb_show_usage();
    27     {
    28         char *arg = argv[optind];
    29         struct stat st;
    3026
    31         if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) {
    32             if (opt & OPT_x) {
    33                 if (S_ISBLK(st.st_mode))
    34                 {
    35                     bb_printf("%u:%u\n", major(st.st_rdev),
    36                                 minor(st.st_rdev));
    37                     return EXIT_SUCCESS;
    38                 } else {
    39                     if (opt & OPT_q)
    40                         putchar('\n');
    41                     else
    42                         bb_error_msg("%s: not a block device", arg);
    43                 }
    44                 return EXIT_FAILURE;
    45             } else
    46             if (S_ISDIR(st.st_mode)) {
    47                 dev_t st_dev = st.st_dev;
    48                 ino_t st_ino = st.st_ino;
    49                 char *p = bb_xasprintf("%s/..", arg);
     27    arg = argv[optind];
    5028
    51                 if (stat(p, &st) == 0) {
    52                     short ret = (st_dev != st.st_dev) ||
    53                         (st_dev == st.st_dev && st_ino == st.st_ino);
    54                     if (opt & OPT_d)
    55                         bb_printf("%u:%u\n", major(st_dev), minor(st_dev));
    56                     else if (!(opt & OPT_q))
    57                         bb_printf("%s is %sa mountpoint\n", arg, ret?"":"not ");
    58                     return !ret;
    59                 }
     29    if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) {
     30        if (opt & OPT_x) {
     31            if (S_ISBLK(st.st_mode)) {
     32                printf("%u:%u\n", major(st.st_rdev),
     33                            minor(st.st_rdev));
     34                return EXIT_SUCCESS;
    6035            } else {
    61                 if (!(opt & OPT_q))
    62                     bb_error_msg("%s: not a directory", arg);
    63                 return EXIT_FAILURE;
     36                if (opt & OPT_q)
     37                    putchar('\n');
     38                else
     39                    bb_error_msg("%s: not a block device", arg);
    6440            }
     41            return EXIT_FAILURE;
     42        } else
     43        if (S_ISDIR(st.st_mode)) {
     44            dev_t st_dev = st.st_dev;
     45            ino_t st_ino = st.st_ino;
     46            char *p = xasprintf("%s/..", arg);
     47
     48            if (stat(p, &st) == 0) {
     49                int ret = (st_dev != st.st_dev) ||
     50                    (st_dev == st.st_dev && st_ino == st.st_ino);
     51                if (opt & OPT_d)
     52                    printf("%u:%u\n", major(st_dev), minor(st_dev));
     53                else if (!(opt & OPT_q))
     54                    printf("%s is %sa mountpoint\n", arg, ret?"":"not ");
     55                return !ret;
     56            }
     57        } else {
     58            if (!(opt & OPT_q))
     59                bb_error_msg("%s: not a directory", arg);
     60            return EXIT_FAILURE;
    6561        }
    66         if (!(opt & OPT_q))
    67             bb_perror_msg("%s", arg);
    68         return EXIT_FAILURE;
    6962    }
     63    if (!(opt & OPT_q))
     64        bb_perror_msg("%s", arg);
     65    return EXIT_FAILURE;
    7066}
Note: See TracChangeset for help on using the changeset viewer.