aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-06-18 20:20:07 +0000
committerRob Landley <rob@landley.net>2006-06-18 20:20:07 +0000
commitea224be6aa8fed5486376d3021a4cb911e935106 (patch)
tree38d6c5d2d53841e3f4e2702521e3b03235c51017 /coreutils
parent14d7065ef1eb836d20e13bc25d1b13f0e76185ac (diff)
downloadbusybox-ea224be6aa8fed5486376d3021a4cb911e935106.tar.gz
skip_whitespace() shouldn't claim its return value is const, it doesn't know
that and callers wind up typecasting it back.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/ls.c112
-rw-r--r--coreutils/test.c7
-rw-r--r--coreutils/uniq.c6
3 files changed, 31 insertions, 94 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 47acec603..4a20b3396 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -36,32 +36,18 @@ enum {
/************************************************************************/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
+#include "busybox.h"
#include <unistd.h>
-#include <dirent.h>
#include <errno.h>
-#include <stdio.h>
#include <string.h>
-#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
-#include <termios.h>
#include <getopt.h> /* struct option */
#include <sys/ioctl.h>
#include <sys/sysmacros.h> /* major() and minor() */
-#include "busybox.h"
-#ifdef CONFIG_SELINUX
-#include <selinux/selinux.h> /* for is_selinux_enabled() */
-#endif
-
-#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
#include <time.h>
-#endif
/* what is the overall style of the listing */
-#define STYLE_AUTO (0)
#define STYLE_COLUMNS (1U<<21) /* fill columns */
#define STYLE_LONG (2U<<21) /* one record per line, extended info */
#define STYLE_SINGLE (3U<<21) /* one record per line */
@@ -99,7 +85,7 @@ enum {
#define DISP_MASK (((DISP_ROWS << 1) - 1) & ~(DISP_DIRNAME - 1))
-#ifdef CONFIG_FEATURE_LS_SORTFILES
+// CONFIG_FEATURE_LS_SORTFILES
/* how will the files be sorted */
#define SORT_ORDER_FORWARD 0 /* sort in reverse order */
#define SORT_ORDER_REVERSE (1U<<27) /* sort in reverse order */
@@ -114,7 +100,6 @@ enum {
#define SORT_DIR (7U<<28) /* sort by file or directory */
#define SORT_MASK (7U<<28)
-#endif
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
/* which of the three times will be used */
@@ -416,11 +401,8 @@ static int sortcmp(const void *a, const void *b)
if (dif == 0) {
/* sort by name- may be a tie_breaker for time or size cmp */
-#ifdef CONFIG_LOCALE_SUPPORT
- dif = strcoll(d1->name, d2->name);
-#else
- dif = strcmp(d1->name, d2->name);
-#endif
+ if (ENABLE_LOCALE_SUPPORT) dif = strcoll(d1->name, d2->name);
+ else dif = strcmp(d1->name, d2->name);
}
if (all_fmt & SORT_ORDER_REVERSE) {
@@ -434,8 +416,12 @@ static void dnsort(struct dnode **dn, int size)
{
qsort(dn, size, sizeof *dn, sortcmp);
}
+#else
+#define sortcmp(a, b) 0
+#define dnsort(dn, size)
#endif
+
/*----------------------------------------------------------------------*/
static void showfiles(struct dnode **dn, int nfiles)
{
@@ -502,11 +488,8 @@ static void showdirs(struct dnode **dn, int ndirs, int first)
{
int i, nfiles;
struct dnode **subdnp;
-
-#ifdef CONFIG_FEATURE_LS_RECURSIVE
int dndirs;
struct dnode **dnd;
-#endif
if (dn == NULL || ndirs < 1)
return;
@@ -522,9 +505,7 @@ static void showdirs(struct dnode **dn, int ndirs, int first)
nfiles = countfiles(subdnp);
if (nfiles > 0) {
/* list all files at this level */
-#ifdef CONFIG_FEATURE_LS_SORTFILES
- dnsort(subdnp, nfiles);
-#endif
+ if (ENABLE_FEATURE_LS_SORTFILES) dnsort(subdnp, nfiles);
showfiles(subdnp, nfiles);
#ifdef CONFIG_FEATURE_LS_RECURSIVE
if (all_fmt & DISP_RECURSIVE) {
@@ -532,9 +513,7 @@ static void showdirs(struct dnode **dn, int ndirs, int first)
dnd = splitdnarray(subdnp, nfiles, SPLIT_SUBDIR);
dndirs = countsubdirs(subdnp, nfiles);
if (dndirs > 0) {
-#ifdef CONFIG_FEATURE_LS_SORTFILES
- dnsort(dnd, dndirs);
-#endif
+ if (ENABLE_FEATURE_LS_SORTFILES) dnsort(dnd, dndirs);
showdirs(dnd, dndirs, 0);
free(dnd); /* free the array of dnode pointers to the dirs */
}
@@ -796,12 +775,6 @@ static int list_single(struct dnode *dn)
# define LS_STR_TIMESTAMPS ""
#endif
-#ifdef CONFIG_FEATURE_LS_SORTFILES
-# define LS_STR_SORTFILES "SXrv"
-#else
-# define LS_STR_SORTFILES ""
-#endif
-
#ifdef CONFIG_FEATURE_LS_FILETYPES
# define LS_STR_FILETYPES "Fp"
#else
@@ -840,7 +813,7 @@ static int list_single(struct dnode *dn)
static const char ls_options[]="Cadil1gnsxAk" \
LS_STR_TIMESTAMPS \
- LS_STR_SORTFILES \
+ USE_FEATURE_LS_SORTFILES("SXrv") \
LS_STR_FILETYPES \
LS_STR_FOLLOW_LINKS \
LS_STR_RECURSIVE \
@@ -872,22 +845,10 @@ static const unsigned opt_flags[] = {
0, /* k - ingored */
#endif
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
-# ifdef CONFIG_FEATURE_LS_SORTFILES
- TIME_CHANGE | SORT_CTIME, /* c */
-# else
- TIME_CHANGE, /* c */
-# endif
+ TIME_CHANGE | (ENABLE_FEATURE_LS_SORTFILES * SORT_CTIME), /* c */
LIST_FULLTIME, /* e */
-# ifdef CONFIG_FEATURE_LS_SORTFILES
- SORT_MTIME, /* t */
-# else
- 0, /* t - ignored -- is this correct? */
-# endif
-# ifdef CONFIG_FEATURE_LS_SORTFILES
- TIME_ACCESS | SORT_ATIME, /* u */
-# else
- TIME_ACCESS, /* u */
-# endif
+ ENABLE_FEATURE_LS_SORTFILES * SORT_MTIME, /* t */
+ TIME_ACCESS | (ENABLE_FEATURE_LS_SORTFILES * SORT_ATIME), /* u */
#endif
#ifdef CONFIG_FEATURE_LS_SORTFILES
SORT_SIZE, /* S */
@@ -943,14 +904,8 @@ int ls_main(int argc, char **argv)
char *color_opt;
#endif
- all_fmt = LIST_SHORT | STYLE_AUTO
-#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
- | TIME_MOD
-#endif
-#ifdef CONFIG_FEATURE_LS_SORTFILES
- | SORT_NAME | SORT_ORDER_FORWARD
-#endif
- ;
+ all_fmt = LIST_SHORT | (ENABLE_FEATURE_LS_TIMESTAMPS * TIME_MOD) |
+ (ENABLE_FEATURE_LS_SORTFILES * (SORT_NAME | SORT_ORDER_FORWARD));
#ifdef CONFIG_FEATURE_AUTOWIDTH
/* Obtain the terminal width. */
@@ -993,11 +948,9 @@ int ls_main(int argc, char **argv)
if (flags & STYLE_MASK_TRIGGER) {
all_fmt &= ~STYLE_MASK;
}
-#ifdef CONFIG_FEATURE_LS_SORTFILES
- if (flags & SORT_MASK_TRIGGER) {
+ if (ENABLE_FEATURE_LS_SORTFILES && (flags & SORT_MASK_TRIGGER)) {
all_fmt &= ~SORT_MASK;
}
-#endif
if (flags & DISP_MASK_TRIGGER) {
all_fmt &= ~DISP_MASK;
}
@@ -1049,12 +1002,12 @@ int ls_main(int argc, char **argv)
if (all_fmt & DISP_NOLIST)
all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */
#endif
-#if defined (CONFIG_FEATURE_LS_TIMESTAMPS) && defined (CONFIG_FEATURE_LS_SORTFILES)
- if (all_fmt & TIME_CHANGE)
- all_fmt = (all_fmt & ~SORT_MASK) | SORT_CTIME;
- if (all_fmt & TIME_ACCESS)
- all_fmt = (all_fmt & ~SORT_MASK) | SORT_ATIME;
-#endif
+ if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) {
+ if (all_fmt & TIME_CHANGE)
+ all_fmt = (all_fmt & ~SORT_MASK) | SORT_CTIME;
+ if (all_fmt & TIME_ACCESS)
+ all_fmt = (all_fmt & ~SORT_MASK) | SORT_ATIME;
+ }
if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* only for long list */
all_fmt &= ~(LIST_ID_NUMERIC|LIST_FULLTIME|LIST_ID_NAME|LIST_ID_NUMERIC);
#ifdef CONFIG_FEATURE_LS_USERNAME
@@ -1063,13 +1016,8 @@ int ls_main(int argc, char **argv)
#endif
/* choose a display format */
- if ((all_fmt & STYLE_MASK) == STYLE_AUTO)
-#if STYLE_AUTO != 0
- all_fmt = (all_fmt & ~STYLE_MASK)
- | (isatty(STDOUT_FILENO) ? STYLE_COLUMNS : STYLE_SINGLE);
-#else
+ if (!(all_fmt & STYLE_MASK))
all_fmt |= (isatty(STDOUT_FILENO) ? STYLE_COLUMNS : STYLE_SINGLE);
-#endif
/*
* when there are no cmd line args we have to supply a default "." arg.
@@ -1114,9 +1062,7 @@ int ls_main(int argc, char **argv)
}
if (all_fmt & DISP_NOLIST) {
-#ifdef CONFIG_FEATURE_LS_SORTFILES
- dnsort(dnp, nfiles);
-#endif
+ if (ENABLE_FEATURE_LS_SORTFILES) dnsort(dnp, nfiles);
if (nfiles > 0)
showfiles(dnp, nfiles);
} else {
@@ -1125,17 +1071,13 @@ int ls_main(int argc, char **argv)
dndirs = countdirs(dnp, nfiles);
dnfiles = nfiles - dndirs;
if (dnfiles > 0) {
-#ifdef CONFIG_FEATURE_LS_SORTFILES
- dnsort(dnf, dnfiles);
-#endif
+ if (ENABLE_FEATURE_LS_SORTFILES) dnsort(dnf, dnfiles);
showfiles(dnf, dnfiles);
if (ENABLE_FEATURE_CLEAN_UP)
free(dnf);
}
if (dndirs > 0) {
-#ifdef CONFIG_FEATURE_LS_SORTFILES
- dnsort(dnd, dndirs);
-#endif
+ if (ENABLE_FEATURE_LS_SORTFILES) dnsort(dnd, dndirs);
showdirs(dnd, dndirs, dnfiles == 0);
if (ENABLE_FEATURE_CLEAN_UP)
free(dnd);
diff --git a/coreutils/test.c b/coreutils/test.c
index 4d920380d..ab3793627 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -19,14 +19,12 @@
* "This program is in the Public Domain."
*/
-#include <sys/types.h>
+#include "busybox.h"
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
-#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
-#include "busybox.h"
/* test(1) accepts the following grammar:
oexpr ::= aexpr | aexpr "-o" oexpr ;
@@ -482,8 +480,7 @@ static arith_t getn(const char *s)
if (errno != 0)
syntax(s, "out of range");
- /* p = bb_skip_whitespace(p); avoid const warning */
- if (*(bb_skip_whitespace(p)))
+ if (*(skip_whitespace(p)))
syntax(s, "bad number");
return r;
diff --git a/coreutils/uniq.c b/coreutils/uniq.c
index be3d75c3a..956c50796 100644
--- a/coreutils/uniq.c
+++ b/coreutils/uniq.c
@@ -10,12 +10,10 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */
-#include <stdio.h>
-#include <stdlib.h>
+#include "busybox.h"
#include <string.h>
#include <ctype.h>
#include <unistd.h>
-#include "busybox.h"
static const char uniq_opts[] = "f:s:" "cdu\0\1\2\4";
@@ -77,7 +75,7 @@ int uniq_main(int argc, char **argv)
while ((s1 = bb_get_chomped_line_from_file(in)) != NULL) {
e1 = s1;
for (i=skip_fields ; i ; i--) {
- e1 = bb_skip_whitespace(e1);
+ e1 = skip_whitespace(e1);
while (*e1 && !isspace(*e1)) {
++e1;
}