summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-14 22:08:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-14 22:08:04 +0000
commit16c7fb7fc5ae647bcc273827f507d90866419560 (patch)
tree35766e878699512ceac5c73829308c6caaa9fa1d /coreutils
parente1e93c1e1cf0ddbb1749176d5f1fc430c869c37a (diff)
downloadbusybox-w32-16c7fb7fc5ae647bcc273827f507d90866419560.tar.gz
busybox-w32-16c7fb7fc5ae647bcc273827f507d90866419560.tar.bz2
busybox-w32-16c7fb7fc5ae647bcc273827f507d90866419560.zip
chown, env: stop using statics
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/chown.c16
-rw-r--r--coreutils/env.c12
2 files changed, 14 insertions, 14 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 15d2faeae..f92299e36 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -13,10 +13,6 @@
13 13
14#include "busybox.h" 14#include "busybox.h"
15 15
16static struct bb_uidgid_t ugid = { -1, -1 };
17
18static int (*chown_func)(const char *, uid_t, gid_t) = chown;
19
20#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP")) 16#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
21#define BIT_RECURSE 1 17#define BIT_RECURSE 1
22#define OPT_RECURSE (option_mask32 & 1) 18#define OPT_RECURSE (option_mask32 & 1)
@@ -38,13 +34,17 @@ static int (*chown_func)(const char *, uid_t, gid_t) = chown;
38#define BIT_TRAVERSE_TOP (0x20|0x40) 34#define BIT_TRAVERSE_TOP (0x20|0x40)
39#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0)) 35#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
40 36
37typedef int (*chown_fptr)(const char *, uid_t, gid_t);
38
39static struct bb_uidgid_t ugid = { -1, -1 };
40
41static int fileAction(const char *fileName, struct stat *statbuf, 41static int fileAction(const char *fileName, struct stat *statbuf,
42 void ATTRIBUTE_UNUSED *junk, int depth) 42 void *cf, int depth)
43{ 43{
44 uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid; 44 uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid;
45 gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid; 45 gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid;
46 46
47 if (!chown_func(fileName, u, g)) { 47 if (!((chown_fptr)cf)(fileName, u, g)) {
48 if (OPT_VERBOSE 48 if (OPT_VERBOSE
49 || (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g)) 49 || (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g))
50 ) { 50 ) {
@@ -62,12 +62,14 @@ int chown_main(int argc, char **argv);
62int chown_main(int argc, char **argv) 62int chown_main(int argc, char **argv)
63{ 63{
64 int retval = EXIT_SUCCESS; 64 int retval = EXIT_SUCCESS;
65 chown_fptr chown_func;
65 66
66 opt_complementary = "-2"; 67 opt_complementary = "-2";
67 getopt32(argc, argv, OPT_STR); 68 getopt32(argc, argv, OPT_STR);
68 argv += optind; 69 argv += optind;
69 70
70 /* This matches coreutils behavior (almost - see below) */ 71 /* This matches coreutils behavior (almost - see below) */
72 chown_func = chown;
71 if (OPT_NODEREF 73 if (OPT_NODEREF
72 /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */ 74 /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
73 USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE) 75 USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
@@ -95,7 +97,7 @@ int chown_main(int argc, char **argv)
95 FALSE, // depth first 97 FALSE, // depth first
96 fileAction, // file action 98 fileAction, // file action
97 fileAction, // dir action 99 fileAction, // dir action
98 NULL, // user data 100 chown_func, // user data
99 0) // depth 101 0) // depth
100 ) { 102 ) {
101 retval = EXIT_FAILURE; 103 retval = EXIT_FAILURE;
diff --git a/coreutils/env.c b/coreutils/env.c
index 7be0c63a5..f47d450c5 100644
--- a/coreutils/env.c
+++ b/coreutils/env.c
@@ -44,8 +44,8 @@ static const struct option env_long_options[] = {
44int env_main(int argc, char** argv); 44int env_main(int argc, char** argv);
45int env_main(int argc, char** argv) 45int env_main(int argc, char** argv)
46{ 46{
47 static char *cleanenv[1] = { NULL }; 47 /* cleanenv was static - why? */
48 48 char *cleanenv[1];
49 char **ep; 49 char **ep;
50 unsigned opt; 50 unsigned opt;
51 llist_t *unset_env = NULL; 51 llist_t *unset_env = NULL;
@@ -55,18 +55,16 @@ int env_main(int argc, char** argv)
55#if ENABLE_FEATURE_ENV_LONG_OPTIONS 55#if ENABLE_FEATURE_ENV_LONG_OPTIONS
56 applet_long_options = env_long_options; 56 applet_long_options = env_long_options;
57#endif 57#endif
58
59 opt = getopt32(argc, argv, "+iu:", &unset_env); 58 opt = getopt32(argc, argv, "+iu:", &unset_env);
60
61 argv += optind; 59 argv += optind;
62 if (*argv && LONE_DASH(argv[0])) { 60 if (*argv && LONE_DASH(argv[0])) {
63 opt |= 1; 61 opt |= 1;
64 ++argv; 62 ++argv;
65 } 63 }
66 64 if (opt & 1) {
67 if (opt & 1) 65 cleanenv[0] = NULL;
68 environ = cleanenv; 66 environ = cleanenv;
69 else if (opt & 2) { 67 } else if (opt & 2) {
70 while (unset_env) { 68 while (unset_env) {
71 unsetenv(unset_env->data); 69 unsetenv(unset_env->data);
72 unset_env = unset_env->link; 70 unset_env = unset_env->link;