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