Print this page
4854 printf(1) doesn't support %b and \c properly

@@ -90,11 +90,11 @@
 
 int
 main(int argc, char *argv[])
 {
         size_t len;
-        int chopped, end, rval;
+        int end, rval;
         char *format, *fmt, *start;
 
         (void) setlocale(LC_ALL, "");
 
         argv++;

@@ -122,11 +122,11 @@
          * format strings are reused as necessary to use up the provided
          * arguments, arguments of zero/null string are provided to use
          * up the format string.
          */
         fmt = format = *argv;
-        chopped = escape(fmt, 1, &len);         /* backslash interpretation */
+        (void) escape(fmt, 1, &len);    /* backslash interpretation */
         rval = end = 0;
         gargv = ++argv;
 
         for (;;) {
                 maxargv = gargv;

@@ -160,11 +160,11 @@
                 if (end == 1) {
                         warnx1(_("missing format character"), NULL, NULL);
                         return (1);
                 }
                 (void) fwrite(start, 1, PTRDIFF(fmt, start), stdout);
-                if (chopped || !*gargv)
+                if (!*gargv)
                         return (rval);
                 /* Restart at the beginning of the format string. */
                 fmt = format;
                 end = 1;
         }

@@ -336,17 +336,15 @@
                 if (p == NULL) {
                         warnx2("%s", strerror(ENOMEM), NULL);
                         return (NULL);
                 }
                 getout = escape(p, 0, &len);
-                *(fmt - 1) = 's';
-                PF(start, p);
-                *(fmt - 1) = 'b';
+                (void) fputs(p, stdout);
                 free(p);
 
                 if (getout)
-                        return (fmt);
+                        exit(*rval);
                 break;
         }
         case 'c': {
                 char p;
 

@@ -454,13 +452,17 @@
                         break;
                 case 'b':               /* backspace */
                         *store = '\b';
                         break;
                 case 'c':
+                        if (!percent) {
                         *store = '\0';
                         *len = PTRDIFF(store, save);
                         return (1);
+                        }
+                        *store = 'c';
+                        break;
                 case 'f':               /* form-feed */
                         *store = '\f';
                         break;
                 case 'n':               /* newline */
                         *store = '\n';