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