[comp.bugs.4bsd] libc/stdio/strout.c does not process all prefix characters. +Fix

gww@marduk.UUCP (Gary Winiger) (09/05/87)

Subject: lib/libc/stdio/strout.c does not process all the prefix characters. +Fix
Index:	lib/libc/stdio/strout.c 4.3BSD +Fix

Description:
	If _strout is called as an aid to _doprnt (obviously not on a VAX), it
	does not correctly process any prefix character other than '-' when
	right adjusting with leading zeros.
Repeat-By:
	_strout(7, "0xffff\n", -6, stdout, '0'); fflush(stdout);
Fix:
	Take into account all prefix characters.
	The attached code resolves this problem at Elxsi.

Gary..
{ucbvax!sun,lll-lcc!lll-tis,amdahl!altos86,bridge2}!elxsi!gww
--------- cut --------- snip --------- :.,$w diff -------------
*** /tmp/,RCSt1002845	Fri Feb  6 10:21:07 1987
--- strout.c	Fri Feb  6 10:08:36 1987
***************
*** 1,11 ****
  /*
   * $Log:	strout.c,v $
   * Revision 1.1  87/01/14  14:07:46  gww
   * Initial revision
   * 
   */
  #if defined(LIBC_SCCS) && !defined(lint)
! static char *ERcsId = "$Header: strout.c,v 1.1 87/01/14 14:07:46 gww Exp $ ENIX BSD";
  static char sccsid[] = "@(#)strout.c	5.2 (Berkeley) 3/9/86";
  #endif LIBC_SCCS and not lint
  
--- 1,14 ----
  /*
   * $Log:	strout.c,v $
+  * Revision 1.2  87/02/06  10:07:43  gww
+  * Take into account all prefix characters (-,+,0x,0X), not just '-'.
+  * 
   * Revision 1.1  87/01/14  14:07:46  gww
   * Initial revision
   * 
   */
  #if defined(LIBC_SCCS) && !defined(lint)
! static char *ERcsId = "$Header: strout.c,v 1.2 87/02/06 10:07:43 gww Exp $ ENIX BSD";
  static char sccsid[] = "@(#)strout.c	5.2 (Berkeley) 3/9/86";
  #endif LIBC_SCCS and not lint
  
***************
*** 16,27 ****
  register count;
  int adjust;
  register FILE *file;
! {
! 	while (adjust < 0) {
! 		if (*string=='-' && fillch=='0') {
  			putc(*string++, file);
  			count--;
  		}
  		putc(fillch, file);
  		adjust++;
  	}
--- 19,48 ----
  register count;
  int adjust;
  register FILE *file;
! {  
! 	/* output prefix characters before filling */
! 
! 	if ((adjust < 0) && (fillch == '0')) {
! 		switch (*string) {
! 		case '-':
! 		case '+':
! 		case ' ':
  			putc(*string++, file);
  			count--;
+ 			break;
+ 		case '0':
+ 			if ((string[1] == 'x') || (string[1] == 'X')) {
+ 				putc(*string++, file);
+ 				putc(*string++, file);
+ 				count -= 2;
+ 			}
+ 			break;
+ 		default:
+ 			break;
  		}
+ 	}
+ 
+ 	while (adjust < 0) {
  		putc(fillch, file);
  		adjust++;
  	}