Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/getprogname.3
Show All 25 Lines | ||||||||||||
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||||||||||
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||||||||||
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||||||||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||||||||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||||||||
.\" | .\" | |||||||||||
.\" $FreeBSD$ | .\" $FreeBSD$ | |||||||||||
.\" | .\" | |||||||||||
.Dd May 1, 2001 | .Dd April 17, 2021 | |||||||||||
.Dt GETPROGNAME 3 | .Dt GETPROGNAME 3 | |||||||||||
.Os | .Os | |||||||||||
.Sh NAME | .Sh NAME | |||||||||||
.Nm getprogname , | .Nm getprogname , | |||||||||||
.Nm setprogname | .Nm setprogname | |||||||||||
.Nd get or set the program name | .Nd get or set the program name | |||||||||||
.Sh LIBRARY | .Sh LIBRARY | |||||||||||
.Lb libc | .Lb libc | |||||||||||
Show All 36 Lines | ||||||||||||
is not necessary. | is not necessary. | |||||||||||
Programs that desire maximum portability should still call it; | Programs that desire maximum portability should still call it; | |||||||||||
on another operating system, | on another operating system, | |||||||||||
these functions may be implemented in a portability library. | these functions may be implemented in a portability library. | |||||||||||
Calling | Calling | |||||||||||
.Fn setprogname | .Fn setprogname | |||||||||||
allows the aforementioned library to learn the program name without | allows the aforementioned library to learn the program name without | |||||||||||
modifications to the start-up code. | modifications to the start-up code. | |||||||||||
.Sh EXAMPLES | ||||||||||||
The following example presents a simple program, which shows the difference | ||||||||||||
yuripvUnsubmitted Done Inline Actions
yuripv: | ||||||||||||
between | ||||||||||||
.Fn getprogname | ||||||||||||
and | ||||||||||||
.Va "argv[0]" . | ||||||||||||
.Bd -literal -offset indent | ||||||||||||
#include <stdio.h> | ||||||||||||
#include <stdlib.h> | ||||||||||||
int | ||||||||||||
Done Inline Actions
yuripv: | ||||||||||||
main(int argc, char** argv) | ||||||||||||
Done Inline Actions
Sorry, still doesn't look completely right, just trying to follow what style(9) says :) The function type should be on a line by itself preceding the function. The opening brace of the function body should be on a line by itself. static char * function(int a1, int a2, float fl, int a4, struct bar *bar) { yuripv: Sorry, still doesn't look completely right, just trying to follow what style(9) says :)
```… | ||||||||||||
Done Inline ActionsGood catch, sorry for not hassle :) 0mp: Good catch, sorry for not hassle :) | ||||||||||||
{ | ||||||||||||
printf("getprogname(): %s\en", getprogname()); | ||||||||||||
printf("argv[0]: %s\en", argv[0]); | ||||||||||||
return (0); | ||||||||||||
} | ||||||||||||
.Ed | ||||||||||||
Done Inline Actions
yuripv: | ||||||||||||
.Pp | ||||||||||||
When compiled and executed (e.g., with | ||||||||||||
.Ql ./a.out ) | ||||||||||||
the output of the program is going to look like this: | ||||||||||||
.Bd -literal -offset indent | ||||||||||||
getprogname(): a.out | ||||||||||||
argv[0]: ./a.out | ||||||||||||
.Ed | ||||||||||||
.Sh SEE ALSO | .Sh SEE ALSO | |||||||||||
.Xr err 3 , | .Xr err 3 , | |||||||||||
.Xr setproctitle 3 | .Xr setproctitle 3 | |||||||||||
.Sh HISTORY | .Sh HISTORY | |||||||||||
These functions first appeared in | These functions first appeared in | |||||||||||
.Nx 1.6 , | .Nx 1.6 , | |||||||||||
and made their way into | and made their way into | |||||||||||
.Fx 4.4 . | .Fx 4.4 . |