From owner-dev-commits-src-branches@freebsd.org Sun Aug 15 21:20:21 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7DE57666AC6; Sun, 15 Aug 2021 21:20:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GnqvT1vNSz4f7f; Sun, 15 Aug 2021 21:20:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2A4D71D3B2; Sun, 15 Aug 2021 21:20:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17FLKLgV028661; Sun, 15 Aug 2021 21:20:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17FLKLTs028655; Sun, 15 Aug 2021 21:20:21 GMT (envelope-from git) Date: Sun, 15 Aug 2021 21:20:21 GMT Message-Id: <202108152120.17FLKLTs028655@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: 2e34e54d4bf5 - stable/12 - getprogname.3: Add an example MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 2e34e54d4bf50258cbda4f14deb4863cf8fcbf65 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2021 21:20:21 -0000 The branch stable/12 has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=2e34e54d4bf50258cbda4f14deb4863cf8fcbf65 commit 2e34e54d4bf50258cbda4f14deb4863cf8fcbf65 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:20:07 +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 +#include + +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