]> git.sur5r.net Git - openldap/blob - clients/gopher/setproctitle.c
added ber_print_error() and renamed lber_bprint into ber_ namespace.
[openldap] / clients / gopher / setproctitle.c
1 /*
2  * Copyright (c) 1990,1991 Regents of the University of Michigan.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12
13 #include "portable.h"
14
15 char    **Argv;         /* pointer to original (main's) argv */
16 int     Argc;           /* original argc */
17
18 /*
19  * takes a printf-style format string (fmt) and up to three parameters (a,b,c)
20  * this clobbers the original argv...
21  */
22
23 /* VARARGS */
24 setproctitle( fmt, a, b, c )
25 char *fmt;
26 char *a, *b, *c;
27 {
28         static char *endargv = (char *)0;
29         char    *s;
30         int             i;
31         char    buf[ 1024 ];
32
33         if ( endargv == (char *)0 ) {
34                 /* set pointer to end of original argv */
35                 endargv = Argv[ Argc-1 ] + strlen( Argv[ Argc-1 ] );
36         }
37         sprintf( buf, fmt, a, b, c );
38         /* make ps print "([prog name])" */
39         s = Argv[0];
40         *s++ = '-';
41         i = strlen( buf );
42         if ( i > endargv - s - 2 ) {
43                 i = endargv - s - 2;
44                 buf[ i ] = '\0';
45         }
46         strcpy( s, buf );
47         s += i;
48         while ( s < endargv ) *s++ = ' ';
49 }