]> git.sur5r.net Git - openldap/blob - clients/gopher/setproctitle.c
Initial revision
[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 char    **Argv;         /* pointer to original (main's) argv */
14 int     Argc;           /* original argc */
15
16 /*
17  * takes a printf-style format string (fmt) and up to three parameters (a,b,c)
18  * this clobbers the original argv...
19  */
20
21 /* VARARGS */
22 setproctitle( fmt, a, b, c )
23 char *fmt;
24 {
25         static char *endargv = (char *)0;
26         char    *s;
27         int             i;
28         char    buf[ 1024 ];
29
30         if ( endargv == (char *)0 ) {
31                 /* set pointer to end of original argv */
32                 endargv = Argv[ Argc-1 ] + strlen( Argv[ Argc-1 ] );
33         }
34         sprintf( buf, fmt, a, b, c );
35         /* make ps print "([prog name])" */
36         s = Argv[0];
37         *s++ = '-';
38         i = strlen( buf );
39         if ( i > endargv - s - 2 ) {
40                 i = endargv - s - 2;
41                 buf[ i ] = '\0';
42         }
43         strcpy( s, buf );
44         s += i;
45         while ( s < endargv ) *s++ = ' ';
46 }