Skip to content

Commit 3b4f15d

Browse files
authored
Merge pull request rust-lang#340 from knight42/utmp
Add utmpx
2 parents 5066b7d + b47e554 commit 3b4f15d

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed

libc-test/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ fn main() {
105105
cfg.header("arpa/inet.h");
106106
cfg.header("time64.h");
107107
cfg.header("xlocale.h");
108+
cfg.header("utmp.h");
108109
} else if !windows {
109110
cfg.header("glob.h");
110111
cfg.header("ifaddrs.h");
@@ -122,6 +123,12 @@ fn main() {
122123
cfg.header("execinfo.h");
123124
cfg.header("xlocale.h");
124125
}
126+
127+
if openbsd {
128+
cfg.header("utmp.h");
129+
} else {
130+
cfg.header("utmpx.h");
131+
}
125132
}
126133
}
127134

src/unix/bsd/openbsdlike/openbsd.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,25 @@ s! {
137137
pub int_p_sign_posn: ::c_char,
138138
pub int_n_sign_posn: ::c_char,
139139
}
140+
141+
pub struct lastlog {
142+
ll_time: ::time_t,
143+
ll_line: [::c_char; UT_LINESIZE],
144+
ll_host: [::c_char; UT_HOSTSIZE],
145+
}
146+
147+
pub struct utmp {
148+
pub ut_line: [::c_char; UT_LINESIZE],
149+
pub ut_name: [::c_char; UT_NAMESIZE],
150+
pub ut_host: [::c_char; UT_HOSTSIZE],
151+
pub ut_time: ::time_t,
152+
}
140153
}
141154

155+
pub const UT_NAMESIZE: usize = 32;
156+
pub const UT_LINESIZE: usize = 8;
157+
pub const UT_HOSTSIZE: usize = 256;
158+
142159
pub const O_CLOEXEC: ::c_int = 0x10000;
143160

144161
pub const MS_SYNC : ::c_int = 0x0002;

src/unix/notbsd/android/b32.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ pub const PTHREAD_STACK_MIN: ::size_t = 4096 * 2;
142142
pub const CPU_SETSIZE: ::size_t = 32;
143143
pub const __CPU_BITS: ::size_t = 32;
144144

145+
pub const UT_LINESIZE: usize = 8;
146+
pub const UT_NAMESIZE: usize = 8;
147+
pub const UT_HOSTSIZE: usize = 16;
148+
145149
extern {
146150
pub fn timegm64(tm: *const ::tm) -> ::time64_t;
147151
}

src/unix/notbsd/android/b64.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ pub const PTHREAD_STACK_MIN: ::size_t = 4096 * 4;
152152
pub const CPU_SETSIZE: ::size_t = 1024;
153153
pub const __CPU_BITS: ::size_t = 64;
154154

155+
pub const UT_LINESIZE: usize = 32;
156+
pub const UT_NAMESIZE: usize = 32;
157+
pub const UT_HOSTSIZE: usize = 256;
158+
155159
extern {
156160
pub fn timegm(tm: *const ::tm) -> ::time64_t;
157161
}

src/unix/notbsd/android/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,37 @@ s! {
100100
pub struct sem_t {
101101
count: ::c_uint,
102102
}
103+
104+
pub struct lastlog {
105+
ll_time: ::time_t,
106+
ll_line: [::c_char; UT_LINESIZE],
107+
ll_host: [::c_char; UT_HOSTSIZE],
108+
}
109+
110+
pub struct exit_status {
111+
pub e_termination: ::c_short,
112+
pub e_exit: ::c_short,
113+
}
114+
115+
pub struct utmp {
116+
pub ut_type: ::c_short,
117+
pub ut_pid: ::pid_t,
118+
pub ut_line: [::c_char; UT_LINESIZE],
119+
pub ut_id: [::c_char; 4],
120+
121+
pub ut_user: [::c_char; UT_NAMESIZE],
122+
pub ut_host: [::c_char; UT_HOSTSIZE],
123+
pub ut_exit: exit_status,
124+
pub ut_session: ::c_long,
125+
pub ut_tv: ::timeval,
126+
127+
pub ut_addr_v6: [::int32_t; 4],
128+
unused: [::c_char; 20],
129+
}
103130
}
104131

132+
pub const USER_PROCESS: ::c_short = 7;
133+
105134
pub const BUFSIZ: ::c_uint = 1024;
106135
pub const FILENAME_MAX: ::c_uint = 1024;
107136
pub const FOPEN_MAX: ::c_uint = 20;
@@ -591,6 +620,10 @@ extern {
591620
pub fn __sched_cpufree(set: *mut ::cpu_set_t);
592621
pub fn __sched_cpucount(setsize: ::size_t, set: *mut cpu_set_t) -> ::c_int;
593622
pub fn sched_getcpu() -> ::c_int;
623+
624+
pub fn utmpname(name: *const ::c_char) -> ::c_int;
625+
pub fn setutent();
626+
pub fn getutent() -> *mut utmp;
594627
}
595628

596629
cfg_if! {

src/unix/notbsd/linux/other/b32/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,27 @@ s! {
8383
pub mem_unit: ::c_uint,
8484
pub _f: [::c_char; 8],
8585
}
86+
87+
pub struct __exit_status {
88+
pub e_termination: ::c_short,
89+
pub e_exit: ::c_short,
90+
}
91+
92+
pub struct utmpx {
93+
pub ut_type: ::c_short,
94+
pub ut_pid: ::pid_t,
95+
pub ut_line: [::c_char; __UT_LINESIZE],
96+
pub ut_id: [::c_char; 4],
97+
98+
pub ut_user: [::c_char; __UT_NAMESIZE],
99+
pub ut_host: [::c_char; __UT_HOSTSIZE],
100+
pub ut_exit: __exit_status,
101+
pub ut_session: ::c_long,
102+
pub ut_tv: ::timeval,
103+
104+
pub ut_addr_v6: [::int32_t; 4],
105+
__glibc_reserved: [::c_char; 20],
106+
}
86107
}
87108

88109
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
@@ -97,6 +118,29 @@ pub const PTRACE_SETFPXREGS: ::c_uint = 19;
97118
pub const PTRACE_GETREGS: ::c_uint = 12;
98119
pub const PTRACE_SETREGS: ::c_uint = 13;
99120

121+
pub const __UT_LINESIZE: usize = 32;
122+
pub const __UT_NAMESIZE: usize = 32;
123+
pub const __UT_HOSTSIZE: usize = 256;
124+
pub const EMPTY: ::c_short = 0;
125+
pub const RUN_LVL: ::c_short = 1;
126+
pub const BOOT_TIME: ::c_short = 2;
127+
pub const NEW_TIME: ::c_short = 3;
128+
pub const OLD_TIME: ::c_short = 4;
129+
pub const INIT_PROCESS: ::c_short = 5;
130+
pub const LOGIN_PROCESS: ::c_short = 6;
131+
pub const USER_PROCESS: ::c_short = 7;
132+
pub const DEAD_PROCESS: ::c_short = 8;
133+
pub const ACCOUNTING: ::c_short = 9;
134+
135+
extern {
136+
pub fn getutxent() -> *mut utmpx;
137+
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
138+
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
139+
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
140+
pub fn setutxent();
141+
pub fn endutxent();
142+
}
143+
100144
cfg_if! {
101145
if #[cfg(target_arch = "x86")] {
102146
mod x86;

0 commit comments

Comments
 (0)