Skip to content

Commit 2d032e4

Browse files
committed
liblibc: Fix prototype of functions taking char *const argv[]
These functions do not modify their arguments, so they does not need mutable pointers. The C prototypes take a constant array of mutable C-strings, but that's a legacy quirk from before C had const (since string literals have type `char *`). The Rust prototypes had `*mut` in the wrong place, anyway: to match the C prototypes, it should have been `*const *mut c_char`. Also fix the one caller of execvp in libstd, which now no longer needs an unsafe cast.
1 parent f6b446f commit 2d032e4

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/liblibc/lib.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -5490,17 +5490,17 @@ pub mod funcs {
54905490
pub fn dup2(src: c_int, dst: c_int) -> c_int;
54915491
#[link_name = "_execv"]
54925492
pub fn execv(prog: *const c_char,
5493-
argv: *mut *const c_char) -> intptr_t;
5493+
argv: *const *const c_char) -> intptr_t;
54945494
#[link_name = "_execve"]
5495-
pub fn execve(prog: *const c_char, argv: *mut *const c_char,
5496-
envp: *mut *const c_char)
5495+
pub fn execve(prog: *const c_char, argv: *const *const c_char,
5496+
envp: *const *const c_char)
54975497
-> c_int;
54985498
#[link_name = "_execvp"]
54995499
pub fn execvp(c: *const c_char,
5500-
argv: *mut *const c_char) -> c_int;
5500+
argv: *const *const c_char) -> c_int;
55015501
#[link_name = "_execvpe"]
5502-
pub fn execvpe(c: *const c_char, argv: *mut *const c_char,
5503-
envp: *mut *const c_char) -> c_int;
5502+
pub fn execvpe(c: *const c_char, argv: *const *const c_char,
5503+
envp: *const *const c_char) -> c_int;
55045504
#[link_name = "_getcwd"]
55055505
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
55065506
#[link_name = "_getpid"]
@@ -5684,12 +5684,12 @@ pub mod funcs {
56845684
pub fn dup(fd: c_int) -> c_int;
56855685
pub fn dup2(src: c_int, dst: c_int) -> c_int;
56865686
pub fn execv(prog: *const c_char,
5687-
argv: *mut *const c_char) -> c_int;
5688-
pub fn execve(prog: *const c_char, argv: *mut *const c_char,
5689-
envp: *mut *const c_char)
5687+
argv: *const *const c_char) -> c_int;
5688+
pub fn execve(prog: *const c_char, argv: *const *const c_char,
5689+
envp: *const *const c_char)
56905690
-> c_int;
56915691
pub fn execvp(c: *const c_char,
5692-
argv: *mut *const c_char) -> c_int;
5692+
argv: *const *const c_char) -> c_int;
56935693
pub fn fork() -> pid_t;
56945694
pub fn fpathconf(filedes: c_int, name: c_int) -> c_long;
56955695
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
@@ -5699,7 +5699,7 @@ pub mod funcs {
56995699
pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t)
57005700
-> c_int;
57015701
pub fn getlogin() -> *mut c_char;
5702-
pub fn getopt(argc: c_int, argv: *mut *const c_char,
5702+
pub fn getopt(argc: c_int, argv: *const *const c_char,
57035703
optstr: *const c_char) -> c_int;
57045704
pub fn getpgrp() -> pid_t;
57055705
pub fn getpid() -> pid_t;
@@ -5749,19 +5749,19 @@ pub mod funcs {
57495749
pub fn dup(fd: c_int) -> c_int;
57505750
pub fn dup2(src: c_int, dst: c_int) -> c_int;
57515751
pub fn execv(prog: *const c_char,
5752-
argv: *mut *const c_char) -> c_int;
5753-
pub fn execve(prog: *const c_char, argv: *mut *const c_char,
5754-
envp: *mut *const c_char)
5752+
argv: *const *const c_char) -> c_int;
5753+
pub fn execve(prog: *const c_char, argv: *const *const c_char,
5754+
envp: *const *const c_char)
57555755
-> c_int;
57565756
pub fn execvp(c: *const c_char,
5757-
argv: *mut *const c_char) -> c_int;
5757+
argv: *const *const c_char) -> c_int;
57585758
pub fn fork() -> pid_t;
57595759
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
57605760
pub fn getegid() -> gid_t;
57615761
pub fn geteuid() -> uid_t;
57625762
pub fn getgid() -> gid_t;
57635763
pub fn getlogin() -> *mut c_char;
5764-
pub fn getopt(argc: c_int, argv: *mut *const c_char,
5764+
pub fn getopt(argc: c_int, argv: *const *const c_char,
57655765
optstr: *const c_char) -> c_int;
57665766
pub fn getuid() -> uid_t;
57675767
pub fn getsid(pid: pid_t) -> pid_t;

src/libstd/sys/unix/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl Process {
311311
if !envp.is_null() {
312312
*sys::os::environ() = envp as *const _;
313313
}
314-
let _ = libc::execvp(*argv, argv as *mut _);
314+
let _ = libc::execvp(*argv, argv);
315315
fail(&mut output)
316316
}
317317

0 commit comments

Comments
 (0)