Date: Sun, 15 Aug 2021 21:19:42 GMT From: Mateusz Piotrowski <0mp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 5cdee2441ed9 - stable/13 - getprogname.3: Add an example Message-ID: <202108152119.17FLJgnv020744@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=5cdee2441ed9cffca7462c88205e70bba61a4d6b commit 5cdee2441ed9cffca7462c88205e70bba61a4d6b Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2021-04-17 21:26:54 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2021-08-15 21:19:09 +0000 getprogname.3: Add an example It shows the difference between getprogname() and argv[0]. Reviewed by: yuripv Approved by: yuripv (src) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D27204 (cherry picked from commit 1ffdcdadf61423dd02ddad82fc4f3f6c39090c8c) --- lib/libc/gen/getprogname.3 | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/getprogname.3 b/lib/libc/gen/getprogname.3 index 53d39a60526b..f43a7b8c6b69 100644 --- a/lib/libc/gen/getprogname.3 +++ b/lib/libc/gen/getprogname.3 @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 1, 2001 +.Dd April 18, 2021 .Dt GETPROGNAME 3 .Os .Sh NAME @@ -84,6 +84,32 @@ Calling .Fn setprogname allows the aforementioned library to learn the program name without modifications to the start-up code. +.Sh EXAMPLES +The following example presents a simple program, which shows the difference +between +.Fn getprogname +and +.Va "argv[0]" . +.Bd -literal -offset indent +#include <stdio.h> +#include <stdlib.h> + +int +main(int argc, char** argv) +{ + printf("getprogname(): %s\en", getprogname()); + printf("argv[0]: %s\en", argv[0]); + return (0); +} +.Ed +.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 .Xr err 3 , .Xr setproctitle 3
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202108152119.17FLJgnv020744>