Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/i386/libsa/printf.c

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

Archive Download this file

Revision: 2045