Chameleon

Chameleon Svn Source Tree

Root/branches/chucko/i386/libsa/printf.c

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
31struct putc_info //Azi: exists on console.c & gui.c
32{
33char * str;
34char * last_str;
35};
36
37static int
38sputc(int c, struct putc_info * pi) //Azi: same as above
39{
40if (pi->last_str)
41{
42if (pi->str == pi->last_str)
43{
44*(pi->str) = '\0';
45return 0;
46}
47}
48*(pi->str)++ = c;
49return c;
50}
51
52/*VARARGS1*/
53/* now slprintf() return the length of the string as in man sprintf()*/
54int sprintf(char * str, const char * fmt, ...)
55{
56va_list ap;
57struct putc_info pi;
58
59va_start(ap, fmt);
60pi.str = str;
61pi.last_str = 0;
62prf(fmt, ap, sputc, &pi);
63*pi.str = '\0';
64va_end(ap);
65return (pi.str - str);
66}
67
68/*VARARGS1*/
69int snprintf(char * str, size_t size, const char * fmt, ...)
70{
71va_list ap;
72struct putc_info pi;
73
74va_start(ap, fmt);
75pi.str = str;
76pi.last_str = str + size - 1;
77prf(fmt, ap, sputc, &pi);
78*pi.str = '\0';
79va_end(ap);
80return (pi.str - str);
81}
82
83/*VARARGS1*/
84int slvprintf(char * str, int len, const char * fmt, va_list ap)
85{
86struct putc_info pi;
87pi.str = str;
88pi.last_str = str + len - 1;
89prf(fmt, ap, sputc, &pi);
90*pi.str = '\0';
91return (pi.str - str);
92}
93

Archive Download this file

Revision: 2337