1 Index: ./lib/__v_printf.c
2 ===================================================================
3 RCS file: /cvs/dietlibc/lib/__v_printf.c,v
4 retrieving revision 1.33
5 retrieving revision 1.35
7 --- ./lib/__v_printf.c 10 Jan 2007 22:51:09 -0000 1.33
8 +++ ./lib/__v_printf.c 17 May 2007 05:00:42 -0000 1.35
10 #define B_WRITE(fn,buf,sz) { if ((unsigned long)(sz) > (((unsigned long)(int)(-1))>>1) || len+(int)(sz)<len) return -1; A_WRITE(fn,buf,sz); } while (0)
12 static const char pad_line[2][16]= { " ", "0000000000000000", };
13 -static int write_pad(int* dlen,struct arg_printf* fn, int len, int padwith) {
14 +static int write_pad(unsigned int* dlen,struct arg_printf* fn, unsigned int len, int padwith) {
16 - if (len<0 || *dlen+len<len) return -1;
17 + if ((int)len<0 || *dlen+len<len) return -1;
18 for (;len>15;len-=16,nr+=16) {
19 A_WRITE(fn,pad_line[(padwith=='0')?1:0],16);
23 int __v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr)
27 #ifdef WANT_ERROR_PRINTF
34 - unsigned char ch, padwith=' ';
35 + unsigned char ch, padwith=' ', precpadwith=' ';
40 if (flag_dot && sz>preci) sz=preci;
44 + padwith=precpadwith=' ';
55 - vs=preci>sz?preci:sz;
56 - if (write_pad(&len,fn,(signed int)width-(signed int)vs,' '))
59 - B_WRITE(fn,sign,todo);
62 - if (write_pad(&len,fn,(signed int)preci-(signed int)sz,'0'))
65 - if (todo && padwith=='0') {
66 - B_WRITE(fn,sign,todo);
69 - if (write_pad(&len,fn,(signed int)width-(signed int)sz, padwith))
72 - B_WRITE(fn,sign,todo);
76 - B_WRITE(fn,s,sz); len+=sz;
77 - } else if (flag_left) {
79 - B_WRITE(fn,sign,todo);
82 - if (write_pad(&len,fn,(signed int)preci-(signed int)sz, '0'))
84 + /* These are the cases for 1234 or "1234" respectively:
95 + In this code, for %6.5s, 6 is width, 5 is preci.
96 + flag_dot means there was a '.' and preci is set.
97 + flag_left means there was a '-'.
98 + sz is 4 (strlen("1234")).
99 + padwith will be '0' for %06u, ' ' otherwise.
100 + precpadwith is '0' for %u, ' ' for %s.
103 + if (flag_dot && width==0) width=preci;
104 + if (!flag_dot) preci=sz;
105 + if (!flag_left) { /* do left-side padding */
106 + if (write_pad(&len,fn,width-preci,padwith))
108 - B_WRITE(fn,s,sz); len+=sz;
109 - vs=preci>sz?preci:sz;
110 - if ((signed int)width-(signed int)vs<0) return -1;
111 - if (write_pad(&len,fn,(signed int)width-(signed int)vs, ' '))
114 + B_WRITE(fn,sign,todo);
117 + /* do preci padding */
118 + if (write_pad(&len,fn,preci-sz,precpadwith))
120 + /* write actual string */
121 + B_WRITE(fn,s,sz); len+=sz;
123 + if (write_pad(&len,fn,width-preci,padwith))
126 - B_WRITE(fn,s,sz); len+=sz;
134 } else flag_in_sign=0;
140 #ifdef WANT_FLOATING_POINT_IN_PRINTF
145 + if (width<sz) width=sz;