mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
pinky: fix a weird bug:
Strings passed to C functions must ends with NULL.
This commit is contained in:
parent
048daee8b9
commit
f91c60ff70
1 changed files with 4 additions and 9 deletions
|
@ -30,8 +30,7 @@ use std::fs::File;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::ffi::CStr;
|
use std::ffi::{CStr, CString, OsStr};
|
||||||
use std::ffi::OsStr;
|
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -209,7 +208,9 @@ impl FromChars for String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getpw(u: &str) -> Option<Passwd> {
|
pub fn getpw(u: &str) -> Option<Passwd> {
|
||||||
let pw = unsafe { getpwnam(u.as_ptr() as *const i8) };
|
let pw = unsafe {
|
||||||
|
getpwnam(CString::new(u).unwrap().as_ptr())
|
||||||
|
};
|
||||||
if !pw.is_null() {
|
if !pw.is_null() {
|
||||||
let data = unsafe { ptr::read(pw) };
|
let data = unsafe { ptr::read(pw) };
|
||||||
Some(Passwd {
|
Some(Passwd {
|
||||||
|
@ -364,12 +365,6 @@ impl Pinky {
|
||||||
fn short_pinky(&self) -> IOResult<()> {
|
fn short_pinky(&self) -> IOResult<()> {
|
||||||
if self.include_heading {
|
if self.include_heading {
|
||||||
self.print_heading();
|
self.print_heading();
|
||||||
} else {
|
|
||||||
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
// FIXME: WEIRD!!! If the following line is removed,
|
|
||||||
// getpwnam() will return NULL.
|
|
||||||
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
|
||||||
print!("");
|
|
||||||
}
|
}
|
||||||
for ut in utmp::read_utmps() {
|
for ut in utmp::read_utmps() {
|
||||||
if ut.is_user_process() {
|
if ut.is_user_process() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue