Changeset 4ddeace in mainline for generic/src/printf/printf_core.c
- Timestamp:
- 2006-06-06T11:45:42Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 99f3249
- Parents:
- 3247f0a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/printf/printf_core.c
r3247f0a r4ddeace 101 101 * @param count 102 102 * @param ps output method and its data 103 * @return 0 on success, EOF on fail103 * @return number or printed characters 104 104 */ 105 105 static int printf_putnchars(const char * buf, size_t count, struct printf_spec *ps) 106 106 { 107 if (ps->write((void *)buf, count, ps->data) == count) { 108 return 0; 109 } 110 111 return EOF; 107 return ps->write((void *)buf, count, ps->data); 112 108 } 113 109 … … 115 111 * @param str string to print 116 112 * @param ps write function specification and support data 117 * @return 0 on success or EOF on fail113 * @return number or printed characters 118 114 */ 119 115 static int printf_putstr(const char * str, struct printf_spec *ps) … … 127 123 count = strlen(str); 128 124 129 if (ps->write((void *) str, count, ps->data) == count) { 130 return 0; 131 } 132 133 return EOF; 125 return ps->write((void *) str, count, ps->data); 134 126 } 135 127 … … 137 129 * @param c one character 138 130 * @param ps output method 139 * @return printed character or EOF131 * @return number or printed characters 140 132 */ 141 133 static int printf_putchar(int c, struct printf_spec *ps) … … 143 135 unsigned char ch = c; 144 136 145 if (ps->write((void *) &ch, 1, ps->data) == 1) { 146 return c; 147 } 148 149 return EOF; 137 return ps->write((void *) &ch, 1, ps->data); 150 138 } 151 139 … … 154 142 * @param width 155 143 * @param flags 156 * @return number of printed characters or EOF144 * @return number of printed characters, negative value on fail 157 145 */ 158 146 static int print_char(char c, int width, __u64 flags, struct printf_spec *ps) … … 163 151 while (--width > 0) { /* one space is consumed by character itself hence predecrement */ 164 152 /* FIXME: painful slow */ 165 printf_putchar(' ', ps); 153 if (printf_putchar(' ', ps) > 0) 154 ++counter; 155 } 156 } 157 158 if (printf_putchar(c, ps) > 0) 159 counter++; 160 161 while (--width > 0) { /* one space is consumed by character itself hence predecrement */ 162 if (printf_putchar(' ', ps) > 0) 166 163 ++counter; 167 }168 }169 170 if (printf_putchar(c, ps) == EOF) {171 return EOF;172 }173 174 while (--width > 0) { /* one space is consumed by character itself hence predecrement */175 printf_putchar(' ', ps);176 ++counter;177 164 } 178 165 … … 185 172 * @param precision 186 173 * @param flags 187 * @return number of printed characters or EOF174 * @return number of printed characters or negative value on fail 188 175 */ 189 176 … … 192 179 int counter = 0; 193 180 size_t size; 181 int retval; 194 182 195 183 if (s == NULL) { … … 208 196 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { 209 197 while (width-- > 0) { 210 printf_putchar(' ', ps);211 counter++;198 if (printf_putchar(' ', ps) == 1) 199 counter++; 212 200 } 213 201 } … … 215 203 while (precision > size) { 216 204 precision--; 217 printf_putchar(' ', ps); 218 ++counter; 219 } 220 221 if (printf_putnchars(s, precision, ps) == EOF) { 222 return EOF; 223 } 224 225 counter += precision; 205 if (printf_putchar(' ', ps) == 1) 206 ++counter; 207 } 208 209 if ((retval = printf_putnchars(s, precision, ps)) < 0) { 210 return -counter; 211 } 212 counter += retval; 226 213 227 214 while (width-- > 0) { 228 printf_putchar(' ', ps);229 ++counter;230 } 231 232 return ++counter;215 if (printf_putchar(' ', ps) == 1) 216 ++counter; 217 } 218 219 return counter; 233 220 } 234 221 … … 255 242 int size = 0; /* size of number with all prefixes and signs */ 256 243 int number_size; /* size of plain number */ 257 int written = 0;258 244 char sgn; 245 int retval; 246 int counter = 0; 259 247 260 248 if (flags & __PRINTF_FLAG_BIGCHARS) … … 323 311 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { 324 312 while (width-- > 0) { 325 printf_putchar(' ', ps);326 written++;313 if (printf_putchar(' ', ps) == 1) 314 counter++; 327 315 } 328 316 } 317 329 318 330 319 /* print sign */ 331 320 if (sgn) { 332 printf_putchar(sgn, ps);333 written++;321 if (printf_putchar(sgn, ps) == 1) 322 counter++; 334 323 } 335 324 … … 339 328 switch(base) { 340 329 case 2: /* Binary formating is not standard, but usefull */ 341 printf_putchar('0', ps); 330 if (printf_putchar('0', ps) == 1) 331 counter++; 342 332 if (flags & __PRINTF_FLAG_BIGCHARS) { 343 printf_putchar('B', ps); 333 if (printf_putchar('B', ps) == 1) 334 counter++; 344 335 } else { 345 printf_putchar('b', ps); 336 if (printf_putchar('b', ps) == 1) 337 counter++; 346 338 } 347 written += 2;348 339 break; 349 340 case 8: 350 printf_putchar('o', ps);351 written++;341 if (printf_putchar('o', ps) == 1) 342 counter++; 352 343 break; 353 344 case 16: 354 printf_putchar('0', ps); 345 if (printf_putchar('0', ps) == 1) 346 counter++; 355 347 if (flags & __PRINTF_FLAG_BIGCHARS) { 356 printf_putchar('X', ps); 348 if (printf_putchar('X', ps) == 1) 349 counter++; 357 350 } else { 358 printf_putchar('x', ps); 351 if (printf_putchar('x', ps) == 1) 352 counter++; 359 353 } 360 written += 2;361 354 break; 362 355 } … … 366 359 precision -= number_size; 367 360 while (precision-- > 0) { 368 printf_putchar('0', ps);369 written++;361 if (printf_putchar('0', ps) == 1) 362 counter++; 370 363 } 371 364 … … 373 366 /* print number itself */ 374 367 375 written += printf_putstr(++ptr, ps); 368 if ((retval = printf_putstr(++ptr, ps)) > 0) { 369 counter += retval; 370 } 376 371 377 372 /* print ending spaces */ 378 373 379 374 while (width-- > 0) { 380 printf_putchar(' ', ps);381 written++;382 } 383 384 return written;375 if (printf_putchar(' ', ps) == 1) 376 counter++; 377 } 378 379 return counter; 385 380 } 386 381 … … 485 480 /* print common characters if any processed */ 486 481 if (i > j) { 487 if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) == EOF) { /* error */482 if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) < 0) { /* error */ 488 483 counter = -counter; 489 484 goto out; … … 582 577 */ 583 578 case 's': 584 if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) == EOF) {579 if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) { 585 580 counter = -counter; 586 581 goto out; … … 592 587 case 'c': 593 588 c = va_arg(ap, unsigned int); 594 if ((retval = print_char(c, width, flags, ps)) == EOF) {589 if ((retval = print_char(c, width, flags, ps)) < 0) { 595 590 counter = -counter; 596 591 goto out; … … 693 688 } 694 689 695 if ((retval = print_number(number, width, precision, base, flags, ps)) == EOF) {690 if ((retval = print_number(number, width, precision, base, flags, ps)) < 0) { 696 691 counter = -counter; 697 692 goto out; … … 707 702 708 703 if (i > j) { 709 if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) == EOF) { /* error */704 if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) < 0) { /* error */ 710 705 counter = -counter; 711 706 goto out;
Note:
See TracChangeset
for help on using the changeset viewer.