diff options
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/stat.c | 191 |
1 files changed, 97 insertions, 94 deletions
diff --git a/coreutils/stat.c b/coreutils/stat.c index a0424d936..ed6580ef0 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
| @@ -16,14 +16,12 @@ | |||
| 16 | #include "libbb.h" | 16 | #include "libbb.h" |
| 17 | 17 | ||
| 18 | /* vars to control behavior */ | 18 | /* vars to control behavior */ |
| 19 | #define OPT_FILESYS (1<<0) | 19 | #define OPT_FILESYS (1 << 0) |
| 20 | #define OPT_TERSE (1<<1) | 20 | #define OPT_TERSE (1 << 1) |
| 21 | #define OPT_DEREFERENCE (1<<2) | 21 | #define OPT_DEREFERENCE (1 << 2) |
| 22 | #define OPT_SELINUX (1<<3) | 22 | #define OPT_SELINUX (1 << 3) |
| 23 | 23 | ||
| 24 | static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1; | 24 | static const char *file_type(const struct stat *st) |
| 25 | |||
| 26 | static char const * file_type(struct stat const *st) | ||
| 27 | { | 25 | { |
| 28 | /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 | 26 | /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 |
| 29 | * for some of these formats. | 27 | * for some of these formats. |
| @@ -46,7 +44,7 @@ static char const * file_type(struct stat const *st) | |||
| 46 | return "weird file"; | 44 | return "weird file"; |
| 47 | } | 45 | } |
| 48 | 46 | ||
| 49 | static char const *human_time(time_t t) | 47 | static const char *human_time(time_t t) |
| 50 | { | 48 | { |
| 51 | /* Old | 49 | /* Old |
| 52 | static char *str; | 50 | static char *str; |
| @@ -56,8 +54,12 @@ static char const *human_time(time_t t) | |||
| 56 | */ | 54 | */ |
| 57 | /* coreutils 6.3 compat: */ | 55 | /* coreutils 6.3 compat: */ |
| 58 | 56 | ||
| 57 | /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ | ||
| 58 | #define buf bb_common_bufsiz1 | ||
| 59 | |||
| 59 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t)); | 60 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t)); |
| 60 | return buf; | 61 | return buf; |
| 62 | #undef buf | ||
| 61 | } | 63 | } |
| 62 | 64 | ||
| 63 | /* Return the type of the specified file system. | 65 | /* Return the type of the specified file system. |
| @@ -65,11 +67,10 @@ static char const *human_time(time_t t) | |||
| 65 | * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2) | 67 | * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2) |
| 66 | * Still others have neither and have to get by with f_type (Linux). | 68 | * Still others have neither and have to get by with f_type (Linux). |
| 67 | */ | 69 | */ |
| 68 | static char const *human_fstype(long f_type) | 70 | static const char *human_fstype(uint32_t f_type) |
| 69 | { | 71 | { |
| 70 | int i; | ||
| 71 | static const struct types { | 72 | static const struct types { |
| 72 | long type; | 73 | uint32_t type; |
| 73 | const char *const fs; | 74 | const char *const fs; |
| 74 | } humantypes[] = { | 75 | } humantypes[] = { |
| 75 | { 0xADFF, "affs" }, | 76 | { 0xADFF, "affs" }, |
| @@ -109,67 +110,80 @@ static char const *human_fstype(long f_type) | |||
| 109 | { 0x62656572, "sysfs" }, | 110 | { 0x62656572, "sysfs" }, |
| 110 | { 0, "UNKNOWN" } | 111 | { 0, "UNKNOWN" } |
| 111 | }; | 112 | }; |
| 113 | |||
| 114 | int i; | ||
| 115 | |||
| 112 | for (i = 0; humantypes[i].type; ++i) | 116 | for (i = 0; humantypes[i].type; ++i) |
| 113 | if (humantypes[i].type == f_type) | 117 | if (humantypes[i].type == f_type) |
| 114 | break; | 118 | break; |
| 115 | return humantypes[i].fs; | 119 | return humantypes[i].fs; |
| 116 | } | 120 | } |
| 117 | 121 | ||
| 122 | static void strcatc(char *str, char c) | ||
| 123 | { | ||
| 124 | int len = strlen(str); | ||
| 125 | str[len++] = c; | ||
| 126 | str[len] = '\0'; | ||
| 127 | } | ||
| 128 | |||
| 129 | static void printfs(char *pformat, const char *msg) | ||
| 130 | { | ||
| 131 | strcatc(pformat, 's'); | ||
| 132 | printf(pformat, msg); | ||
| 133 | } | ||
| 134 | |||
| 118 | #if ENABLE_FEATURE_STAT_FORMAT | 135 | #if ENABLE_FEATURE_STAT_FORMAT |
| 119 | /* print statfs info */ | 136 | /* print statfs info */ |
| 120 | static void print_statfs(char *pformat, const size_t buf_len, const char m, | 137 | static void print_statfs(char *pformat, const char m, |
| 121 | const char *const filename, void const *data | 138 | const char *const filename, const void *data |
| 122 | USE_SELINUX(, security_context_t scontext)) | 139 | USE_SELINUX(, security_context_t scontext)) |
| 123 | { | 140 | { |
| 124 | struct statfs const *statfsbuf = data; | 141 | const struct statfs *statfsbuf = data; |
| 125 | if (m == 'n') { | 142 | if (m == 'n') { |
| 126 | strncat(pformat, "s", buf_len); | 143 | printfs(pformat, filename); |
| 127 | printf(pformat, filename); | ||
| 128 | } else if (m == 'i') { | 144 | } else if (m == 'i') { |
| 129 | strncat(pformat, "Lx", buf_len); | 145 | strcat(pformat, "Lx"); |
| 130 | printf(pformat, statfsbuf->f_fsid); | 146 | printf(pformat, statfsbuf->f_fsid); |
| 131 | } else if (m == 'l') { | 147 | } else if (m == 'l') { |
| 132 | strncat(pformat, "lu", buf_len); | 148 | strcat(pformat, "lu"); |
| 133 | printf(pformat, statfsbuf->f_namelen); | 149 | printf(pformat, statfsbuf->f_namelen); |
| 134 | } else if (m == 't') { | 150 | } else if (m == 't') { |
| 135 | strncat(pformat, "lx", buf_len); | 151 | strcat(pformat, "lx"); |
| 136 | printf(pformat, (unsigned long) (statfsbuf->f_type)); /* no equiv */ | 152 | printf(pformat, (unsigned long) (statfsbuf->f_type)); /* no equiv */ |
| 137 | } else if (m == 'T') { | 153 | } else if (m == 'T') { |
| 138 | strncat(pformat, "s", buf_len); | 154 | printfs(pformat, human_fstype(statfsbuf->f_type)); |
| 139 | printf(pformat, human_fstype(statfsbuf->f_type)); | ||
| 140 | } else if (m == 'b') { | 155 | } else if (m == 'b') { |
| 141 | strncat(pformat, "jd", buf_len); | 156 | strcat(pformat, "jd"); |
| 142 | printf(pformat, (intmax_t) (statfsbuf->f_blocks)); | 157 | printf(pformat, (intmax_t) (statfsbuf->f_blocks)); |
| 143 | } else if (m == 'f') { | 158 | } else if (m == 'f') { |
| 144 | strncat(pformat, "jd", buf_len); | 159 | strcat(pformat, "jd"); |
| 145 | printf(pformat, (intmax_t) (statfsbuf->f_bfree)); | 160 | printf(pformat, (intmax_t) (statfsbuf->f_bfree)); |
| 146 | } else if (m == 'a') { | 161 | } else if (m == 'a') { |
| 147 | strncat(pformat, "jd", buf_len); | 162 | strcat(pformat, "jd"); |
| 148 | printf(pformat, (intmax_t) (statfsbuf->f_bavail)); | 163 | printf(pformat, (intmax_t) (statfsbuf->f_bavail)); |
| 149 | } else if (m == 's' || m == 'S') { | 164 | } else if (m == 's' || m == 'S') { |
| 150 | strncat(pformat, "lu", buf_len); | 165 | strcat(pformat, "lu"); |
| 151 | printf(pformat, (unsigned long) (statfsbuf->f_bsize)); | 166 | printf(pformat, (unsigned long) (statfsbuf->f_bsize)); |
| 152 | } else if (m == 'c') { | 167 | } else if (m == 'c') { |
| 153 | strncat(pformat, "jd", buf_len); | 168 | strcat(pformat, "jd"); |
| 154 | printf(pformat, (intmax_t) (statfsbuf->f_files)); | 169 | printf(pformat, (intmax_t) (statfsbuf->f_files)); |
| 155 | } else if (m == 'd') { | 170 | } else if (m == 'd') { |
| 156 | strncat(pformat, "jd", buf_len); | 171 | strcat(pformat, "jd"); |
| 157 | printf(pformat, (intmax_t) (statfsbuf->f_ffree)); | 172 | printf(pformat, (intmax_t) (statfsbuf->f_ffree)); |
| 158 | #if ENABLE_SELINUX | 173 | #if ENABLE_SELINUX |
| 159 | } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) { | 174 | } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) { |
| 160 | strncat(pformat, "s", buf_len); | 175 | printfs(pformat, scontext); |
| 161 | printf(scontext); | ||
| 162 | #endif | 176 | #endif |
| 163 | } else { | 177 | } else { |
| 164 | strncat(pformat, "c", buf_len); | 178 | strcatc(pformat, 'c'); |
| 165 | printf(pformat, m); | 179 | printf(pformat, m); |
| 166 | } | 180 | } |
| 167 | } | 181 | } |
| 168 | 182 | ||
| 169 | /* print stat info */ | 183 | /* print stat info */ |
| 170 | static void print_stat(char *pformat, const size_t buf_len, const char m, | 184 | static void print_stat(char *pformat, const char m, |
| 171 | const char *const filename, void const *data | 185 | const char *const filename, const void *data |
| 172 | USE_SELINUX(, security_context_t scontext)) | 186 | USE_SELINUX(, security_context_t scontext)) |
| 173 | { | 187 | { |
| 174 | #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) | 188 | #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) |
| 175 | struct stat *statbuf = (struct stat *) data; | 189 | struct stat *statbuf = (struct stat *) data; |
| @@ -177,131 +191,118 @@ static void print_stat(char *pformat, const size_t buf_len, const char m, | |||
| 177 | struct group *gw_ent; | 191 | struct group *gw_ent; |
| 178 | 192 | ||
| 179 | if (m == 'n') { | 193 | if (m == 'n') { |
| 180 | strncat(pformat, "s", buf_len); | 194 | printfs(pformat, filename); |
| 181 | printf(pformat, filename); | ||
| 182 | } else if (m == 'N') { | 195 | } else if (m == 'N') { |
| 183 | strncat(pformat, "s", buf_len); | 196 | strcatc(pformat, 's'); |
| 184 | if (S_ISLNK(statbuf->st_mode)) { | 197 | if (S_ISLNK(statbuf->st_mode)) { |
| 185 | char *linkname = xmalloc_readlink_or_warn(filename); | 198 | char *linkname = xmalloc_readlink_or_warn(filename); |
| 186 | if (linkname == NULL) { | 199 | if (linkname == NULL) |
| 187 | bb_perror_msg("cannot read symbolic link '%s'", filename); | ||
| 188 | return; | 200 | return; |
| 189 | } | ||
| 190 | /*printf("\"%s\" -> \"%s\"", filename, linkname); */ | 201 | /*printf("\"%s\" -> \"%s\"", filename, linkname); */ |
| 191 | printf(pformat, filename); | 202 | printf(pformat, filename); |
| 192 | printf(" -> "); | 203 | printf(" -> "); |
| 193 | printf(pformat, linkname); | 204 | printf(pformat, linkname); |
| 205 | free(linkname); | ||
| 194 | } else { | 206 | } else { |
| 195 | printf(pformat, filename); | 207 | printf(pformat, filename); |
| 196 | } | 208 | } |
| 197 | } else if (m == 'd') { | 209 | } else if (m == 'd') { |
| 198 | strncat(pformat, "ju", buf_len); | 210 | strcat(pformat, "ju"); |
| 199 | printf(pformat, (uintmax_t) statbuf->st_dev); | 211 | printf(pformat, (uintmax_t) statbuf->st_dev); |
| 200 | } else if (m == 'D') { | 212 | } else if (m == 'D') { |
| 201 | strncat(pformat, "jx", buf_len); | 213 | strcat(pformat, "jx"); |
| 202 | printf(pformat, (uintmax_t) statbuf->st_dev); | 214 | printf(pformat, (uintmax_t) statbuf->st_dev); |
| 203 | } else if (m == 'i') { | 215 | } else if (m == 'i') { |
| 204 | strncat(pformat, "ju", buf_len); | 216 | strcat(pformat, "ju"); |
| 205 | printf(pformat, (uintmax_t) statbuf->st_ino); | 217 | printf(pformat, (uintmax_t) statbuf->st_ino); |
| 206 | } else if (m == 'a') { | 218 | } else if (m == 'a') { |
| 207 | strncat(pformat, "lo", buf_len); | 219 | strcat(pformat, "lo"); |
| 208 | printf(pformat, (unsigned long) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO))); | 220 | printf(pformat, (unsigned long) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO))); |
| 209 | } else if (m == 'A') { | 221 | } else if (m == 'A') { |
| 210 | strncat(pformat, "s", buf_len); | 222 | printfs(pformat, bb_mode_string(statbuf->st_mode)); |
| 211 | printf(pformat, bb_mode_string(statbuf->st_mode)); | ||
| 212 | } else if (m == 'f') { | 223 | } else if (m == 'f') { |
| 213 | strncat(pformat, "lx", buf_len); | 224 | strcat(pformat, "lx"); |
| 214 | printf(pformat, (unsigned long) statbuf->st_mode); | 225 | printf(pformat, (unsigned long) statbuf->st_mode); |
| 215 | } else if (m == 'F') { | 226 | } else if (m == 'F') { |
| 216 | strncat(pformat, "s", buf_len); | 227 | printfs(pformat, file_type(statbuf)); |
| 217 | printf(pformat, file_type(statbuf)); | ||
| 218 | } else if (m == 'h') { | 228 | } else if (m == 'h') { |
| 219 | strncat(pformat, "lu", buf_len); | 229 | strcat(pformat, "lu"); |
| 220 | printf(pformat, (unsigned long) statbuf->st_nlink); | 230 | printf(pformat, (unsigned long) statbuf->st_nlink); |
| 221 | } else if (m == 'u') { | 231 | } else if (m == 'u') { |
| 222 | strncat(pformat, "lu", buf_len); | 232 | strcat(pformat, "lu"); |
| 223 | printf(pformat, (unsigned long) statbuf->st_uid); | 233 | printf(pformat, (unsigned long) statbuf->st_uid); |
| 224 | } else if (m == 'U') { | 234 | } else if (m == 'U') { |
| 225 | strncat(pformat, "s", buf_len); | ||
| 226 | setpwent(); | 235 | setpwent(); |
| 227 | pw_ent = getpwuid(statbuf->st_uid); | 236 | pw_ent = getpwuid(statbuf->st_uid); |
| 228 | printf(pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN"); | 237 | printfs(pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN"); |
| 229 | } else if (m == 'g') { | 238 | } else if (m == 'g') { |
| 230 | strncat(pformat, "lu", buf_len); | 239 | strcat(pformat, "lu"); |
| 231 | printf(pformat, (unsigned long) statbuf->st_gid); | 240 | printf(pformat, (unsigned long) statbuf->st_gid); |
| 232 | } else if (m == 'G') { | 241 | } else if (m == 'G') { |
| 233 | strncat(pformat, "s", buf_len); | ||
| 234 | setgrent(); | 242 | setgrent(); |
| 235 | gw_ent = getgrgid(statbuf->st_gid); | 243 | gw_ent = getgrgid(statbuf->st_gid); |
| 236 | printf(pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN"); | 244 | printfs(pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN"); |
| 237 | } else if (m == 't') { | 245 | } else if (m == 't') { |
| 238 | strncat(pformat, "lx", buf_len); | 246 | strcat(pformat, "lx"); |
| 239 | printf(pformat, (unsigned long) major(statbuf->st_rdev)); | 247 | printf(pformat, (unsigned long) major(statbuf->st_rdev)); |
| 240 | } else if (m == 'T') { | 248 | } else if (m == 'T') { |
| 241 | strncat(pformat, "lx", buf_len); | 249 | strcat(pformat, "lx"); |
| 242 | printf(pformat, (unsigned long) minor(statbuf->st_rdev)); | 250 | printf(pformat, (unsigned long) minor(statbuf->st_rdev)); |
| 243 | } else if (m == 's') { | 251 | } else if (m == 's') { |
| 244 | strncat(pformat, "ju", buf_len); | 252 | strcat(pformat, "ju"); |
| 245 | printf(pformat, (uintmax_t) (statbuf->st_size)); | 253 | printf(pformat, (uintmax_t) (statbuf->st_size)); |
| 246 | } else if (m == 'B') { | 254 | } else if (m == 'B') { |
| 247 | strncat(pformat, "lu", buf_len); | 255 | strcat(pformat, "lu"); |
| 248 | printf(pformat, (unsigned long) 512); //ST_NBLOCKSIZE | 256 | printf(pformat, (unsigned long) 512); //ST_NBLOCKSIZE |
| 249 | } else if (m == 'b') { | 257 | } else if (m == 'b') { |
| 250 | strncat(pformat, "ju", buf_len); | 258 | strcat(pformat, "ju"); |
| 251 | printf(pformat, (uintmax_t) statbuf->st_blocks); | 259 | printf(pformat, (uintmax_t) statbuf->st_blocks); |
| 252 | } else if (m == 'o') { | 260 | } else if (m == 'o') { |
| 253 | strncat(pformat, "lu", buf_len); | 261 | strcat(pformat, "lu"); |
| 254 | printf(pformat, (unsigned long) statbuf->st_blksize); | 262 | printf(pformat, (unsigned long) statbuf->st_blksize); |
| 255 | } else if (m == 'x') { | 263 | } else if (m == 'x') { |
| 256 | strncat(pformat, "s", buf_len); | 264 | printfs(pformat, human_time(statbuf->st_atime)); |
| 257 | printf(pformat, human_time(statbuf->st_atime)); | ||
| 258 | } else if (m == 'X') { | 265 | } else if (m == 'X') { |
| 259 | strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); | 266 | strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); |
| 260 | printf(pformat, (unsigned long) statbuf->st_atime); | 267 | printf(pformat, (unsigned long) statbuf->st_atime); |
| 261 | } else if (m == 'y') { | 268 | } else if (m == 'y') { |
| 262 | strncat(pformat, "s", buf_len); | 269 | printfs(pformat, human_time(statbuf->st_mtime)); |
| 263 | printf(pformat, human_time(statbuf->st_mtime)); | ||
| 264 | } else if (m == 'Y') { | 270 | } else if (m == 'Y') { |
| 265 | strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); | 271 | strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); |
| 266 | printf(pformat, (unsigned long) statbuf->st_mtime); | 272 | printf(pformat, (unsigned long) statbuf->st_mtime); |
| 267 | } else if (m == 'z') { | 273 | } else if (m == 'z') { |
| 268 | strncat(pformat, "s", buf_len); | 274 | printfs(pformat, human_time(statbuf->st_ctime)); |
| 269 | printf(pformat, human_time(statbuf->st_ctime)); | ||
| 270 | } else if (m == 'Z') { | 275 | } else if (m == 'Z') { |
| 271 | strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); | 276 | strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); |
| 272 | printf(pformat, (unsigned long) statbuf->st_ctime); | 277 | printf(pformat, (unsigned long) statbuf->st_ctime); |
| 273 | #if ENABLE_SELINUX | 278 | #if ENABLE_SELINUX |
| 274 | } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) { | 279 | } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) { |
| 275 | strncat(pformat, "s", buf_len); | 280 | printfs(pformat, scontext); |
| 276 | printf(pformat, scontext); | ||
| 277 | #endif | 281 | #endif |
| 278 | } else { | 282 | } else { |
| 279 | strncat(pformat, "c", buf_len); | 283 | strcatc(pformat, 'c'); |
| 280 | printf(pformat, m); | 284 | printf(pformat, m); |
| 281 | } | 285 | } |
| 282 | } | 286 | } |
| 283 | 287 | ||
| 284 | static void print_it(char const *masterformat, char const *filename, | 288 | static void print_it(const char *masterformat, const char *filename, |
| 285 | void (*print_func) (char *, size_t, char, char const *, void const * | 289 | void (*print_func) (char*, char, const char*, const void* USE_SELINUX(, security_context_t scontext)), |
| 286 | USE_SELINUX(, security_context_t scontext)), | 290 | const void *data |
| 287 | void const *data USE_SELINUX(, security_context_t scontext) ) | 291 | USE_SELINUX(, security_context_t scontext) ) |
| 288 | { | 292 | { |
| 289 | char *b; | 293 | /* Create a working copy of the format string */ |
| 290 | |||
| 291 | /* create a working copy of the format string */ | ||
| 292 | char *format = xstrdup(masterformat); | 294 | char *format = xstrdup(masterformat); |
| 293 | |||
| 294 | /* Add 2 to accomodate our conversion of the stat '%s' format string | 295 | /* Add 2 to accomodate our conversion of the stat '%s' format string |
| 295 | * to the printf '%llu' one. */ | 296 | * to the printf '%llu' one. */ |
| 296 | size_t n_alloc = strlen(format) + 2 + 1; | 297 | char *dest = xmalloc(strlen(format) + 2 + 1); |
| 297 | char *dest = xmalloc(n_alloc); | 298 | char *b; |
| 298 | 299 | ||
| 299 | b = format; | 300 | b = format; |
| 300 | while (b) { | 301 | while (b) { |
| 301 | size_t len; | 302 | size_t len; |
| 302 | char *p = strchr(b, '%'); | 303 | char *p = strchr(b, '%'); |
| 303 | if (!p) { | 304 | if (!p) { |
| 304 | /* coreutils 6.3 always print <cr> at the end */ | 305 | /* coreutils 6.3 always prints <cr> at the end */ |
| 305 | /*fputs(b, stdout);*/ | 306 | /*fputs(b, stdout);*/ |
| 306 | puts(b); | 307 | puts(b); |
| 307 | break; | 308 | break; |
| @@ -309,10 +310,11 @@ static void print_it(char const *masterformat, char const *filename, | |||
| 309 | *p++ = '\0'; | 310 | *p++ = '\0'; |
| 310 | fputs(b, stdout); | 311 | fputs(b, stdout); |
| 311 | 312 | ||
| 313 | /* dest = "%<modifiers>" */ | ||
| 312 | len = strspn(p, "#-+.I 0123456789"); | 314 | len = strspn(p, "#-+.I 0123456789"); |
| 313 | dest[0] = '%'; | 315 | dest[0] = '%'; |
| 314 | memcpy(dest + 1, p, len); | 316 | memcpy(dest + 1, p, len); |
| 315 | dest[1 + len] = 0; | 317 | dest[1 + len] = '\0'; |
| 316 | p += len; | 318 | p += len; |
| 317 | 319 | ||
| 318 | b = p + 1; | 320 | b = p + 1; |
| @@ -324,7 +326,8 @@ static void print_it(char const *masterformat, char const *filename, | |||
| 324 | bb_putchar('%'); | 326 | bb_putchar('%'); |
| 325 | break; | 327 | break; |
| 326 | default: | 328 | default: |
| 327 | print_func(dest, n_alloc, *p, filename, data USE_SELINUX(,scontext)); | 329 | /* Completes "%<modifiers>" with specifier and printfs */ |
| 330 | print_func(dest, *p, filename, data USE_SELINUX(,scontext)); | ||
| 328 | break; | 331 | break; |
| 329 | } | 332 | } |
| 330 | } | 333 | } |
| @@ -335,7 +338,7 @@ static void print_it(char const *masterformat, char const *filename, | |||
| 335 | #endif | 338 | #endif |
| 336 | 339 | ||
| 337 | /* Stat the file system and print what we find. */ | 340 | /* Stat the file system and print what we find. */ |
| 338 | static bool do_statfs(char const *filename, char const *format) | 341 | static bool do_statfs(const char *filename, const char *format) |
| 339 | { | 342 | { |
| 340 | struct statfs statfsbuf; | 343 | struct statfs statfsbuf; |
| 341 | #if ENABLE_SELINUX | 344 | #if ENABLE_SELINUX |
| @@ -358,7 +361,7 @@ static bool do_statfs(char const *filename, char const *format) | |||
| 358 | } | 361 | } |
| 359 | 362 | ||
| 360 | #if ENABLE_FEATURE_STAT_FORMAT | 363 | #if ENABLE_FEATURE_STAT_FORMAT |
| 361 | if (format == NULL) | 364 | if (format == NULL) { |
| 362 | #if !ENABLE_SELINUX | 365 | #if !ENABLE_SELINUX |
| 363 | format = (option_mask32 & OPT_TERSE | 366 | format = (option_mask32 & OPT_TERSE |
| 364 | ? "%n %i %l %t %s %b %f %a %c %d\n" | 367 | ? "%n %i %l %t %s %b %f %a %c %d\n" |
| @@ -367,9 +370,8 @@ static bool do_statfs(char const *filename, char const *format) | |||
| 367 | "Block size: %-10s\n" | 370 | "Block size: %-10s\n" |
| 368 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" | 371 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" |
| 369 | "Inodes: Total: %-10c Free: %d"); | 372 | "Inodes: Total: %-10c Free: %d"); |
| 370 | print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); | ||
| 371 | #else | 373 | #else |
| 372 | format = (option_mask32 & OPT_TERSE | 374 | format = (option_mask32 & OPT_TERSE |
| 373 | ? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n": | 375 | ? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n": |
| 374 | "%n %i %l %t %s %b %f %a %c %d\n") | 376 | "%n %i %l %t %s %b %f %a %c %d\n") |
| 375 | : (option_mask32 & OPT_SELINUX ? | 377 | : (option_mask32 & OPT_SELINUX ? |
| @@ -385,8 +387,9 @@ static bool do_statfs(char const *filename, char const *format) | |||
| 385 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" | 387 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" |
| 386 | "Inodes: Total: %-10c Free: %d\n") | 388 | "Inodes: Total: %-10c Free: %d\n") |
| 387 | ); | 389 | ); |
| 388 | print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); | ||
| 389 | #endif /* SELINUX */ | 390 | #endif /* SELINUX */ |
| 391 | } | ||
| 392 | print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); | ||
| 390 | #else /* FEATURE_STAT_FORMAT */ | 393 | #else /* FEATURE_STAT_FORMAT */ |
| 391 | format = (option_mask32 & OPT_TERSE | 394 | format = (option_mask32 & OPT_TERSE |
| 392 | ? "%s %llx %lu " | 395 | ? "%s %llx %lu " |
| @@ -444,7 +447,7 @@ static bool do_statfs(char const *filename, char const *format) | |||
| 444 | } | 447 | } |
| 445 | 448 | ||
| 446 | /* stat the file and print what we find */ | 449 | /* stat the file and print what we find */ |
| 447 | static bool do_stat(char const *filename, char const *format) | 450 | static bool do_stat(const char *filename, const char *format) |
| 448 | { | 451 | { |
| 449 | struct stat statbuf; | 452 | struct stat statbuf; |
| 450 | #if ENABLE_SELINUX | 453 | #if ENABLE_SELINUX |
| @@ -612,7 +615,7 @@ int stat_main(int argc, char **argv) | |||
| 612 | char *format = NULL; | 615 | char *format = NULL; |
| 613 | int i; | 616 | int i; |
| 614 | int ok = 1; | 617 | int ok = 1; |
| 615 | bool (*statfunc)(char const *, char const *) = do_stat; | 618 | bool (*statfunc)(const char *, const char *) = do_stat; |
| 616 | 619 | ||
| 617 | getopt32(argv, "ftL" | 620 | getopt32(argv, "ftL" |
| 618 | USE_SELINUX("Z") | 621 | USE_SELINUX("Z") |
