xref: /minix3/lib/libc/gen/getprogname.3 (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1*f14fb602SLionel Sambuc.\" $NetBSD: getprogname.3,v 1.8 2011/05/21 19:06:44 dholland Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 2001 Christopher G. Demetriou
42fe8fb19SBen Gras.\" All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
72fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
82fe8fb19SBen Gras.\" are met:
92fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
102fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
112fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
122fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
132fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
142fe8fb19SBen Gras.\" 3. All advertising materials mentioning features or use of this software
152fe8fb19SBen Gras.\"    must display the following acknowledgement:
162fe8fb19SBen Gras.\"          This product includes software developed for the
172fe8fb19SBen Gras.\"          NetBSD Project.  See http://www.NetBSD.org/ for
182fe8fb19SBen Gras.\"          information about NetBSD.
192fe8fb19SBen Gras.\" 4. The name of the author may not be used to endorse or promote products
202fe8fb19SBen Gras.\"    derived from this software without specific prior written permission.
212fe8fb19SBen Gras.\"
222fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
232fe8fb19SBen Gras.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
242fe8fb19SBen Gras.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
252fe8fb19SBen Gras.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
262fe8fb19SBen Gras.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
272fe8fb19SBen Gras.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
282fe8fb19SBen Gras.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
292fe8fb19SBen Gras.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
302fe8fb19SBen Gras.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
312fe8fb19SBen Gras.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
322fe8fb19SBen Gras.\"
332fe8fb19SBen Gras.\" <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
342fe8fb19SBen Gras.\"
35*f14fb602SLionel Sambuc.Dd May 21, 2011
362fe8fb19SBen Gras.Dt GETPROGNAME 3
372fe8fb19SBen Gras.Os
382fe8fb19SBen Gras.Sh NAME
392fe8fb19SBen Gras.Nm getprogname ,
402fe8fb19SBen Gras.Nm setprogname
412fe8fb19SBen Gras.Nd get/set the name of the current program
422fe8fb19SBen Gras.Sh LIBRARY
432fe8fb19SBen Gras.Lb libc
442fe8fb19SBen Gras.Sh SYNOPSIS
452fe8fb19SBen Gras.In stdlib.h
462fe8fb19SBen Gras.Ft const char *
472fe8fb19SBen Gras.Fn getprogname "void"
482fe8fb19SBen Gras.Ft void
492fe8fb19SBen Gras.Fn setprogname "const char *name"
502fe8fb19SBen Gras.Sh DESCRIPTION
512fe8fb19SBen GrasThese utility functions get and set the current program's name
522fe8fb19SBen Grasas used by various error-reporting functions.
532fe8fb19SBen Gras.Pp
542fe8fb19SBen Gras.Fn getprogname
552fe8fb19SBen Grasreturns the name of the current program.
562fe8fb19SBen GrasThis function is typically useful when generating error messages
572fe8fb19SBen Grasor other diagnostic output.
582fe8fb19SBen GrasIf the program name has not been set,
592fe8fb19SBen Gras.Fn getprogname
602fe8fb19SBen Graswill return
612fe8fb19SBen Gras.Dv NULL .
622fe8fb19SBen Gras.Pp
632fe8fb19SBen Gras.Fn setprogname
642fe8fb19SBen Grassets the name of the current program to be the last pathname
652fe8fb19SBen Grascomponent of the
662fe8fb19SBen Gras.Fa name
672fe8fb19SBen Grasargument.
682fe8fb19SBen GrasIt should be invoked at the start of the program, using the
692fe8fb19SBen Gras.Fa argv[0]
702fe8fb19SBen Graspassed into the program's
712fe8fb19SBen Gras.Fn main
722fe8fb19SBen Grasfunction.
732fe8fb19SBen GrasA pointer into the string pointed to by the
742fe8fb19SBen Gras.Fa name
752fe8fb19SBen Grasargument is kept as the program name.
762fe8fb19SBen GrasTherefore, the string pointed to by
772fe8fb19SBen Gras.Fa name
782fe8fb19SBen Grasshould not be modified during the rest of the program's operation.
792fe8fb19SBen Gras.Pp
802fe8fb19SBen GrasA program's name can only be set once, and in
812fe8fb19SBen Gras.Nx
822fe8fb19SBen Grasthat is actually
832fe8fb19SBen Grasdone by program start-up code that is run before
842fe8fb19SBen Gras.Fn main
852fe8fb19SBen Grasis called.
862fe8fb19SBen GrasTherefore, in
872fe8fb19SBen Gras.Nx ,
882fe8fb19SBen Grascalling
892fe8fb19SBen Gras.Fn setprogname
90*f14fb602SLionel Sambucexplicitly has no effect.
91*f14fb602SLionel SambucHowever, portable programs that wish to use
92*f14fb602SLionel Sambuc.Fn getprogname
93*f14fb602SLionel Sambucshould call
94*f14fb602SLionel Sambuc.Fn setprogname
952fe8fb19SBen Grasfrom
96*f14fb602SLionel Sambuc.Fn main .
97*f14fb602SLionel SambucOn operating systems where
982fe8fb19SBen Gras.Fn getprogname
992fe8fb19SBen Grasand
1002fe8fb19SBen Gras.Fn setprogname
101*f14fb602SLionel Sambucare implemented via a portability library, this call is needed to
102*f14fb602SLionel Sambucmake the name available.
1032fe8fb19SBen Gras.Sh SEE ALSO
1042fe8fb19SBen Gras.Xr err 3 ,
1052fe8fb19SBen Gras.Xr setproctitle 3
1062fe8fb19SBen Gras.Sh HISTORY
1072fe8fb19SBen GrasThe
1082fe8fb19SBen Gras.Nm getprogname
1092fe8fb19SBen Grasand
1102fe8fb19SBen Gras.Nm setprogname
1112fe8fb19SBen Grasfunction calls appeared in
1122fe8fb19SBen Gras.Nx 1.6 .
1132fe8fb19SBen Gras.Sh RESTRICTIONS
1142fe8fb19SBen GrasThe string returned by
1152fe8fb19SBen Gras.Fn getprogname
1162fe8fb19SBen Grasis supplied by the invoking process and should not be trusted by
1172fe8fb19SBen Grassetuid or setgid programs.
118