preparatory patch for -Wwrite-strings #3
authorDenis Vlasenko <vda.linux@googlemail.com>
Mon, 29 Jan 2007 22:51:44 +0000 (22:51 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Mon, 29 Jan 2007 22:51:44 +0000 (22:51 -0000)
init/init.c
loginutils/adduser.c
loginutils/getty.c
loginutils/passwd.c
loginutils/su.c
miscutils/crontab.c
util-linux/fdisk.c
util-linux/fdisk_osf.c
util-linux/ipcrm.c
util-linux/mount.c

index 7694b4448d1eac502010d34f4d4b3c9986a4f9f4..cb314003ee02b6dc6e998cb3814e1c79e24458ee 100644 (file)
@@ -326,27 +326,26 @@ static void console_init(void)
                        /* Force the TERM setting to vt102 for serial console --
                         * if TERM is set to linux (the default) */
                        if (s == NULL || strcmp(s, "linux") == 0)
-                               putenv("TERM=vt102");
+                               putenv((char*)"TERM=vt102");
 #if !ENABLE_SYSLOGD
                        log_console = console;
 #endif
                } else {
                        if (s == NULL)
-                               putenv("TERM=linux");
+                               putenv((char*)"TERM=linux");
                }
                close(fd);
        }
        messageD(LOG, "console=%s", console);
 }
 
-static void fixup_argv(int argc, char **argv, char *new_argv0)
+static void fixup_argv(int argc, char **argv, const char *new_argv0)
 {
        int len;
 
        /* Fix up argv[0] to be certain we claim to be init */
        len = strlen(argv[0]);
-       memset(argv[0], 0, len);
-       safe_strncpy(argv[0], new_argv0, len + 1);
+       strncpy(argv[0], new_argv0, len);
 
        /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
        len = 1;
@@ -381,7 +380,8 @@ static pid_t run(const struct init_action *a)
 {
        int i;
        pid_t pid;
-       char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath;
+       char *s, *tmpCmd, *cmdpath;
+       char *cmd[INIT_BUFFS_SIZE];
        char buf[INIT_BUFFS_SIZE + 6];  /* INIT_BUFFS_SIZE+strlen("exec ")+1 */
        sigset_t nmask, omask;
        static const char press_enter[] =
@@ -389,7 +389,7 @@ static pid_t run(const struct init_action *a)
 #include CUSTOMIZED_BANNER
 #endif
                "\nPlease press Enter to activate this console. ";
-       char *prog;
+       const char *prog;
 
        /* Block sigchild while forking.  */
        sigemptyset(&nmask);
@@ -472,7 +472,7 @@ static pid_t run(const struct init_action *a)
                /* See if any special /bin/sh requiring characters are present */
                if (strpbrk(a->command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
                        cmd[0] = (char *)DEFAULT_SHELL;
-                       cmd[1] = "-c";
+                       cmd[1] = (char*)"-c";
                        cmd[2] = strcat(strcpy(buf, "exec "), a->command);
                        cmd[3] = NULL;
                } else {
index ea0b89a9b98033110cad70fe8f36e9473422c55f..5a48e9cbb0021f35801dfe921d60e4509adafe02 100644 (file)
@@ -169,7 +169,7 @@ int adduser_main(int argc, char **argv)
                bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
        }
 
-       pw.pw_gecos = "Linux User,,,";
+       pw.pw_gecos = (char *)"Linux User,,,";
        pw.pw_shell = (char *)DEFAULT_SHELL;
        pw.pw_dir = NULL;
 
@@ -185,7 +185,7 @@ int adduser_main(int argc, char **argv)
 
        /* create a passwd struct */
        pw.pw_name = argv[optind];
-       pw.pw_passwd = "x";
+       pw.pw_passwd = (char *)"x";
        pw.pw_uid = 0;
        pw.pw_gid = usegroup ? xgroup2gid(usegroup) : 0; /* exits on failure */
 
index f2c2b4afb9721fd66ff1a464a707bcb1ea9b71b5..8f81cafccca55b4f05fa6536c220543b6449a315 100644 (file)
@@ -33,7 +33,7 @@
 #include <time.h>
 #if ENABLE_FEATURE_WTMP
 extern void updwtmp(const char *filename, const struct utmp *ut);
-static void update_utmp(char *line);
+static void update_utmp(const char *line);
 #endif
 #endif  /* LOGIN_PROCESS */
 
@@ -85,10 +85,10 @@ static void update_utmp(char *line);
 struct options {
        int flags;                      /* toggle switches, see below */
        unsigned timeout;               /* time-out period */
-       char *login;                    /* login program */
-       char *tty;                      /* name of tty */
-       char *initstring;               /* modem init string */
-       char *issue;                    /* alternative issue file */
+       const char *login;                    /* login program */
+       const char *tty;                      /* name of tty */
+       const char *initstring;               /* modem init string */
+       const char *issue;                    /* alternative issue file */
        int numspeed;                   /* number of baud rates to try */
        int speeds[MAX_SPEED];          /* baud rates to be tried */
 };
@@ -187,7 +187,7 @@ static void parse_args(int argc, char **argv, struct options *op)
                const char *p = op->initstring;
                char *q;
 
-               q = op->initstring = xstrdup(op->initstring);
+               op->initstring = q = xstrdup(op->initstring);
                /* copy optarg into op->initstring decoding \ddd
                   octal codes into chars */
                while (*p) {
@@ -233,7 +233,7 @@ static void xdup2(int srcfd, int dstfd, const char *tty)
 }
 
 /* open_tty - set up tty as standard { input, output, error } */
-static void open_tty(char *tty, struct termios *tp, int local)
+static void open_tty(const char *tty, struct termios *tp, int local)
 {
        int chdir_to_root = 0;
 
@@ -655,7 +655,7 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat
 #ifdef SYSV_STYLE
 #if ENABLE_FEATURE_UTMP
 /* update_utmp - update our utmp entry */
-static void update_utmp(char *line)
+static void update_utmp(const char *line)
 {
        struct utmp ut;
        struct utmp *utp;
index 5c822b190c37683302c8d87c509a945e01d730aa..ab20f2807948126b3bb55e231e0b5e485fe802a1 100644 (file)
@@ -53,7 +53,7 @@ static void crypt_make_salt(char *p, int cnt)
 static char* new_password(const struct passwd *pw, uid_t myuid, int algo)
 {
        char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */
-       char *orig = "";
+       char *orig = (char*)"";
        char *newp = NULL;
        char *cipher = NULL;
        char *cp = NULL;
@@ -241,7 +241,7 @@ int passwd_main(int argc, char **argv)
                /*STATE_ALGO_des = 0x20, not needed yet */
        };
        unsigned opt;
-       char *opt_a = "";
+       const char *opt_a = "";
        const char *filename;
        char *myname;
        char *name;
index e1c1591aa6dab292b9005f476a7eb612877ddd4d..9a134dd88a32a47fb3a4ff6a0b70541d99c23829 100644 (file)
@@ -14,9 +14,9 @@
 int su_main(int argc, char **argv)
 {
        unsigned flags;
-       char *opt_shell = 0;
-       char *opt_command = 0;
-       char *opt_username = "root";
+       char *opt_shell = NULL;
+       char *opt_command = NULL;
+       const char *opt_username = "root";
        struct passwd *pw;
        uid_t cur_uid = getuid();
        const char *tty;
index d442272f0cb4258ed51a7c59617a49c2aea21c8e..eb7c2059c099f78ccab26fc1d60f6b68f6ba4efc 100644 (file)
@@ -290,8 +290,7 @@ static void EditFile(const char *user, const char *file)
                /*
                 * CHILD - change user and run editor
                 */
-               char *ptr;
-               char visual[1024];
+               const char *ptr;
 
                if (ChangeUser(user, 1) < 0)
                        exit(0);
@@ -299,10 +298,9 @@ static void EditFile(const char *user, const char *file)
                if (ptr == NULL || strlen(ptr) > 256)
                        ptr = PATH_VI;
 
-               snprintf(visual, sizeof(visual), "%s %s", ptr, file);
-               execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", visual, NULL);
-               perror("exec");
-               exit(0);
+               ptr = xasprintf("%s %s", ptr, file);
+               execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", ptr, NULL);
+               bb_perror_msg_and_die("exec");
        }
        if (pid < 0) {
                /*
index f15b9af919daf92120b4838405cb3672fd26ab4e..6d827105e0f0cfaa0628b443ec98b80672782883 100644 (file)
@@ -185,7 +185,7 @@ static void reread_partition_table(int leave);
 static void delete_partition(int i);
 static int get_partition(int warn, int max);
 static void list_types(const struct systypes *sys);
-static unsigned read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, char *mesg);
+static unsigned read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char *mesg);
 #endif
 static const char *partition_type(unsigned char type);
 static void fdisk_fatal(enum failure why) ATTRIBUTE_NORETURN;
@@ -1410,7 +1410,7 @@ get_boot(enum action what)
  * There is no default if DFLT is not between LOW and HIGH.
  */
 static unsigned
-read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, char *mesg)
+read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char *mesg)
 {
        unsigned i;
        int default_ok = 1;
index 3f56bd27d62ec9f7a89e5146d22e6b22d13b9b97..2555c2e7b427799c4d9f368f1b05b1e3829fbfc0 100644 (file)
@@ -630,7 +630,7 @@ xbsd_create_disklabel(void)
 }
 
 static int
-edit_int(int def, char *mesg)
+edit_int(int def, const char *mesg)
 {
        mesg = xasprintf("%s (%d): ", mesg, def);
        do {
@@ -639,7 +639,7 @@ edit_int(int def, char *mesg)
        } while (!isdigit(*line_ptr));
        def = atoi(line_ptr);
  ret:
-       free(mesg);
+       free((char*)mesg);
        return def;
 }
 
@@ -707,9 +707,9 @@ sync_disks(void)
 static void
 xbsd_write_bootstrap(void)
 {
-       char *bootdir = BSD_LINUX_BOOTDIR;
        char path[MAXPATHLEN];
-       char *dkbasename;
+       const char *bootdir = BSD_LINUX_BOOTDIR;
+       const char *dkbasename;
        struct xbsd_disklabel dl;
        char *d, *p, *e;
        int sector;
index 507e58fe35642bf91192af4d0e5bf84eea2dd7ea..886c2efbd9d5987356495dd64ef720afc1c5c440 100644 (file)
@@ -152,8 +152,8 @@ int ipcrm_main(int argc, char **argv)
                                  (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0));
 
                        if (id < 0) {
-                               char *errmsg;
-                               const char * const what = "key";
+                               const char *errmsg;
+                               const char *const what = "key";
 
                                error++;
                                switch (errno) {
@@ -183,8 +183,8 @@ int ipcrm_main(int argc, char **argv)
                                  semctl(id, 0, IPC_RMID, arg));
 
                if (result) {
-                       char *errmsg;
-                       const char * const what = iskey ? "key" : "id";
+                       const char *errmsg;
+                       const char *const what = iskey ? "key" : "id";
 
                        error++;
                        switch (errno) {
index ee45f01a6bf907737a0ed8f2688c22c6f9f0d245..ba98519b6380a39e1fd5cb97535dcf90ccd46cfc 100644 (file)
@@ -64,7 +64,7 @@ enum {
  * flags */
 
 struct {
-       char *name;
+       const char *name;
        long flags;
 } static mount_options[] = {
        // MS_FLAGS set a bit.  ~MS_FLAGS disable that bit.  0 flags are NOPs.
@@ -122,7 +122,7 @@ struct {
 #define VECTOR_SIZE(v) (sizeof(v) / sizeof((v)[0]))
 
 /* Append mount options to string */
-static void append_mount_options(char **oldopts, char *newopts)
+static void append_mount_options(char **oldopts, const char *newopts)
 {
        if (*oldopts && **oldopts) {
                /* do not insert options which are already there */
@@ -303,7 +303,7 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
                fsname = 0;
                if (!mp->mnt_type || !*mp->mnt_type) { /* bind mount */
                        mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname);
-                       mp->mnt_type = "bind";
+                       mp->mnt_type = (char*)"bind";
                }
                mp->mnt_freq = mp->mnt_passno = 0;
 
@@ -1342,7 +1342,7 @@ prepare_kernel_data:
 
 do_mount: /* perform actual mount */
 
-       mp->mnt_type = "nfs";
+       mp->mnt_type = (char*)"nfs";
        retval = mount_it_now(mp, vfsflags, (char*)&data);
        goto ret;
 
@@ -1428,7 +1428,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
                // lock is required
                vfsflags |= MS_MANDLOCK;
 
-               mp->mnt_type = "cifs";
+               mp->mnt_type = (char*)"cifs";
                rc = mount_it_now(mp, vfsflags, filteropts);
                if (ENABLE_FEATURE_CLEAN_UP) free(mp->mnt_fsname);
                goto report_error;