1*46635b74Sguenther.\" $OpenBSD: getprogname.3,v 1.6 2023/02/22 06:31:51 guenther Exp $ 2c88a5da8Sajacoutot.\" 3c88a5da8Sajacoutot.\" Copyright (c) 2001 Christopher G. Demetriou 4c88a5da8Sajacoutot.\" All rights reserved. 5c88a5da8Sajacoutot.\" 6c88a5da8Sajacoutot.\" Redistribution and use in source and binary forms, with or without 7c88a5da8Sajacoutot.\" modification, are permitted provided that the following conditions 8c88a5da8Sajacoutot.\" are met: 9c88a5da8Sajacoutot.\" 1. Redistributions of source code must retain the above copyright 10c88a5da8Sajacoutot.\" notice, this list of conditions and the following disclaimer. 11c88a5da8Sajacoutot.\" 2. Redistributions in binary form must reproduce the above copyright 12c88a5da8Sajacoutot.\" notice, this list of conditions and the following disclaimer in the 13c88a5da8Sajacoutot.\" documentation and/or other materials provided with the distribution. 14c88a5da8Sajacoutot.\" 3. All advertising materials mentioning features or use of this software 15c88a5da8Sajacoutot.\" must display the following acknowledgement: 16c88a5da8Sajacoutot.\" This product includes software developed for the 17c88a5da8Sajacoutot.\" NetBSD Project. See http://www.NetBSD.org/ for 18c88a5da8Sajacoutot.\" information about NetBSD. 19c88a5da8Sajacoutot.\" 4. The name of the author may not be used to endorse or promote products 20c88a5da8Sajacoutot.\" derived from this software without specific prior written permission. 21c88a5da8Sajacoutot.\" 22c88a5da8Sajacoutot.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23c88a5da8Sajacoutot.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24c88a5da8Sajacoutot.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25c88a5da8Sajacoutot.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26c88a5da8Sajacoutot.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27c88a5da8Sajacoutot.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28c88a5da8Sajacoutot.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29c88a5da8Sajacoutot.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30c88a5da8Sajacoutot.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31c88a5da8Sajacoutot.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32c88a5da8Sajacoutot.\" 33*46635b74Sguenther.Dd $Mdocdate: February 22 2023 $ 34c88a5da8Sajacoutot.Dt GETPROGNAME 3 35c88a5da8Sajacoutot.Os 36c88a5da8Sajacoutot.Sh NAME 37c88a5da8Sajacoutot.Nm getprogname , 38c88a5da8Sajacoutot.Nm setprogname 39*46635b74Sguenther.Nd get or set the name of the current program 40c88a5da8Sajacoutot.Sh SYNOPSIS 41c88a5da8Sajacoutot.In stdlib.h 42c88a5da8Sajacoutot.Ft const char * 43c88a5da8Sajacoutot.Fn getprogname "void" 44c88a5da8Sajacoutot.Ft void 45c88a5da8Sajacoutot.Fn setprogname "const char *name" 46c88a5da8Sajacoutot.Sh DESCRIPTION 47c88a5da8SajacoutotThese utility functions get and set the current program's name 48c88a5da8Sajacoutotas used by various error-reporting functions. 49c88a5da8Sajacoutot.Pp 50c88a5da8Sajacoutot.Fn getprogname 51c88a5da8Sajacoutotreturns the name of the current program. 52c88a5da8SajacoutotThis function is typically useful when generating error messages 53c88a5da8Sajacoutotor other diagnostic output. 54c88a5da8Sajacoutot.Pp 55c88a5da8SajacoutotThe 56c88a5da8Sajacoutot.Fn setprogname 572a01c780Stedufunction sets the name of the program to be the last path component of the 584f07dcdaSschwarze.Fa name 59c88a5da8Sajacoutotargument. 602a01c780SteduInternally, only the pointer to the given string is kept as the program name, 612a01c780Steduso it should not be modified and the storage for the string must remain valid 622a01c780Stedufor the rest of the program's lifetime. 63c88a5da8Sajacoutot.Sh SEE ALSO 64c88a5da8Sajacoutot.Xr err 3 , 65c88a5da8Sajacoutot.Xr setproctitle 3 66c88a5da8Sajacoutot.Sh HISTORY 67c88a5da8SajacoutotThe 684f07dcdaSschwarze.Fn getprogname 69c88a5da8Sajacoutotand 704f07dcdaSschwarze.Fn setprogname 719733c316Sjmcfunctions first appeared in 726e792a6eSderaadt.Ox 5.4 736e792a6eSderaadtas function-based wrappers around the 746e792a6eSderaadt.Bx 4.4 756e792a6eSderaadt.Va __progname 766e792a6eSderaadtinterface. 779733c316Sjmc.Sh CAVEATS 78c88a5da8SajacoutotThe string returned by 79c88a5da8Sajacoutot.Fn getprogname 80c88a5da8Sajacoutotis supplied by the invoking process and should not be trusted by 81c88a5da8Sajacoutotsetuid or setgid programs. 82