]> git.saurik.com Git - apple/file_cmds.git/blobdiff - stat/stat.c
file_cmds-321.100.10.0.1.tar.gz
[apple/file_cmds.git] / stat / stat.c
index 78f8107b4c663428331c1764e7fb08e25ac36845..610eff94d732e87e01652a40196fa77cd51c5d2f 100644 (file)
@@ -41,17 +41,16 @@ __RCSID("$NetBSD: stat.c,v 1.13 2003/07/25 03:21:17 atatat Exp $");
 #endif
 #endif
 
-/* Commenting FBSDID, as it is not needed in OSX.
 __FBSDID("$FreeBSD: src/usr.bin/stat/stat.c,v 1.6 2003/10/06 01:55:17 dougb Exp $");
-*/
 
 #if HAVE_CONFIG_H
 #include "config.h" 
 #else  /* HAVE_CONFIG_H */
 #define HAVE_STRUCT_STAT_ST_FLAGS 1
 #define HAVE_STRUCT_STAT_ST_GEN 1
-#define HAVE_STRUCT_STAT_ST_BIRTHTIME 0 /* was 1; not needed if ! __BSD_VISIBLE ? */
+#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
 #define HAVE_STRUCT_STAT_ST_MTIMENSEC 1
+#define HAVE_STRUCT_STAT_ST_ATIM 0
 #define HAVE_DEVNAME 1
 #endif /* HAVE_CONFIG_H */
 
@@ -110,7 +109,7 @@ __FBSDID("$FreeBSD: src/usr.bin/stat/stat.c,v 1.6 2003/10/06 01:55:17 dougb Exp
 #define LINUX_FORMAT \
        "  File: \"%N\"%n" \
        "  Size: %-11z  FileType: %HT%n" \
-       "  Mode: (%04OLp/%.10Sp)         Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%n" \
+       "  Mode: (%04OA/%.10Sp)         Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%n" \
        "Device: %Hd,%Ld   Inode: %i    Links: %l%n" \
        "Access: %Sa%n" \
        "Modify: %Sm%n" \
@@ -162,6 +161,7 @@ __FBSDID("$FreeBSD: src/usr.bin/stat/stat.c,v 1.6 2003/10/06 01:55:17 dougb Exp
 #define SHOW_st_dev    'd'
 #define SHOW_st_ino    'i'
 #define SHOW_st_mode   'p'
+#define SHOW_st_mode2  'A'
 #define SHOW_st_nlink  'l'
 #define SHOW_st_uid    'u'
 #define SHOW_st_gid    'g'
@@ -487,6 +487,7 @@ output(const struct stat *st, const char *file,
                        fmtcase(what, SHOW_st_dev);
                        fmtcase(what, SHOW_st_ino);
                        fmtcase(what, SHOW_st_mode);
+                       fmtcase(what, SHOW_st_mode2);
                        fmtcase(what, SHOW_st_nlink);
                        fmtcase(what, SHOW_st_uid);
                        fmtcase(what, SHOW_st_gid);
@@ -548,13 +549,13 @@ format1(const struct stat *st,
        struct passwd *pw;
        struct group *gr;
        const struct timespec *tsp;
-       struct timespec ts;
+       struct timespec ts = {0,0};
        struct tm *tm;
        int l, small, formats;
 
        tsp = NULL;
-       formats = 0;
-       small = 0;
+//     formats = 0;
+//     small = 0;
 
        /*
         * First, pick out the data and tweak it based on hilo or
@@ -601,6 +602,7 @@ format1(const struct stat *st,
                        ofmt = FMTF_UNSIGNED;
                break;
        case SHOW_st_mode:
+       case SHOW_st_mode2:
                small = (sizeof(st->st_mode) == 4);
                data = st->st_mode;
                strmode(st->st_mode, smode);
@@ -608,6 +610,8 @@ format1(const struct stat *st,
                l = strlen(sdata);
                if (sdata[l - 1] == ' ')
                        sdata[--l] = '\0';
+               if (what == SHOW_st_mode2)
+                       data &= 07777;
                if (hilo == HIGH_PIECE) {
                        data >>= 12;
                        sdata += 1;
@@ -686,8 +690,11 @@ format1(const struct stat *st,
                ts = *tsp;              /* copy so we can muck with it */
                small = (sizeof(ts.tv_sec) == 4);
                data = ts.tv_sec;
-               small = 1;
                tm = localtime(&ts.tv_sec);
+               if (tm == NULL) {
+                       ts.tv_sec = 0;
+                       tm = localtime(&ts.tv_sec);
+               }
                (void)strftime(path, sizeof(path), timefmt, tm);
                sdata = path;
                formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
@@ -724,7 +731,14 @@ format1(const struct stat *st,
                small = (sizeof(st->st_flags) == 4);
                data = st->st_flags;
                sdata = NULL;
-               formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
+               formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
+                       FMTF_STRING;
+               if (ofmt == FMTF_STRING) {
+                       small = 0;
+                       data = 0;
+                       snprintf(path, sizeof(path), "%s", fflagstostr(st->st_flags));
+                       sdata = path;
+               }
                if (ofmt == 0)
                        ofmt = FMTF_UNSIGNED;
                break;