<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://computers.huntertur.net/index.php?action=history&amp;feed=atom&amp;title=BSD_progname_%28getprogname%2C_setprogname%29</id>
	<title>BSD progname (getprogname, setprogname) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://computers.huntertur.net/index.php?action=history&amp;feed=atom&amp;title=BSD_progname_%28getprogname%2C_setprogname%29"/>
	<link rel="alternate" type="text/html" href="https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;action=history"/>
	<updated>2026-06-02T20:29:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;diff=701&amp;oldid=prev</id>
		<title>Huntertur: /* How NetBSD does it */ Remove incorrect statement about this not being mentioned in the man page</title>
		<link rel="alternate" type="text/html" href="https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;diff=701&amp;oldid=prev"/>
		<updated>2023-06-26T04:00:56Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;How NetBSD does it: &lt;/span&gt; Remove incorrect statement about this not being mentioned in the man page&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:00, 26 June 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; simply returns &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/getprogname.c?rev=1.5&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; simply returns &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/getprogname.c?rev=1.5&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; has functionality for setting &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;, including using &amp;lt;code&amp;gt;strrchr&amp;lt;/code&amp;gt; to get the location of the last occurrence of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. This is to normalize a program run from &amp;lt;code&amp;gt;./blah/bin/hello&amp;lt;/code&amp;gt; to just &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;, which is actually useful added value&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; that isn&#039;t mentioned in the man page&lt;/del&gt;. However, unless the source file is modified, this functionality is never used, since a constant defined in the file makes the function a no-op.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setprogname.c?rev=1.3&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt; &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; gets set in &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; using the same rule that the &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; would have followed, but with a manual search, and with an extra rule that sets &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; to an empty string (pointer to &amp;lt;code&amp;gt;\0&amp;lt;/code&amp;gt;) instead of &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; if the program name really is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, making the point in the man page about &amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; possibly returning &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; moot.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/csu/common/crt0-common.c?rev=1.27&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; has functionality for setting &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;, including using &amp;lt;code&amp;gt;strrchr&amp;lt;/code&amp;gt; to get the location of the last occurrence of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. This is to normalize a program run from &amp;lt;code&amp;gt;./blah/bin/hello&amp;lt;/code&amp;gt; to just &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;, which is actually useful added value. However, unless the source file is modified, this functionality is never used, since a constant defined in the file makes the function a no-op.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setprogname.c?rev=1.3&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt; &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; gets set in &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; using the same rule that the &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; would have followed, but with a manual search, and with an extra rule that sets &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; to an empty string (pointer to &amp;lt;code&amp;gt;\0&amp;lt;/code&amp;gt;) instead of &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; if the program name really is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, making the point in the man page about &amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; possibly returning &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; moot.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/csu/common/crt0-common.c?rev=1.27&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Quick test ==&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Quick test ==&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;!-- diff cache key computers_wiki-mediawiki-:diff:1.41:old-700:rev-701:wikidiff2=table:1.14.1:bc2a06be --&gt;
&lt;/table&gt;</summary>
		<author><name>Huntertur</name></author>
	</entry>
	<entry>
		<id>https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;diff=700&amp;oldid=prev</id>
		<title>Huntertur: Remove duplicate periods</title>
		<link rel="alternate" type="text/html" href="https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;diff=700&amp;oldid=prev"/>
		<updated>2023-06-23T21:42:07Z</updated>

		<summary type="html">&lt;p&gt;Remove duplicate periods&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 21:42, 23 June 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Initial thoughts ==&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Initial thoughts ==&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The man page says the functions appeared in NetBSD 1.6 and seems to suggest that they store &amp;lt;code&amp;gt;argv[0]&amp;lt;/code&amp;gt; verbatim, even if it is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, and that &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; is useless because &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; calls it during C runtime initialization and because the program name is a write-once value.&amp;lt;ref&amp;gt;https://man.netbsd.org/NetBSD-9.3-STABLE/getprogname.3&amp;lt;/ref&amp;gt; The functions then found their way into FreeBSD 4.4.&amp;lt;ref&amp;gt;https://man.freebsd.org/cgi/man.cgi?query=getprogname&amp;amp;apropos=0&amp;amp;sektion=3&amp;amp;manpath=FreeBSD+13.2-RELEASE+and+Ports&amp;amp;arch=default&amp;amp;format=html&amp;lt;/ref&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/del&gt; Unlike NetBSD and FreeBSD, OpenBSD states that the functions originated as a wrapper for the 4.4BSD &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; interface, first appearing in OpenBSD 5.4.&amp;lt;ref&amp;gt;https://man.openbsd.org/OpenBSD-7.3/getprogname.3&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The man page says the functions appeared in NetBSD 1.6 and seems to suggest that they store &amp;lt;code&amp;gt;argv[0]&amp;lt;/code&amp;gt; verbatim, even if it is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, and that &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; is useless because &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; calls it during C runtime initialization and because the program name is a write-once value.&amp;lt;ref&amp;gt;https://man.netbsd.org/NetBSD-9.3-STABLE/getprogname.3&amp;lt;/ref&amp;gt; The functions then found their way into FreeBSD 4.4.&amp;lt;ref&amp;gt;https://man.freebsd.org/cgi/man.cgi?query=getprogname&amp;amp;apropos=0&amp;amp;sektion=3&amp;amp;manpath=FreeBSD+13.2-RELEASE+and+Ports&amp;amp;arch=default&amp;amp;format=html&amp;lt;/ref&amp;gt; Unlike NetBSD and FreeBSD, OpenBSD states that the functions originated as a wrapper for the 4.4BSD &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; interface, first appearing in OpenBSD 5.4.&amp;lt;ref&amp;gt;https://man.openbsd.org/OpenBSD-7.3/getprogname.3&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== How NetBSD does it ==&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== How NetBSD does it ==&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; simply returns &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/getprogname.c?rev=1.5&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; simply returns &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/getprogname.c?rev=1.5&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; has functionality for setting &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;, including using &amp;lt;code&amp;gt;strrchr&amp;lt;/code&amp;gt; to get the location of the last occurrence of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. This is to normalize a program run from &amp;lt;code&amp;gt;./blah/bin/hello&amp;lt;/code&amp;gt; to just &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;, which is actually useful added value that isn&#039;t mentioned in the man page. However, unless the source file is modified, this functionality is never used, since a constant defined in the file makes the function a no-op.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setprogname.c?rev=1.3&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/del&gt; &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; gets set in &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; using the same rule that the &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; would have followed, but with a manual search, and with an extra rule that sets &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; to an empty string (pointer to &amp;lt;code&amp;gt;\0&amp;lt;/code&amp;gt;) instead of &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; if the program name really is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, making the point in the man page about &amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; possibly returning &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; moot.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/csu/common/crt0-common.c?rev=1.27&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; has functionality for setting &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;, including using &amp;lt;code&amp;gt;strrchr&amp;lt;/code&amp;gt; to get the location of the last occurrence of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. This is to normalize a program run from &amp;lt;code&amp;gt;./blah/bin/hello&amp;lt;/code&amp;gt; to just &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;, which is actually useful added value that isn&#039;t mentioned in the man page. However, unless the source file is modified, this functionality is never used, since a constant defined in the file makes the function a no-op.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setprogname.c?rev=1.3&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt; &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; gets set in &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; using the same rule that the &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; would have followed, but with a manual search, and with an extra rule that sets &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; to an empty string (pointer to &amp;lt;code&amp;gt;\0&amp;lt;/code&amp;gt;) instead of &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; if the program name really is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, making the point in the man page about &amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; possibly returning &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; moot.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/csu/common/crt0-common.c?rev=1.27&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Quick test ==&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Quick test ==&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Huntertur</name></author>
	</entry>
	<entry>
		<id>https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;diff=698&amp;oldid=prev</id>
		<title>Huntertur: Add example code</title>
		<link rel="alternate" type="text/html" href="https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;diff=698&amp;oldid=prev"/>
		<updated>2023-06-23T04:39:35Z</updated>

		<summary type="html">&lt;p&gt;Add example code&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:39, 23 June 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; has functionality for setting &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;, including using &amp;lt;code&amp;gt;strrchr&amp;lt;/code&amp;gt; to get the location of the last occurrence of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. This is to normalize a program run from &amp;lt;code&amp;gt;./blah/bin/hello&amp;lt;/code&amp;gt; to just &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;, which is actually useful added value that isn&#039;t mentioned in the man page. However, unless the source file is modified, this functionality is never used, since a constant defined in the file makes the function a no-op.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setprogname.c?rev=1.3&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;. &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; gets set in &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; using the same rule that the &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; would have followed, but with a manual search, and with an extra rule that sets &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; to an empty string (pointer to &amp;lt;code&amp;gt;\0&amp;lt;/code&amp;gt;) instead of &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; if the program name really is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, making the point in the man page about &amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; possibly returning &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; moot.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/csu/common/crt0-common.c?rev=1.27&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; has functionality for setting &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;, including using &amp;lt;code&amp;gt;strrchr&amp;lt;/code&amp;gt; to get the location of the last occurrence of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. This is to normalize a program run from &amp;lt;code&amp;gt;./blah/bin/hello&amp;lt;/code&amp;gt; to just &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;, which is actually useful added value that isn&#039;t mentioned in the man page. However, unless the source file is modified, this functionality is never used, since a constant defined in the file makes the function a no-op.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setprogname.c?rev=1.3&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;. &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; gets set in &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; using the same rule that the &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; would have followed, but with a manual search, and with an extra rule that sets &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; to an empty string (pointer to &amp;lt;code&amp;gt;\0&amp;lt;/code&amp;gt;) instead of &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; if the program name really is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, making the point in the man page about &amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; possibly returning &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; moot.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/csu/common/crt0-common.c?rev=1.27&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Quick test ==&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Compile this and run it from different paths.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&quot;c&quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int main(int argc, char *argv[])&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    printf(&quot;progname is %s\n&quot;, getprogname());&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    printf(&quot;argv[0] is %s\n&quot;, argv[0]);&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    return EXIT_SUCCESS;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== References ==&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== References ==&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Huntertur</name></author>
	</entry>
	<entry>
		<id>https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;diff=695&amp;oldid=prev</id>
		<title>Huntertur: Create page</title>
		<link rel="alternate" type="text/html" href="https://computers.huntertur.net/index.php?title=BSD_progname_(getprogname,_setprogname)&amp;diff=695&amp;oldid=prev"/>
		<updated>2023-06-23T04:31:33Z</updated>

		<summary type="html">&lt;p&gt;Create page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The &amp;#039;&amp;#039;&amp;#039;BSD __progname interface&amp;#039;&amp;#039;&amp;#039;, composed of (&amp;#039;&amp;#039;&amp;#039;getprogname&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;setprogname&amp;#039;&amp;#039;&amp;#039;), stood out to me while reading the NetBSD source code. Why have functions for &amp;lt;code&amp;gt;argv[0]&amp;lt;/code&amp;gt;? It turns out it does a little more.&lt;br /&gt;
&lt;br /&gt;
== Initial thoughts ==&lt;br /&gt;
&lt;br /&gt;
The man page says the functions appeared in NetBSD 1.6 and seems to suggest that they store &amp;lt;code&amp;gt;argv[0]&amp;lt;/code&amp;gt; verbatim, even if it is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, and that &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; is useless because &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; calls it during C runtime initialization and because the program name is a write-once value.&amp;lt;ref&amp;gt;https://man.netbsd.org/NetBSD-9.3-STABLE/getprogname.3&amp;lt;/ref&amp;gt; The functions then found their way into FreeBSD 4.4.&amp;lt;ref&amp;gt;https://man.freebsd.org/cgi/man.cgi?query=getprogname&amp;amp;apropos=0&amp;amp;sektion=3&amp;amp;manpath=FreeBSD+13.2-RELEASE+and+Ports&amp;amp;arch=default&amp;amp;format=html&amp;lt;/ref&amp;gt;. Unlike NetBSD and FreeBSD, OpenBSD states that the functions originated as a wrapper for the 4.4BSD &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; interface, first appearing in OpenBSD 5.4.&amp;lt;ref&amp;gt;https://man.openbsd.org/OpenBSD-7.3/getprogname.3&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How NetBSD does it ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; simply returns &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/getprogname.c?rev=1.5&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; has functionality for setting &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt;, including using &amp;lt;code&amp;gt;strrchr&amp;lt;/code&amp;gt; to get the location of the last occurrence of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. This is to normalize a program run from &amp;lt;code&amp;gt;./blah/bin/hello&amp;lt;/code&amp;gt; to just &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;, which is actually useful added value that isn&amp;#039;t mentioned in the man page. However, unless the source file is modified, this functionality is never used, since a constant defined in the file makes the function a no-op.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setprogname.c?rev=1.3&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;. &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; gets set in &amp;lt;code&amp;gt;crt0&amp;lt;/code&amp;gt; using the same rule that the &amp;lt;code&amp;gt;setprogname&amp;lt;/code&amp;gt; would have followed, but with a manual search, and with an extra rule that sets &amp;lt;code&amp;gt;__progname&amp;lt;/code&amp;gt; to an empty string (pointer to &amp;lt;code&amp;gt;\0&amp;lt;/code&amp;gt;) instead of &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; if the program name really is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;, making the point in the man page about &amp;lt;code&amp;gt;getprogname&amp;lt;/code&amp;gt; possibly returning &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; moot.&amp;lt;ref&amp;gt;http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/csu/common/crt0-common.c?rev=1.27&amp;amp;content-type=text/x-cvsweb-markup&amp;amp;only_with_tag=MAIN&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Unix]]&lt;/div&gt;</summary>
		<author><name>Huntertur</name></author>
	</entry>
</feed>