Skip to content

Commit 893d4d8

Browse files
committed
Adding getprogname and setprogname for all BSDs and Solaris.
Adding program_invocation_short_name for Linux (Musl and glibc). Adding __progname for Android. This is a little different, but is a safer alternative to using argv[0], which may not exist, and includes Android's default application name (currently '<unknown>'). Adding these functions and externs means it is possible for all but Windows applications to safely discover their name, rather than rely on argv[0] parsing, /proc/self/exe, etc.
1 parent a04a52a commit 893d4d8

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

src/unix/bsd/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ extern {
358358
buf: *mut ::c_char,
359359
buflen: ::size_t,
360360
result: *mut *mut passwd) -> ::c_int;
361+
pub fn getprogname() -> *const ::c_char;
362+
pub fn setprogname(name: *const ::c_char);
361363
}
362364

363365
cfg_if! {

src/unix/notbsd/android/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ f! {
625625
}
626626
}
627627

628+
extern {
629+
static mut __progname: *mut ::c_char;
630+
}
631+
628632
extern {
629633
pub fn madvise(addr: *const ::c_void, len: ::size_t, advice: ::c_int)
630634
-> ::c_int;

src/unix/notbsd/linux/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ f! {
474474
}
475475
}
476476

477+
extern {
478+
static mut program_invocation_short_name: *mut ::c_char;
479+
}
480+
477481
#[link(name = "util")]
478482
extern {
479483
pub fn shm_open(name: *const c_char, oflag: ::c_int,

src/unix/solaris/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,5 +901,7 @@ extern {
901901
locale: *const ::c_char,
902902
base: ::locale_t) -> ::locale_t;
903903
pub fn uselocale(loc: ::locale_t) -> ::locale_t;
904+
pub fn getprogname() -> *const ::c_char;
905+
pub fn setprogname(name: *const ::c_char);
904906
}
905907

0 commit comments

Comments
 (0)