chown, env: stop using statics

This commit is contained in:
Denis Vlasenko 2007-03-14 22:08:04 +00:00
parent e1e93c1e1c
commit 16c7fb7fc5
2 changed files with 14 additions and 14 deletions

View File

@ -13,10 +13,6 @@
#include "busybox.h" #include "busybox.h"
static struct bb_uidgid_t ugid = { -1, -1 };
static int (*chown_func)(const char *, uid_t, gid_t) = chown;
#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP")) #define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
#define BIT_RECURSE 1 #define BIT_RECURSE 1
#define OPT_RECURSE (option_mask32 & 1) #define OPT_RECURSE (option_mask32 & 1)
@ -38,13 +34,17 @@ static int (*chown_func)(const char *, uid_t, gid_t) = chown;
#define BIT_TRAVERSE_TOP (0x20|0x40) #define BIT_TRAVERSE_TOP (0x20|0x40)
#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0)) #define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
typedef int (*chown_fptr)(const char *, uid_t, gid_t);
static struct bb_uidgid_t ugid = { -1, -1 };
static int fileAction(const char *fileName, struct stat *statbuf, static int fileAction(const char *fileName, struct stat *statbuf,
void ATTRIBUTE_UNUSED *junk, int depth) void *cf, int depth)
{ {
uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid; uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid;
gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid; gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid;
if (!chown_func(fileName, u, g)) { if (!((chown_fptr)cf)(fileName, u, g)) {
if (OPT_VERBOSE if (OPT_VERBOSE
|| (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g)) || (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g))
) { ) {
@ -62,12 +62,14 @@ int chown_main(int argc, char **argv);
int chown_main(int argc, char **argv) int chown_main(int argc, char **argv)
{ {
int retval = EXIT_SUCCESS; int retval = EXIT_SUCCESS;
chown_fptr chown_func;
opt_complementary = "-2"; opt_complementary = "-2";
getopt32(argc, argv, OPT_STR); getopt32(argc, argv, OPT_STR);
argv += optind; argv += optind;
/* This matches coreutils behavior (almost - see below) */ /* This matches coreutils behavior (almost - see below) */
chown_func = chown;
if (OPT_NODEREF if (OPT_NODEREF
/* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */ /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE) USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
@ -95,7 +97,7 @@ int chown_main(int argc, char **argv)
FALSE, // depth first FALSE, // depth first
fileAction, // file action fileAction, // file action
fileAction, // dir action fileAction, // dir action
NULL, // user data chown_func, // user data
0) // depth 0) // depth
) { ) {
retval = EXIT_FAILURE; retval = EXIT_FAILURE;

View File

@ -44,8 +44,8 @@ static const struct option env_long_options[] = {
int env_main(int argc, char** argv); int env_main(int argc, char** argv);
int env_main(int argc, char** argv) int env_main(int argc, char** argv)
{ {
static char *cleanenv[1] = { NULL }; /* cleanenv was static - why? */
char *cleanenv[1];
char **ep; char **ep;
unsigned opt; unsigned opt;
llist_t *unset_env = NULL; llist_t *unset_env = NULL;
@ -55,18 +55,16 @@ int env_main(int argc, char** argv)
#if ENABLE_FEATURE_ENV_LONG_OPTIONS #if ENABLE_FEATURE_ENV_LONG_OPTIONS
applet_long_options = env_long_options; applet_long_options = env_long_options;
#endif #endif
opt = getopt32(argc, argv, "+iu:", &unset_env); opt = getopt32(argc, argv, "+iu:", &unset_env);
argv += optind; argv += optind;
if (*argv && LONE_DASH(argv[0])) { if (*argv && LONE_DASH(argv[0])) {
opt |= 1; opt |= 1;
++argv; ++argv;
} }
if (opt & 1) {
if (opt & 1) cleanenv[0] = NULL;
environ = cleanenv; environ = cleanenv;
else if (opt & 2) { } else if (opt & 2) {
while (unset_env) { while (unset_env) {
unsetenv(unset_env->data); unsetenv(unset_env->data);
unset_env = unset_env->link; unset_env = unset_env->link;