Browse Source

Make program_invocation_name modifiable

libiconv expects program_invocation_name to be an lvalue
Steve McKay 5 years ago
parent
commit
4859c222e7
6 changed files with 21 additions and 3 deletions
  1. 1 1
      include/bits/errno.h
  2. 2 2
      src/header/errno/mod.rs
  3. 1 0
      tests/Makefile
  4. 13 0
      tests/errno.c
  5. 0 0
      tests/expected/errno.stderr
  6. 4 0
      tests/expected/errno.stdout

+ 1 - 1
include/bits/errno.h

@@ -8,7 +8,7 @@ extern "C" {
 #define ENOTSUP EOPNOTSUPP
 
 #define errno (*__errno_location())
-#define program_invocation_name (__program_invocation_name())
+#define program_invocation_name (*__program_invocation_name())
 
 #ifdef __cplusplus
 } // extern "C"

+ 2 - 2
src/header/errno/mod.rs

@@ -14,8 +14,8 @@ pub unsafe extern "C" fn __errno_location() -> *mut c_int {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn __program_invocation_name() -> *mut c_char {
-    platform::inner_argv[0]
+pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
+    &mut platform::inner_argv[0]
 }
 
 pub const EPERM: c_int = 1; /* Operation not permitted */

+ 1 - 0
tests/Makefile

@@ -8,6 +8,7 @@ EXPECT_NAMES=\
 	ctype \
 	destructor \
 	dirent/scandir \
+	errno \
 	error \
 	fcntl/create \
 	fcntl/fcntl \

+ 13 - 0
tests/errno.c

@@ -0,0 +1,13 @@
+#include <errno.h>
+#include <stdio.h>
+#include "test_helpers.h"
+
+int main(int argc, char **argv) {
+    puts(argv[0]);
+    puts(program_invocation_name);
+
+    program_invocation_name = "yes, you can change this";
+
+    puts(argv[0]);
+    puts(program_invocation_name);
+}

+ 0 - 0
tests/expected/errno.stderr


+ 4 - 0
tests/expected/errno.stdout

@@ -0,0 +1,4 @@
+bins/errno
+bins/errno
+yes, you can change this
+yes, you can change this