3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990,1991 Regents of the University of Michigan.
10 * Redistribution and use in source and binary forms are permitted
11 * provided that this notice is preserved and that due credit is given
12 * to the University of Michigan at Ann Arbor. The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission. This software
15 * is provided ``as is'' without express or implied warranty.
20 #ifndef HAVE_SETPROCTITLE
24 #include <ac/stdlib.h>
26 #include <ac/setproctitle.h>
27 #include <ac/string.h>
28 #include <ac/stdarg.h>
30 char **Argv; /* pointer to original (main's) argv */
31 int Argc; /* original argc */
34 * takes a printf-style format string (fmt) and up to three parameters (a,b,c)
35 * this clobbers the original argv...
39 void setproctitle( const char *fmt, ... )
41 static char *endargv = (char *)0;
49 buf[sizeof(buf) - 1] = '\0';
50 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
54 if ( endargv == (char *)0 ) {
55 /* set pointer to end of original argv */
56 endargv = Argv[ Argc-1 ] + strlen( Argv[ Argc-1 ] );
58 /* make ps print "([prog name])" */
62 if ( i > endargv - s - 2 ) {
68 while ( s < endargv ) *s++ = ' ';
70 #endif /* NOSETPROCTITLE */