]> git.sur5r.net Git - openldap/blob - libraries/liblutil/setproctitle.c
Axe <varargs.h> support. Assume STDC C translator is available
[openldap] / libraries / liblutil / setproctitle.c
1 #include "portable.h"
2
3 #ifndef HAVE_SETPROCTITLE
4
5 #include <stdio.h>
6
7 #include <ac/stdlib.h>
8
9 #include <ac/setproctitle.h>
10 #include <ac/string.h>
11 #include <ac/stdarg.h>
12
13 /*
14  * Copyright (c) 1990,1991 Regents of the University of Michigan.
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms are permitted
18  * provided that this notice is preserved and that due credit is given
19  * to the University of Michigan at Ann Arbor. The name of the University
20  * may not be used to endorse or promote products derived from this
21  * software without specific prior written permission. This software
22  * is provided ``as is'' without express or implied warranty.
23  */
24
25 char    **Argv;         /* pointer to original (main's) argv */
26 int     Argc;           /* original argc */
27
28 /*
29  * takes a printf-style format string (fmt) and up to three parameters (a,b,c)
30  * this clobbers the original argv...
31  */
32
33 /* VARARGS */
34 void setproctitle( const char *fmt, ... )
35 {
36         static char *endargv = (char *)0;
37         char    *s;
38         int             i;
39         char    buf[ 1024 ];
40         va_list ap;
41
42         va_start(ap, fmt);
43
44 #ifdef HAVE_VSNPRINTF
45         buf[sizeof(buf) - 1] = '\0';
46         vsnprintf( buf, sizeof(buf)-1, fmt, ap );
47 #elif HAVE_VPRINTF
48         vsprintf( buf, fmt, ap ); /* hope it's not too long */
49 #else
50         /* use doprnt() */
51         chokeme = "choke me!  I don't have a doprnt() manual handy";
52 #endif
53
54         va_end(ap);
55
56         if ( endargv == (char *)0 ) {
57                 /* set pointer to end of original argv */
58                 endargv = Argv[ Argc-1 ] + strlen( Argv[ Argc-1 ] );
59         }
60         /* make ps print "([prog name])" */
61         s = Argv[0];
62         *s++ = '-';
63         i = strlen( buf );
64         if ( i > endargv - s - 2 ) {
65                 i = endargv - s - 2;
66                 buf[ i ] = '\0';
67         }
68         strcpy( s, buf );
69         s += i;
70         while ( s < endargv ) *s++ = ' ';
71 }
72 #endif /* NOSETPROCTITLE */