changeset 1183:0752b2d58909 draft

Rename xmsprintf() to just xmprintf(). Partly because there's no supplied target string ala sprintf, and partly because I can never remember what order the m and s go in.
author Rob Landley <rob@landley.net>
date Thu, 16 Jan 2014 09:26:50 -0600
parents 7079ea384a2e
children 48334d7a2b55
files lib/lib.h lib/password.c lib/xwrap.c toys/lsb/mktemp.c toys/lsb/passwd.c toys/lsb/su.c toys/lsb/umount.c toys/other/pwdx.c toys/pending/fdisk.c toys/pending/fsck.c toys/pending/groupadd.c toys/pending/init.c toys/pending/netstat.c toys/pending/ps.c toys/pending/syslogd.c toys/pending/tcpsvd.c toys/pending/useradd.c toys/pending/watch.c toys/posix/cp.c toys/posix/ln.c toys/posix/nohup.c toys/posix/split.c
diffstat 22 files changed, 52 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.h	Wed Jan 15 09:38:31 2014 -0600
+++ b/lib/lib.h	Thu Jan 16 09:26:50 2014 -0600
@@ -83,7 +83,7 @@
 void *xrealloc(void *ptr, size_t size);
 char *xstrndup(char *s, size_t n);
 char *xstrdup(char *s);
-char *xmsprintf(char *format, ...);
+char *xmprintf(char *format, ...);
 void xprintf(char *format, ...);
 void xputs(char *s);
 void xputc(char c);
--- a/lib/password.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/lib/password.c	Thu Jan 16 09:26:50 2014 -0600
@@ -129,7 +129,7 @@
   struct flock lock;
 
   shadow = strstr(filename, "shadow");
-  filenamesfx = xmsprintf("%s+", filename);
+  filenamesfx = xmprintf("%s+", filename);
   sfx = strchr(filenamesfx, '+');
 
   exfp = fopen(filename, "r+");
@@ -163,7 +163,7 @@
   }
 
   ret = 0;
-  namesfx = xmsprintf("%s:",username);
+  namesfx = xmprintf("%s:",username);
   while ((line = get_line(fileno(exfp))) != NULL)
   {
     if (strncmp(line, namesfx, strlen(namesfx)))
--- a/lib/xwrap.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/lib/xwrap.c	Thu Jan 16 09:26:50 2014 -0600
@@ -66,7 +66,7 @@
 }
 
 // Die unless we can allocate enough space to sprintf() into.
-char *xmsprintf(char *format, ...)
+char *xmprintf(char *format, ...)
 {
   va_list va, va2;
   int len;
--- a/toys/lsb/mktemp.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/lsb/mktemp.c	Thu Jan 16 09:26:50 2014 -0600
@@ -38,7 +38,7 @@
     if (!TT.tmpdir) TT.tmpdir = "/tmp";
     tmp = "tmp.xxxxxx";
   }
-  if (TT.tmpdir) tmp = xmsprintf("%s/%s", TT.tmpdir ? TT.tmpdir : "/tmp",
+  if (TT.tmpdir) tmp = xmprintf("%s/%s", TT.tmpdir ? TT.tmpdir : "/tmp",
     *toys.optargs ? *toys.optargs : "tmp.XXXXXX");
 
   if (d_flag ? mkdtemp(tmp) == NULL : mkstemp(tmp) == -1)
--- a/toys/lsb/passwd.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/lsb/passwd.c	Thu Jan 16 09:26:50 2014 -0600
@@ -160,7 +160,7 @@
   } else if (toys.optflags & FLAG_l) {
     if (pass[0] == '!') error_exit("password is already locked for %s",name);
     printf("Locking password for %s\n",name);
-    encrypted = xmsprintf("!%s",pass);
+    encrypted = xmprintf("!%s",pass);
   } else if (toys.optflags & FLAG_u) {
     if (pass[0] != '!') error_exit("password is already unlocked for %s",name);
 
--- a/toys/lsb/su.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/lsb/su.c	Thu Jan 16 09:26:50 2014 -0600
@@ -33,7 +33,7 @@
 {
   char *s = getenv(name);
 
-  if (s) return xmsprintf("%s=%s", name, s);
+  if (s) return xmprintf("%s=%s", name, s);
 
   return 0;
 }
--- a/toys/lsb/umount.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/lsb/umount.c	Thu Jan 16 09:26:50 2014 -0600
@@ -57,7 +57,7 @@
     char *comma = ",";
 
     if (atold[strlen(atold)-1] == ',') comma = "";
-    temp = xmsprintf("%s%s%s", atold, comma, new);
+    temp = xmprintf("%s%s%s", atold, comma, new);
   } else temp = xstrdup(new);
   free (atold);
   *old = temp;
--- a/toys/other/pwdx.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/other/pwdx.c	Thu Jan 16 09:26:50 2014 -0600
@@ -23,7 +23,7 @@
     char *path;
     int num_bytes;
 
-    path = xmsprintf("/proc/%s/cwd", *optargs);
+    path = xmprintf("/proc/%s/cwd", *optargs);
     num_bytes = readlink(path, toybuf, sizeof(toybuf)-1);
     free(path);
 
--- a/toys/pending/fdisk.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/fdisk.c	Thu Jan 16 09:26:50 2014 -0600
@@ -1005,7 +1005,7 @@
     return;
   }
 
-  msg = xmsprintf("  %s\n  p  primary partition(1-4)\n",
+  msg = xmprintf("  %s\n  p  primary partition(1-4)\n",
           extended_offset? "l  logical (5 or over)" : "e  extended");
 
   choice = 0x20 | read_input(msg, NULL);
--- a/toys/pending/fsck.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/fsck.c	Thu Jan 16 09:26:50 2014 -0600
@@ -198,9 +198,9 @@
   else type = "auto";
 
   args = xzalloc((toys.optc + 2 + 1 + 1) * sizeof(char*)); //+1, for NULL, +1 if -C
-  args[0] = xmsprintf("fsck.%s", type);
+  args[0] = xmprintf("fsck.%s", type);
   
-  if(toys.optflags & FLAG_C) args[i++] = xmsprintf("%s %d","-C", TT.fd_num);
+  if(toys.optflags & FLAG_C) args[i++] = xmprintf("%s %d","-C", TT.fd_num);
   while(toys.optargs[j]) {
     if(*toys.optargs[j]) args[i++] = xstrdup(toys.optargs[j]);
     j++;
--- a/toys/pending/groupadd.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/groupadd.c	Thu Jan 16 09:26:50 2014 -0600
@@ -59,10 +59,10 @@
     }
   }
 
-  entry = xmsprintf("%s:%s:%d:", *toys.optargs, "x", TT.gid);
+  entry = xmprintf("%s:%s:%d:", *toys.optargs, "x", TT.gid);
   update_password(GROUP_PATH, *toys.optargs, entry);
   free(entry);
-  entry = xmsprintf("%s:%s::", *toys.optargs, "!");
+  entry = xmprintf("%s:%s::", *toys.optargs, "!");
   update_password(SECURE_GROUP_PATH, *toys.optargs, entry);
   free(entry);
 }
@@ -82,7 +82,7 @@
     xgetpwnam(*toys.optargs);
     if (!(grp = getgrnam(toys.optargs[1]))) 
       error_exit("group '%s' does not exist", toys.optargs[1]);
-    if (!grp->gr_mem) entry = xmsprintf("%s", *toys.optargs);
+    if (!grp->gr_mem) entry = xmprintf("%s", *toys.optargs);
     else {
       int i;
 
--- a/toys/pending/init.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/init.c	Thu Jan 16 09:26:50 2014 -0600
@@ -155,8 +155,8 @@
           case 1:
             if (*extracted_token) {
               if (!strncmp(extracted_token, "/dev/", 5))
-                tty_name = xmsprintf("%s",extracted_token);
-              else tty_name = xmsprintf("/dev/%s",extracted_token);
+                tty_name = xmprintf("%s",extracted_token);
+              else tty_name = xmprintf("/dev/%s",extracted_token);
             } else tty_name = xstrdup("");
             break;
           case 2:
--- a/toys/pending/netstat.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/netstat.c	Thu Jan 16 09:26:50 2014 -0600
@@ -115,7 +115,7 @@
   if (!path) path = "";
   c = find_last_char(path, '/');
   while (*fname == '/') fname++;
-  return xmsprintf("%s%s%s", path, (c)? "" : "/", fname);
+  return xmprintf("%s%s%s", path, (c)? "" : "/", fname);
 }
 /*
  * Concat sub-path and the file name.
@@ -211,10 +211,10 @@
 static char *get_servname(int port, char *label)
 {
   int lport = htons(port);
-  if (!lport) return xmsprintf("%s", "*");
+  if (!lport) return xmprintf("%s", "*");
   struct servent *ser = getservbyport(lport, label);
-  if (ser) return xmsprintf("%s", ser->s_name);
-  return xmsprintf("%u", (unsigned)ntohs(lport));
+  if (ser) return xmprintf("%s", ser->s_name);
+  return xmprintf("%u", (unsigned)ntohs(lport));
 }
 /*
  * used to convert address into text format.
--- a/toys/pending/ps.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/ps.c	Thu Jan 16 09:26:50 2014 -0600
@@ -104,8 +104,8 @@
           temp++;
           while (def_header[i].name) {
             if (!(strcmp(def_header[i].name, ptr))) { // search from default header
-              if (str) ptr = xmsprintf("%s,%s", temp, str); //handle condition like ppid = M,OM
-              else ptr = xmsprintf("%s", temp);
+              if (str) ptr = xmprintf("%s,%s", temp, str); //handle condition like ppid = M,OM
+              else ptr = xmprintf("%s", temp);
               list_add(&o_list, &def_header[i], ptr);
               break;
             }
@@ -163,7 +163,7 @@
   min = info.uptime - min;
   sec = min % 60;
   min = min / 60;
-  temp = xmsprintf("%3lu:%02u", min,sec);
+  temp = xmprintf("%3lu:%02u", min,sec);
   xprintf("%*.*s",7,7,temp);
   free(temp);
 }
@@ -177,7 +177,7 @@
   min = (s_time + u_time)/sysconf(_SC_CLK_TCK);
   sec = min % 60;
   min = min / 60;
-  temp = xmsprintf("%3lu:%02u", min,sec);
+  temp = xmprintf("%3lu:%02u", min,sec);
   xprintf("%*.*s",6,6,temp);
   free(temp);
 }
@@ -237,7 +237,7 @@
   name = ptr;
   ptr = strrchr(stat_buff, ')');
   *ptr = '\0'; //unecessary if?
-  name = xmsprintf("[%s]", name);
+  name = xmprintf("[%s]", name);
   ptr += 2; // goto STATE
   n = sscanf(ptr, "%c %u %u %*u %d %*s %*s %*s %*s %*s %*s "
       "%lu %lu %*s %*s %*s %d %*s %*s %lu %lu %ld",            
@@ -272,15 +272,15 @@
     switch (p->position) {
       case 0:
         pw = getpwuid(stats.st_uid);
-        if (!pw) user = xmsprintf("%d",(int)stats.st_uid);
-        else user = xmsprintf("%s", pw->pw_name);
+        if (!pw) user = xmprintf("%d",(int)stats.st_uid);
+        else user = xmprintf("%s", pw->pw_name);
         printf("%-*.*s", width, width, user);
         free(user);
         break;
       case 1:
         gr = getgrgid(stats.st_gid);
-        if (!gr) group = xmsprintf("%d",(int)stats.st_gid);
-        else group = xmsprintf("%s", gr->gr_name);
+        if (!gr) group = xmprintf("%d",(int)stats.st_gid);
+        else group = xmprintf("%s", gr->gr_name);
         printf("%-*.*s", width, width, group);
         free(group);
         break;
@@ -322,16 +322,16 @@
       case 9:
         get_uid_gid(stat_buff, "Gid:", &rgid);
         gr = getgrgid(rgid);
-        if (!gr) rgroup = xmsprintf("%d",(int)stats.st_gid);
-        else rgroup = xmsprintf("%s", gr->gr_name);
+        if (!gr) rgroup = xmprintf("%d",(int)stats.st_gid);
+        else rgroup = xmprintf("%s", gr->gr_name);
         printf("%-*.*s", width,width, rgroup);
         free(rgroup);
         break;
       case 10:
         get_uid_gid(stat_buff, "Uid:", &ruid);
         pw = getpwuid(ruid);
-        if (!pw) ruser = xmsprintf("%d",(int)stats.st_uid);
-        else ruser = xmsprintf("%s", pw->pw_name);
+        if (!pw) ruser = xmprintf("%d",(int)stats.st_uid);
+        else ruser = xmprintf("%s", pw->pw_name);
         printf("%-*.*s", width, width, ruser);
         free(ruser);
         break;
@@ -340,7 +340,7 @@
         break;
       case 12:
         if (tty_major) {
-          char *temp = xmsprintf("%d,%d", tty_major,tty_minor);
+          char *temp = xmprintf("%d,%d", tty_major,tty_minor);
           printf("%-*s", width, temp);
           free(temp);
         } else printf("%-*s", width, "?");
@@ -370,7 +370,7 @@
   DIR *d; 
   int tid;
   struct dirent *de;
-  char *tmp = xmsprintf("/proc/%d/task",pid);
+  char *tmp = xmprintf("/proc/%d/task",pid);
 
   if (!(d = opendir(tmp))) {
     free(tmp);
--- a/toys/pending/syslogd.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/syslogd.c	Thu Jan 16 09:26:50 2014 -0600
@@ -176,7 +176,7 @@
    */
   if (toys.optflags & FLAG_R) {
     file = xzalloc(sizeof(struct logfile));
-    file->filename = xmsprintf("@%s",TT.remote_log);
+    file->filename = xmprintf("@%s",TT.remote_log);
     TT.lfiles = file;
     if (!(toys.optflags & FLAG_L)) return 0;
   }
--- a/toys/pending/tcpsvd.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/tcpsvd.c	Thu Jan 16 09:26:50 2014 -0600
@@ -79,8 +79,8 @@
 
   if (!(status = getnameinfo(sock, len, hbuf, sizeof(hbuf), sbuf, 
           sizeof(sbuf), flags))) {
-    if (flags & NI_NUMERICSERV) return xmsprintf("%s:%s",hbuf, sbuf);
-    return xmsprintf("%s",hbuf);
+    if (flags & NI_NUMERICSERV) return xmprintf("%s:%s",hbuf, sbuf);
+    return xmprintf("%s",hbuf);
   }
   error_exit("getnameinfo: %s", gai_strerror(status));
 }
--- a/toys/pending/useradd.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/useradd.c	Thu Jan 16 09:26:50 2014 -0600
@@ -90,7 +90,7 @@
 
     args[0] = "chown";
     args[1] = "-R";
-    args[2] = xmsprintf("%u:%u", TT.uid, TT.gid);
+    args[2] = xmprintf("%u:%u", TT.uid, TT.gid);
     args[3] = hdir;
     //Change ownership to that of UID and GID of new user
     toys.exitval = exec_wait(args);
@@ -118,7 +118,7 @@
   if (toys.optflags & FLAG_g) pwd.pw_gecos = TT.gecos;
   else pwd.pw_gecos = "Linux User,";
   if (toys.optflags & FLAG_h) pwd.pw_dir = TT.dir;
-  else pwd.pw_dir = xmsprintf("/home/%s", *toys.optargs);
+  else pwd.pw_dir = xmprintf("/home/%s", *toys.optargs);
   if (toys.optflags & FLAG_s) pwd.pw_shell = TT.shell;
   else pwd.pw_shell = get_shell();
 
@@ -168,7 +168,7 @@
     //add group, invoke addgroup command
     args[0] = "groupadd";
     args[1] = toys.optargs[0];
-    args[2] = xmsprintf("-g%ld", pwd.pw_gid);
+    args[2] = xmprintf("-g%ld", pwd.pw_gid);
     args[3] = NULL;
     if (exec_wait(args)) error_msg("addgroup fail");
   }
@@ -180,15 +180,15 @@
    */
 
   // 1. add an entry to /etc/passwd and /etc/shadow file
-  entry = xmsprintf("%s:%s:%ld:%ld:%s:%s:%s", pwd.pw_name, pwd.pw_passwd,
+  entry = xmprintf("%s:%s:%ld:%ld:%s:%s:%s", pwd.pw_name, pwd.pw_passwd,
       pwd.pw_uid, pwd.pw_gid, pwd.pw_gecos, pwd.pw_dir, pwd.pw_shell);
   if (update_password("/etc/passwd", pwd.pw_name, entry)) error_exit("updating passwd file failed");
   free(entry);
 
   if (toys.optflags & FLAG_S) 
-  entry = xmsprintf("%s:!!:%u::::::", pwd.pw_name, 
+  entry = xmprintf("%s:!!:%u::::::", pwd.pw_name, 
       (unsigned)(time(NULL))/(24*60*60)); //passwd is not set initially
-  else entry = xmsprintf("%s:!!:%u:%ld:%ld:%ld:::", pwd.pw_name, 
+  else entry = xmprintf("%s:!!:%u:%ld:%ld:%ld:::", pwd.pw_name, 
             (unsigned)(time(NULL))/(24*60*60), 0, 99999, 7); //passwd is not set initially
   update_password("/etc/shadow", pwd.pw_name, entry);
   free(entry);
--- a/toys/pending/watch.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/pending/watch.c	Thu Jan 16 09:26:50 2014 -0600
@@ -35,10 +35,10 @@
   while(toys.optargs[++i])
   {
     char * oldcmd = cmd;
-    cmd = xmsprintf("%s %s", oldcmd, toys.optargs[i]);
+    cmd = xmprintf("%s %s", oldcmd, toys.optargs[i]);
     if (CFG_TOYBOX_FREE) free(oldcmd);
   }
-  header = xmsprintf("Every %us: %s", TT.interval, cmd);
+  header = xmprintf("Every %us: %s", TT.interval, cmd);
   hlen = strlen(header);
 
   while(1) {
--- a/toys/posix/cp.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/posix/cp.c	Thu Jan 16 09:26:50 2014 -0600
@@ -176,7 +176,7 @@
 
         if (*or->name == '/') dotdots = 0;
         if (dotdots) {
-          char *s2 = xmsprintf("% *c%s", 3*dotdots, ' ', s);
+          char *s2 = xmprintf("% *c%s", 3*dotdots, ' ', s);
           free(s);
           s = s2;
           while(dotdots--) {
@@ -275,7 +275,7 @@
     char *src = toys.optargs[i];
     int rc = 1;
 
-    if (destdir) TT.destname = xmsprintf("%s/%s", destname, basename(src));
+    if (destdir) TT.destname = xmprintf("%s/%s", destname, basename(src));
     else TT.destname = destname;
 
     errno = EXDEV;
--- a/toys/posix/ln.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/posix/ln.c	Thu Jan 16 09:26:50 2014 -0600
@@ -48,7 +48,7 @@
     int rc;
     char *try = toys.optargs[i];
 
-    if (S_ISDIR(buf.st_mode)) new = xmsprintf("%s/%s", dest, basename(try));
+    if (S_ISDIR(buf.st_mode)) new = xmprintf("%s/%s", dest, basename(try));
     else new = dest;
     // Silently unlink the existing target (if any)
     if (toys.optflags & FLAG_f) unlink(new);
--- a/toys/posix/nohup.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/posix/nohup.c	Thu Jan 16 09:26:50 2014 -0600
@@ -28,7 +28,7 @@
         S_IRUSR|S_IWUSR ))
     {
       char *temp = getenv("HOME");
-      temp = xmsprintf("%s/%s", temp ? temp : "", "nohup.out");
+      temp = xmprintf("%s/%s", temp ? temp : "", "nohup.out");
       xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
     }
   }
--- a/toys/posix/split.c	Wed Jan 15 09:38:31 2014 -0600
+++ b/toys/posix/split.c	Thu Jan 16 09:26:50 2014 -0600
@@ -100,7 +100,7 @@
   if (!TT.bytes && !TT.lines) TT.lines = 1000;
 
   // Allocate template for output filenames
-  TT.outfile = xmsprintf("%s% *c", (toys.optc == 2) ? toys.optargs[1] : "x",
+  TT.outfile = xmprintf("%s% *c", (toys.optc == 2) ? toys.optargs[1] : "x",
     (int)TT.suflen, ' ');
 
   // We only ever use one input, but this handles '-' or no input for us.