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