diff options
author | Rob Landley <rob@landley.net> | 2021-02-22 19:48:49 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2021-02-22 19:48:49 -0600 |
commit | 1f9e37e36117c51a17f017143f1b68787d913979 (patch) | |
tree | 5841c85b9019c99ea2464afea19866cae79262d8 | |
parent | e2ad5c6c155ef63833f6d3774b607c314fbe8987 (diff) | |
download | toybox-1f9e37e36117c51a17f017143f1b68787d913979.tar.gz |
Remove ifdefs from stat.
-rw-r--r-- | lib/portability.h | 5 | ||||
-rw-r--r-- | toys/other/stat.c | 21 |
2 files changed, 9 insertions, 17 deletions
diff --git a/lib/portability.h b/lib/portability.h index b3646473..54f97afd 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -215,6 +215,11 @@ int posix_fallocate(int, off_t, off_t); // macOS keeps newlocale(3) in the non-POSIX <xlocale.h> rather than <locale.h>. #include <xlocale.h> +static inline long statfs_bsize(struct statfs *sf) { return sf->f_iosize; } +static inline long statfs_frsize(struct statfs *sf) { return sf->f_bsize; } +#else +static inline long statfs_bsize(struct statfs *sf) { return sf->f_bsize; } +static inline long statfs_frsize(struct statfs *sf) { return sf->f_frsize; } #endif diff --git a/toys/other/stat.c b/toys/other/stat.c index 6d5fc018..98f27ed6 100644 --- a/toys/other/stat.c +++ b/toys/other/stat.c @@ -141,15 +141,8 @@ static void print_statfs(char type) { else if (type == 'c') out('u', statfs->f_files); else if (type == 'd') out('u', statfs->f_ffree); else if (type == 'f') out('u', statfs->f_bfree); - else if (type == 'l') { -#ifdef __APPLE__ - // TODO: move this into portability.c somehow, or just use this everywhere? - // (glibc and bionic will just re-do the statfs and return f_namelen.) - out('d', pathconf(TT.file, _PC_NAME_MAX)); -#else - out('d', statfs->f_namelen); -#endif - } else if (type == 't') out('x', statfs->f_type); + else if (type == 'l') out('d', pathconf(TT.file, _PC_NAME_MAX)); + else if (type == 't') out('x', statfs->f_type); else if (type == 'T') strout(fs_type_name(statfs)); else if (type == 'i') { int *val = (int *) &statfs->f_fsid; @@ -157,14 +150,8 @@ static void print_statfs(char type) { sprintf(buf, "%08x%08x", val[0], val[1]); strout(buf); - } -#ifdef __APPLE__ - else if (type == 's') out('d', statfs->f_iosize); - else if (type == 'S') out('d', statfs->f_bsize); -#else - else if (type == 's') out('d', statfs->f_bsize); - else if (type == 'S') out('d', statfs->f_frsize); -#endif + } else if (type == 's') out('d', statfs_bsize(statfs)); + else if (type == 'S') out('d', statfs_frsize(statfs)); else strout("?"); } |