| 1 | /* Provide a version of _doprnt in terms of fprintf.
|
|---|
| 2 | Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
|---|
| 3 | Contributed by Kaveh Ghazi ([email protected]) 3/29/98
|
|---|
| 4 |
|
|---|
| 5 | This program is free software; you can redistribute it and/or modify it
|
|---|
| 6 | under the terms of the GNU General Public License as published by the
|
|---|
| 7 | Free Software Foundation; either version 2, or (at your option) any
|
|---|
| 8 | later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program; if not, write to the Free Software
|
|---|
| 17 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 18 |
|
|---|
| 19 | #include "config.h"
|
|---|
| 20 | #include "ansidecl.h"
|
|---|
| 21 | #include "safe-ctype.h"
|
|---|
| 22 |
|
|---|
| 23 | #include <stdio.h>
|
|---|
| 24 | #ifdef ANSI_PROTOTYPES
|
|---|
| 25 | #include <stdarg.h>
|
|---|
| 26 | #else
|
|---|
| 27 | #include <varargs.h>
|
|---|
| 28 | #endif
|
|---|
| 29 | #ifdef HAVE_STRING_H
|
|---|
| 30 | #include <string.h>
|
|---|
| 31 | #endif
|
|---|
| 32 | #ifdef HAVE_STDLIB_H
|
|---|
| 33 | #include <stdlib.h>
|
|---|
| 34 | #endif
|
|---|
| 35 |
|
|---|
| 36 | #undef _doprnt
|
|---|
| 37 |
|
|---|
| 38 | #ifdef HAVE__DOPRNT
|
|---|
| 39 | #define TEST
|
|---|
| 40 | #endif
|
|---|
| 41 |
|
|---|
| 42 | #ifdef TEST /* Make sure to use the internal one. */
|
|---|
| 43 | #define _doprnt my_doprnt
|
|---|
| 44 | #endif
|
|---|
| 45 |
|
|---|
| 46 | #define COPY_VA_INT \
|
|---|
| 47 | do { \
|
|---|
| 48 | const int value = abs (va_arg (ap, int)); \
|
|---|
| 49 | char buf[32]; \
|
|---|
| 50 | ptr++; /* Go past the asterisk. */ \
|
|---|
| 51 | *sptr = '\0'; /* NULL terminate sptr. */ \
|
|---|
| 52 | sprintf(buf, "%d", value); \
|
|---|
| 53 | strcat(sptr, buf); \
|
|---|
|
|---|