3 * dosio_sprintf.c - formatted print to a buffer using RawDoFmt()
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
10 #include <sys/cdefs.h> /* REG() and ASM macros */
11 #include <dos/rdargs.h> /* CSource */
15 #include <inline/exec.h>
17 #include <proto/exec.h>
19 #include <clib/exec_protos.h>
23 __stuffchar(REG(d0
) char ch
,
24 REG(a3
) struct CSource
* sc
)
26 if (sc
->CS_CurChr
< sc
->CS_Length
27 && (sc
->CS_Buffer
[sc
->CS_CurChr
] = ch
))
31 /****** net.lib/SPrintf ******************************************
34 SPrintf -- formatted print to a buffer
37 len = SPrintf(Buffer, FormatString, Arguments...)
38 len = VSPrintf(Buffer, FormatString, ap)
40 ULONG SPrintf(STRPTR, const char *, ...)
41 ULONG VSPrintf(STRPTR, const char *, va_list)
44 Prints to a simple buffer or to a CSource buffer. These functions
45 are similar to C-library sprintf() with RawDoFmt() formatting.
48 Buffer - Pointer to buffer.
49 FormatString - This is a printf()-style format string as defined
50 in exec.library/RawDoFmt().
51 Arguments - as in printf() .
53 Result - Pointer to CSource structure.
56 Number of characters printed.
59 SPrintf(mybuf, "line=%ld, val=%lx\n",
60 __LINE__, very.interesting->value);
63 Function SPrintf() assumes that no print is longer than 1024 chars.
64 It does not check for buffer owerflow (there no way to check, the
65 definition of sprintf misses it).
67 SPrintf strings are truncated to maximum of 1024 chars (including
71 exec.library/RawDoFmt()
73 ******************************************************************************
78 VCSPrintf(struct CSource
*buf
, const char *fmt
, va_list ap
)
80 ULONG start
= buf
->CS_CurChr
;
82 if (buf
->CS_Length
&& buf
->CS_CurChr
< buf
->CS_Length
) {
83 RawDoFmt((STRPTR
)fmt
, ap
, __stuffchar
, buf
);
85 if (buf
->CS_CurChr
== buf
->CS_Length
) {
86 buf
->CS_CurChr
--; /* must NUL terminate */
88 buf
->CS_Buffer
[buf
->CS_CurChr
] = '\0';
90 return buf
->CS_CurChr
- start
;
92 /* A pathological case */
98 CSPrintf(struct CSource
*buf
, const char *fmt
, ...)
104 len
= VCSPrintf(buf
, fmt
, ap
);
110 VSPrintf(char *buf
, const char *fmt
, va_list ap
)
116 cs
.CS_Length
= 1024; /* This is not probably the cleanest way :-) */
118 return VCSPrintf(&cs
, fmt
, ap
);
122 SPrintf(char *buf
, const char *fmt
, ...)
128 len
= VSPrintf(buf
, fmt
, ap
);