X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=coreutils%2Fdu.c;h=a547b1e14c7bff35c1397d02970758ec25e50df7;hb=35a4bbe74f87900dc6014a1871e207709fe40de8;hp=d453ba412065a2b90882585cca15dbcbd99e925c;hpb=57545c810a1d0e0783b71d1ba74af45063e2fa42;p=oweals%2Fbusybox.git diff --git a/coreutils/du.c b/coreutils/du.c index d453ba412..a547b1e14 100644 --- a/coreutils/du.c +++ b/coreutils/du.c @@ -6,20 +6,7 @@ * Copyright (C) 1999,2000,2001 by John Beppu * Copyright (C) 2002 Edward Betts * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ /* BB_AUDIT SUSv3 compliant (unless default blocksize set to 1k) */ @@ -36,20 +23,15 @@ * 4) Fixed busybox bug #1284 involving long overflow with human_readable. */ -#include -#include -#include -#include -#include #include "busybox.h" #ifdef CONFIG_FEATURE_HUMAN_READABLE -# ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K -static unsigned long disp_hr = KILOBYTE; +# ifdef CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K +static unsigned long disp_hr = 1024; # else static unsigned long disp_hr = 512; # endif -#elif defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K +#elif defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K static unsigned int disp_k = 1; #else static unsigned int disp_k; /* bss inits to 0 */ @@ -70,23 +52,23 @@ static int one_file_system; static dev_t dir_dev; -static void print(long size, char *filename) +static void print(long size, const char * const filename) { /* TODO - May not want to defer error checking here. */ #ifdef CONFIG_FEATURE_HUMAN_READABLE - bb_printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr), + printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr), filename); #else if (disp_k) { size++; size >>= 1; } - bb_printf("%ld\t%s\n", size, filename); + printf("%ld\t%s\n", size, filename); #endif } /* tiny recursive du */ -static long du(char *filename) +static long du(const char * const filename) { struct stat statbuf; long sum; @@ -134,9 +116,8 @@ static long du(char *filename) struct dirent *entry; char *newfile; - dir = opendir(filename); + dir = warn_opendir(filename); if (!dir) { - bb_perror_msg("%s", filename); status = EXIT_FAILURE; return sum; } @@ -172,9 +153,9 @@ int du_main(int argc, char **argv) int slink_depth_save; int print_final_total; char *smax_print_depth; - unsigned long opt; + unsigned opt; -#ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K +#ifdef CONFIG_FEATURE_DU_DEFUALT_BLOCKSIZE_1K if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */ #ifdef CONFIG_FEATURE_HUMAN_READABLE disp_hr = 512; @@ -184,31 +165,31 @@ int du_main(int argc, char **argv) } #endif - /* Note: SUSv3 specifies that -a and -s options can not be used together + /* Note: SUSv3 specifies that -a and -s options cannot be used together * in strictly conforming applications. However, it also says that some * du implementations may produce output when -a and -s are used together. * gnu du exits with an error code in this case. We choose to simply * ignore -a. This is consistent with -s being equivalent to -d 0. */ #ifdef CONFIG_FEATURE_HUMAN_READABLE - bb_opt_complementally = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; - opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); + opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; + opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); if((opt & (1 << 9))) { /* -h opt */ disp_hr = 0; } if((opt & (1 << 10))) { /* -m opt */ - disp_hr = MEGABYTE; + disp_hr = 1024*1024; } if((opt & (1 << 2))) { /* -k opt */ - disp_hr = KILOBYTE; + disp_hr = 1024; } #else - bb_opt_complementally = "H-L:L-H:s-d:d-s"; - opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); -#if !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K + opt_complementary = "H-L:L-H:s-d:d-s"; + opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); +#if !defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K if((opt & (1 << 2))) { /* -k opt */ disp_k = 1; @@ -234,7 +215,7 @@ int du_main(int argc, char **argv) one_file_system = opt & (1 << 5); /* -x opt */ if((opt & (1 << 6))) { /* -d opt */ - max_print_depth = bb_xgetularg10_bnd(smax_print_depth, 0, INT_MAX); + max_print_depth = xatoi_u(smax_print_depth); } if((opt & (1 << 7))) { /* -l opt */ @@ -265,5 +246,5 @@ int du_main(int argc, char **argv) print(total, "total"); } - bb_fflush_stdout_and_exit(status); + fflush_stdout_and_exit(status); }