ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/ihost/libukcprog/strf.c
Revision: 1.1
Committed: Fri Mar 8 14:37:29 2002 UTC (22 years, 8 months ago) by tdb
Content type: text/plain
Branch: MAIN
CVS Tags: IHOST_1_5_3, IHOST_1_5_2, IHOST_1_5_1, IHOST_1_5, IHOST_1_0_RC1
Log Message:
I'm not usually up for putting third party sources in here, but in this
case I'll make an exception. This is ukcprog, a set of useful C functions
which the ihost plugins Pete's writing uses. It's got a pretty free license
too. I've munged the Makefile around, as all it needs to do now is make the
library, not install anything. The idea is to statically compile the other
programs against this library, making the final binary independent of this
code etc.

File Contents

# User Rev Content
1 tdb 1.1 /* strf.c -- formatted strings, storage allocated from malloc */
2    
3     /* Copyright 1992 Godfrey Paul, University of Kent at Canterbury.
4     *
5     * You can do what you like with this source code as long as
6     * you don't try to make money out of it and you include an
7     * unaltered copy of this message (including the copyright).
8     */
9    
10     char ukcprog_strf_sccsid[] = "$Id: strf.c,v 1.7 1993/05/30 18:15:16 gjap Exp $ UKC";
11    
12     #ifdef __STDC__
13     #include <stdarg.h>
14     #else
15     #include <varargs.h>
16     #endif
17    
18     #include <stdio.h>
19     #include <stdlib.h>
20    
21     #include "ukcprog.h"
22    
23    
24     #ifdef __STDC__
25     char *
26     strf(const char *fmt, ...)
27     {
28    
29     #else /* !__STDC__ */
30     char *
31     strf(va_alist)
32     va_dcl
33     {
34     char *fmt;
35     #endif /* !__STDC__ */
36     va_list args;
37     char buffer[100];
38     char *s;
39    
40     #ifdef __STDC__
41     va_start(args, fmt);
42     #else
43     va_start(args);
44     fmt = va_arg(args, char *);
45     #endif
46    
47     s = formf(buffer, sizeof(buffer), fmt, args);
48    
49     va_end(args);
50    
51     if (s == buffer) /* not obtained from malloc */
52     s = strsave(s);
53    
54     return s;
55     }