On Wed, Sep 7, 2016 at 10:22 AM, Gisle Vanem <[email protected]> wrote:
> Jim Meyering wrote:
>
>> +# elif HAVE_DECL___ARGV
>> + return last_component (__argv);
>
> This should be:
> return last_component (*__argv);
>
> Or with a bit more care:
> if (*__argv == NULL)
> return ("?");
> return last_component (__argv);
Thanks!
I fixed that and the copy/paste error mentioned below with a patch in
your name. Will push after you ACK.
> And in the test:
>
> +int
> +main (void)
> +{
> + char const *p = getprogname ();
> + assert (STREQ (p, "test-getprogname"));
> + return 0;
> +}
>
>
> getprogname() would return "test-getprogname.exe" on
> Windows. Hence a fail.
I've fixed that with a separate patch to make it use EXEEXT.
> BTW, what is 'base' used for here:
>
> # elif HAVE_GETEXECNAME
> const char *base = getexecname ();
> if (!base)
> base = "?";
> return last_component (program_invocation_name);
From 067547cfd48db2611bf0d7f11b67ccd27344b961 Mon Sep 17 00:00:00 2001
From: Gisle Vanem <[email protected]>
Date: Wed, 7 Sep 2016 10:45:03 -0700
Subject: [PATCH 1/2] getprogname: fix errors in previous change
* lib/getprogname.c (getprogname) [HAVE_GETEXECNAME]:
s/program_invocation_name/base/
[HAVE_DECL___ARGV]: Handle NULL __argv or __argv[0].
---
ChangeLog | 7 +++++++
lib/getprogname.c | 11 ++++++-----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1786c81..da6b6a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-07 Gisle Vanem <[email protected]>
+
+ getprogname: fix errors in previous change
+ * lib/getprogname.c (getprogname) [HAVE_GETEXECNAME]:
+ s/program_invocation_name/base/
+ [HAVE_DECL___ARGV]: Handle NULL __argv or __argv[0].
+
2016-09-07 Jim Meyering <[email protected]>
getprogname: port to systems with __argv (mingw, msvc)
diff --git a/lib/getprogname.c b/lib/getprogname.c
index 77aaf18..d70c2aa 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -34,12 +34,13 @@ getprogname (void)
# elif HAVE_DECL_PROGRAM_INVOCATION_NAME
return last_component (program_invocation_name);
# elif HAVE_GETEXECNAME
- const char *base = getexecname ();
- if (!base)
- base = "?";
- return last_component (program_invocation_name);
+ const char *p = getexecname ();
+ if (!p)
+ p = "?";
+ return last_component (p);
# elif HAVE_DECL___ARGV
- return last_component (__argv);
+ const char *p = __argv && __argv[0] ? __argv[0] : "?";
+ return last_component (p);
# else
# error "getprogname module not ported to this OS"
# endif
--
2.7.4
From 5e0dae40c0591d88bdbd4e9bdf0154f30b99de90 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Wed, 7 Sep 2016 11:03:03 -0700
Subject: [PATCH 2/2] getprogname-tests: work also when EXEEXT is nonempty
* modules/getprogname-tests (Makefile.am): Define EXEEXT.
* tests/test-getprogname.c (main): Use it.
Suggested by Gisle Vanem.
---
ChangeLog | 7 +++++++
modules/getprogname-tests | 1 +
tests/test-getprogname.c | 2 +-
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index da6b6a9..85f3ae4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-07 Jim Meyering <[email protected]>
+
+ getprogname-tests: work also when EXEEXT is nonempty
+ * modules/getprogname-tests (Makefile.am): Define EXEEXT.
+ * tests/test-getprogname.c (main): Use it.
+ Suggested by Gisle Vanem.
+
2016-09-07 Gisle Vanem <[email protected]>
getprogname: fix errors in previous change
diff --git a/modules/getprogname-tests b/modules/getprogname-tests
index 071bf38..822b7a3 100644
--- a/modules/getprogname-tests
+++ b/modules/getprogname-tests
@@ -8,6 +8,7 @@ string
configure.ac:
Makefile.am:
+DEFS += -DEXEEXT=\"@EXEEXT@\"
TESTS += test-getprogname
check_PROGRAMS += test-getprogname
test_getprogname_LDADD = $(LDADD)
diff --git a/tests/test-getprogname.c b/tests/test-getprogname.c
index 4d92170..6e3f694 100644
--- a/tests/test-getprogname.c
+++ b/tests/test-getprogname.c
@@ -26,6 +26,6 @@ int
main (void)
{
char const *p = getprogname ();
- assert (STREQ (p, "test-getprogname"));
+ assert (STREQ (p, "test-getprogname" EXEEXT));
return 0;
}
--
2.7.4