Skip to content

Commit 19fd504

Browse files
committed
Auto merge of #281 - lemonrock:getprogname, r=alexcrichton
Getprogname Added `getprogname()` and `setprogname()` for all BSDs and Solaris (including Mac OS X). Added `program_invocation_short_name` global, for Linux (glibc and Musl) which is effectively the same thing, and is what compatibility libraries like `libbsd` use to implement `getprogname()`. Added `__progname` global for Android, which, whilst not quite the same as `getprogname` or `program_invocation_short_name`, is better than using argv[0], as it (a) avoids a common bug with no arguments (b) avoids a common bug with a NULL string in argv[0] and (c) incorporates Android's chosen name for an unknown process.
2 parents 2cd2cff + 893d4d8 commit 19fd504

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
@@ -515,6 +515,10 @@ f! {
515515
}
516516
}
517517

518+
extern {
519+
static mut __progname: *mut ::c_char;
520+
}
521+
518522
extern {
519523
pub fn madvise(addr: *const ::c_void, len: ::size_t, advice: ::c_int)
520524
-> ::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)