[git] Updated (1.5.5.1 -> 1.5.5.4)
[opensde-package-nopast.git] / base / dietlibc / dietlibc-0.30-7_printf_pad.patch
blobf125ebd1a6b1234bd1b3fe3fe9232000e92a4835
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
6 diff -u -r1.33 -r1.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
9 @@ -19,9 +19,9 @@
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) {
15 int nr=0;
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);
21 @@ -34,7 +34,7 @@
23 int __v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr)
25 - int len=0;
26 + unsigned int len=0;
27 #ifdef WANT_ERROR_PRINTF
28 int _errno = errno;
29 #endif
30 @@ -51,7 +51,7 @@
31 #define s u_str.s
33 int retval;
34 - unsigned char ch, padwith=' ';
35 + unsigned char ch, padwith=' ', precpadwith=' ';
37 char flag_in_sign=0;
38 char flag_upcase=0;
39 @@ -172,7 +172,7 @@
40 if (flag_dot && sz>preci) sz=preci;
41 preci=0;
42 flag_dot^=flag_dot;
43 - padwith=' ';
44 + padwith=precpadwith=' ';
46 print_out:
48 @@ -192,46 +192,46 @@
49 sz-=todo;
50 width-=todo;
53 - if (!flag_left) {
54 - if (flag_dot) {
55 - vs=preci>sz?preci:sz;
56 - if (write_pad(&len,fn,(signed int)width-(signed int)vs,' '))
57 - return -1;
58 - if (todo) {
59 - B_WRITE(fn,sign,todo);
60 - len+=todo;
61 - }
62 - if (write_pad(&len,fn,(signed int)preci-(signed int)sz,'0'))
63 - return -1;
64 - } else {
65 - if (todo && padwith=='0') {
66 - B_WRITE(fn,sign,todo);
67 - len+=todo; todo=0;
68 - }
69 - if (write_pad(&len,fn,(signed int)width-(signed int)sz, padwith))
70 - return -1;
71 - if (todo) {
72 - B_WRITE(fn,sign,todo);
73 - len+=todo;
74 - }
75 - }
76 - B_WRITE(fn,s,sz); len+=sz;
77 - } else if (flag_left) {
78 - if (todo) {
79 - B_WRITE(fn,sign,todo);
80 - len+=todo;
81 - }
82 - if (write_pad(&len,fn,(signed int)preci-(signed int)sz, '0'))
84 + /* These are the cases for 1234 or "1234" respectively:
85 + %.6u -> "001234"
86 + %6u -> " 1234"
87 + %06u -> "001234"
88 + %-6u -> "1234 "
89 + %.6s -> "1234"
90 + %6s -> " 1234"
91 + %06s -> " 1234"
92 + %-6s -> "1234 "
93 + %6.5u -> " 01234"
94 + %6.5s -> " 1234"
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.
101 + */
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))
107 return -1;
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, ' '))
113 + if (todo) {
114 + B_WRITE(fn,sign,todo);
115 + len+=todo;
117 + /* do preci padding */
118 + if (write_pad(&len,fn,preci-sz,precpadwith))
119 + return -1;
120 + /* write actual string */
121 + B_WRITE(fn,s,sz); len+=sz;
122 + if (flag_left) {
123 + if (write_pad(&len,fn,width-preci,padwith))
124 return -1;
125 - } else {
126 - B_WRITE(fn,s,sz); len+=sz;
129 break;
132 @@ -327,6 +327,8 @@
133 ++sz;
134 } else flag_in_sign=0;
136 + precpadwith='0';
138 goto print_out;
140 #ifdef WANT_FLOATING_POINT_IN_PRINTF
141 @@ -374,6 +376,8 @@
144 sz=strlen(s);
145 + if (width<sz) width=sz;
146 + padwith='0';
147 flag_dot=0;
148 flag_hash=0;
149 goto print_out;