Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/lib/vsprintf.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | */ |
| 6 | |
| 7 | /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ |
| 8 | /* |
| 9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) |
| 10 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 11 | #include <stdarg.h> |
| 12 | #include <string.h> |
| 13 | |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 14 | int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 15 | |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 16 | /* FIXME this global makes vsprintf non-reentrant */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 17 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 18 | static char *str_buf; |
| 19 | static void str_tx_byte(unsigned char byte) |
| 20 | { |
| 21 | *str_buf = byte; |
| 22 | str_buf++; |
| 23 | } |
| 24 | |
| 25 | int vsprintf(char * buf, const char *fmt, va_list args) |
| 26 | { |
| 27 | int i; |
| 28 | str_buf = buf; |
| 29 | i = vtxprintf(str_tx_byte, fmt, args); |
| 30 | /* maeder/Ispiri -- The null termination was missing a deference */ |
| 31 | /* and was just zeroing out the pointer instead */ |
| 32 | *str_buf = '\0'; |
| 33 | return i; |
| 34 | } |
| 35 | |
| 36 | int sprintf(char * buf, const char *fmt, ...) |
| 37 | { |
| 38 | va_list args; |
| 39 | int i; |
| 40 | |
| 41 | va_start(args, fmt); |
| 42 | i=vsprintf(buf,fmt,args); |
| 43 | va_end(args); |
| 44 | return i; |
| 45 | } |