2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2006 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1990,1991 Regents of the University of Michigan.
16 * All rights reserved.
18 * Redistribution and use in source and binary forms are permitted
19 * provided that this notice is preserved and that due credit is given
20 * to the University of Michigan at Ann Arbor. The name of the University
21 * may not be used to endorse or promote products derived from this
22 * software without specific prior written permission. This software
23 * is provided ``as is'' without express or implied warranty.
28 #ifndef HAVE_SETPROCTITLE
32 #include <ac/stdlib.h>
34 #include <ac/setproctitle.h>
35 #include <ac/string.h>
36 #include <ac/stdarg.h>
38 char **Argv; /* pointer to original (main's) argv */
39 int Argc; /* original argc */
42 * takes a printf-style format string (fmt) and up to three parameters (a,b,c)
43 * this clobbers the original argv...
47 void setproctitle( const char *fmt, ... )
49 static char *endargv = (char *)0;
57 buf[sizeof(buf) - 1] = '\0';
58 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
62 if ( endargv == (char *)0 ) {
63 /* set pointer to end of original argv */
64 endargv = Argv[ Argc-1 ] + strlen( Argv[ Argc-1 ] );
66 /* make ps print "([prog name])" */
70 if ( i > endargv - s - 2 ) {
76 while ( s < endargv ) *s++ = ' ';
78 #endif /* NOSETPROCTITLE */