Move __progname out of libc_init_common.cpp.
And put the trivial getter and setter functions with it.
Change-Id: I13375c801654df043f18d3463e4ff68ef2f6bd5d
diff --git a/libc/Android.bp b/libc/Android.bp
index 58d8ab2..a7625a0 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -490,8 +490,6 @@
"upstream-openbsd/lib/libc/gen/errx.c",
"upstream-openbsd/lib/libc/gen/fnmatch.c",
"upstream-openbsd/lib/libc/gen/ftok.c",
- "upstream-openbsd/lib/libc/gen/getprogname.c",
- "upstream-openbsd/lib/libc/gen/setprogname.c",
"upstream-openbsd/lib/libc/gen/verr.c",
"upstream-openbsd/lib/libc/gen/verrx.c",
"upstream-openbsd/lib/libc/gen/vwarn.c",
@@ -806,6 +804,7 @@
"bionic/__gnu_basename.cpp",
"bionic/__libc_current_sigrtmax.cpp",
"bionic/__libc_current_sigrtmin.cpp",
+ "bionic/__progname.cpp",
"bionic/abort.cpp",
"bionic/accept.cpp",
"bionic/access.cpp",
diff --git a/libc/bionic/__progname.cpp b/libc/bionic/__progname.cpp
new file mode 100644
index 0000000..92279c4
--- /dev/null
+++ b/libc/bionic/__progname.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "private/bionic_defs.h"
+
+// Not exported in a public header file, but accessible via `extern`,
+// and well-known in the BSDs (though they also only publicly export
+// the functional interface these days).
+__BIONIC_WEAK_VARIABLE_FOR_NATIVE_BRIDGE
+const char* __progname;
+
+const char* getprogname() {
+ return __progname;
+}
+
+void setprogname(const char* name) {
+ const char* last_slash = strrchr(name, '/');
+ __progname = (last_slash != nullptr) ? last_slash + 1 : name;
+}
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 9403dca..502ae09 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -59,10 +59,6 @@
__LIBC_HIDDEN__ constinit _Atomic(bool) __libc_memtag_stack;
__LIBC_HIDDEN__ constinit bool __libc_memtag_stack_abi;
-// Not public, but well-known in the BSDs.
-__BIONIC_WEAK_VARIABLE_FOR_NATIVE_BRIDGE
-const char* __progname;
-
#if defined(__i386__) || defined(__x86_64__)
// Default sizes based on the old hard-coded values for Atom/Silvermont (x86) and Core 2 (x86-64)...
size_t __x86_data_cache_size = 24 * 1024;
diff --git a/libc/upstream-openbsd/lib/libc/gen/getprogname.c b/libc/upstream-openbsd/lib/libc/gen/getprogname.c
deleted file mode 100644
index a020830..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/getprogname.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* $OpenBSD: getprogname.c,v 1.4 2016/03/13 18:34:20 guenther Exp $ */
-/*
- * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <stdlib.h>
-
-const char *
-getprogname(void)
-{
- return (__progname);
-}
diff --git a/libc/upstream-openbsd/lib/libc/gen/setprogname.c b/libc/upstream-openbsd/lib/libc/gen/setprogname.c
deleted file mode 100644
index bce4cbd..0000000
--- a/libc/upstream-openbsd/lib/libc/gen/setprogname.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* $OpenBSD: setprogname.c,v 1.6 2017/09/17 06:38:03 otto Exp $ */
-/*
- * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-void
-setprogname(const char *progname)
-{
- char *tmpn;
-
- tmpn = strrchr(progname, '/');
- if (tmpn == NULL)
- __progname = (char *)progname;
- else
- __progname = tmpn + 1;
-}