]> git.saurik.com Git - apple/bootx.git/blame - bootx.tproj/libclite.subproj/sprintf.c
BootX-81.tar.gz
[apple/bootx.git] / bootx.tproj / libclite.subproj / sprintf.c
CommitLineData
04fee52e
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
8be739c0
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
04fee52e 11 *
8be739c0
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
04fee52e
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
8be739c0
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
04fee52e
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright 1993 NeXT, Inc.
24 * All rights reserved.
25 */
26/*
27 * sprintf.c - sprintf and helper functions.
28 *
366defd1 29 * Copyright (c) 1998-2002 Apple Computer, Inc.
04fee52e
A
30 *
31 * DRI: Josh de Cesare
32 */
33
34#include <libclite.h>
35
36struct putc_info {
37 char *str;
38 char *last_str;
39};
40
41static void
42sputc(
43 int c,
44 struct putc_info *pi
45)
46{
47 if (pi->last_str)
48 if (pi->str == pi->last_str) {
49 *(pi->str) = '\0';
50 return;
51 }
52 *(pi->str)++ = c;
53}
54
55/*VARARGS1*/
56int sprintf(char *str, const char *fmt, ...)
57{
58 va_list ap;
59 struct putc_info pi;
60
61 va_start(ap, fmt);
62 pi.str = str;
63 pi.last_str = 0;
8be739c0 64 prf(fmt, (unsigned int *)ap, (int (*)(int ch))sputc, &pi);
04fee52e
A
65 *pi.str = '\0';
66 va_end(ap);
67 return 0;
68}
69
70/*VARARGS1*/
71int slvprintf(char *str, int len, const char *fmt, va_list ap )
72{
73 struct putc_info pi;
74 pi.str = str;
75 pi.last_str = str + len - 1;
8be739c0 76 prf(fmt, (unsigned int *)ap, (int (*)(int ch))sputc, &pi);
04fee52e
A
77 *pi.str = '\0';
78 return (pi.str - str);
79}