1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #1084 from Arcterus/stdbuf-fix

Fix Makefile and stdbuf
This commit is contained in:
mpkh 2017-11-27 08:08:50 +04:00 committed by GitHub
commit ef4d09ee3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 385 additions and 278 deletions

517
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -306,10 +306,10 @@ ifeq (${MULTICALL}, y)
cd $(INSTALLDIR_BIN) && ln -fs $(PROG_PREFIX)uutils $(PROG_PREFIX)$(prog);)
else
$(foreach prog, $(INSTALLEES), \
$(INSTALL) $(PKG_BUILDDIR)/$(prog) $(INSTALLDIR_BIN)/$(PROG_PREFIX)$(prog);)
$(INSTALL) $(BUILDDIR)/$(prog) $(INSTALLDIR_BIN)/$(PROG_PREFIX)$(prog);)
endif
mkdir -p $(INSTALLDIR_LIB)
$(foreach lib, $(LIBS), $(INSTALL) $(BUILDDIR)/$(lib) $(INSTALLDIR_LIB)/$(lib);)
$(foreach lib, $(LIBS), $(INSTALL) $(BUILDDIR)/build/*/out/$(lib) $(INSTALLDIR_LIB)/$(lib);)
uninstall:
ifeq (${MULTICALL}, y)

View file

@ -48,21 +48,21 @@ pub fn uumain(args: Vec<String>) -> i32 {
The utmp file will be {}", utmpx::DEFAULT_FILE);
let mut opts = new_coreopts!(SYNTAX, SUMMARY, &long_help);
opts.optflag("l",
"l",
"",
"produce long format output for the specified USERs");
opts.optflag("b",
"b",
"",
"omit the user's home directory and shell in long format");
opts.optflag("h", "h", "omit the user's project file in long format");
opts.optflag("p", "p", "omit the user's plan file in long format");
opts.optflag("s", "s", "do short format output, this is the default");
opts.optflag("f", "f", "omit the line of column headings in short format");
opts.optflag("w", "w", "omit the user's full name in short format");
opts.optflag("h", "", "omit the user's project file in long format");
opts.optflag("p", "", "omit the user's plan file in long format");
opts.optflag("s", "", "do short format output, this is the default");
opts.optflag("f", "", "omit the line of column headings in short format");
opts.optflag("w", "", "omit the user's full name in short format");
opts.optflag("i",
"i",
"",
"omit the user's full name and remote host in short format");
opts.optflag("q",
"q",
"",
"omit the user's full name, remote host and idle time in short format");
opts.optflag("", "help", "display this help and exit");
opts.optflag("", "version", "output version information and exit");

View file

@ -2,6 +2,7 @@
name = "stdbuf"
version = "0.0.1"
authors = []
build = "build.rs"
[lib]
name = "uu_stdbuf"
@ -10,6 +11,10 @@ path = "stdbuf.rs"
[dependencies]
getopts = "0.2.14"
uucore = { path="../uucore" }
libstdbuf = { path="libstdbuf" }
[build-dependencies]
cc = "1.0"
[[bin]]
name = "stdbuf"

31
src/stdbuf/Makefile Normal file
View file

@ -0,0 +1,31 @@
BUILDDIR ?= $(OUT_DIR)
CC ?= gcc
RUSTC ?= rustc
# Shared library extension
SYSTEM := $(shell uname)
DYLIB_EXT :=
ifeq ($(SYSTEM),Linux)
DYLIB_EXT := so
DYLIB_FLAGS := -shared
DYLIB_LINK_START := -Wl,--whole-archive
DYLIB_LINK_END := -Wl,--no-whole-archive
endif
ifeq ($(SYSTEM),Darwin)
DYLIB_EXT := dylib
DYLIB_FLAGS := -dynamiclib -undefined dynamic_lookup
DYLIB_LINK_START :=
DYLIB_LINK_END :=
endif
all: $(BUILDDIR)/libstdbuf.$(DYLIB_EXT)
$(BUILDDIR):
mkdir -p $@
$(BUILDDIR)/libstdbuf.$(DYLIB_EXT): build.rs libstdbuf/libstdbuf.rs libstdbuf.c libstdbuf.h | $(BUILDDIR)
cp $(BUILDDIR)/../../../deps/liblibstdbuf-*.a $(BUILDDIR)/liblibstdbuf.a && \
$(CC) -c -Wall -Werror -fPIC libstdbuf.c -o $(BUILDDIR)/libstdbuf.o && \
$(CC) $(DYLIB_FLAGS) -o $@ $(BUILDDIR)/libstdbuf.o $(DYLIB_LINK_START) $(BUILDDIR)/liblibstdbuf.a $(DYLIB_LINK_END)

5
src/stdbuf/build.rs Normal file
View file

@ -0,0 +1,5 @@
use std::process::Command;
fn main() {
Command::new("make").output().expect("failed to execute make");
}

View file

@ -1,12 +1,9 @@
#![crate_name = "libstdbuf"]
#![crate_type = "staticlib"]
extern crate libc;
#[macro_use]
extern crate uucore;
use libc::{c_int, size_t, c_char, FILE, _IOFBF, _IONBF, _IOLBF, setvbuf};
use libc::{c_int, size_t, c_char, FILE, _IOFBF, _IONBF, _IOLBF};
use std::env;
use std::io::Write;
use std::ptr;
@ -17,8 +14,6 @@ extern {
static stderr: *mut FILE;
}
static NAME: &'static str = "libstdbuf";
fn set_buffer(stream: *mut FILE, value: &str) {
let (mode, size): (c_int, size_t) = match value {
"0" => (_IONBF, 0 as size_t),
@ -43,7 +38,7 @@ fn set_buffer(stream: *mut FILE, value: &str) {
}
#[no_mangle]
pub extern fn stdbuf() {
pub unsafe extern "C" fn stdbuf() {
if let Ok(val) = env::var("_STDBUF_E") {
set_buffer(stderr, &val);
}

View file

@ -0,0 +1,13 @@
[package]
name = "libstdbuf"
version = "0.0.1"
authors = []
[lib]
name = "libstdbuf"
path = "libstdbuf.rs"
crate-type = ["staticlib"]
[dependencies]
uucore = { path="../../uucore" }
libc = "0.2"

View file

@ -0,0 +1,51 @@
extern crate libc;
#[macro_use]
extern crate uucore;
use libc::{c_int, size_t, c_char, FILE, _IOFBF, _IONBF, _IOLBF};
use std::env;
use std::io::Write;
use std::ptr;
extern {
static stdin: *mut FILE;
static stdout: *mut FILE;
static stderr: *mut FILE;
}
fn set_buffer(stream: *mut FILE, value: &str) {
let (mode, size): (c_int, size_t) = match value {
"0" => (_IONBF, 0 as size_t),
"L" => (_IOLBF, 0 as size_t),
input => {
let buff_size: usize = match input.parse() {
Ok(num) => num,
Err(e) => crash!(1, "incorrect size of buffer!: {}", e)
};
(_IOFBF, buff_size as size_t)
}
};
let res: c_int;
unsafe {
let buffer: *mut c_char = ptr::null_mut();
assert!(buffer.is_null());
res = libc::setvbuf(stream, buffer, mode, size);
}
if res != 0 {
crash!(res, "error while calling setvbuf!");
}
}
#[no_mangle]
pub unsafe extern fn stdbuf() {
if let Ok(val) = env::var("_STDBUF_E") {
set_buffer(stderr, &val);
}
if let Ok(val) = env::var("_STDBUF_I") {
set_buffer(stdin, &val);
}
if let Ok(val) = env::var("_STDBUF_O") {
set_buffer(stdout, &val);
}
}

View file

@ -55,7 +55,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
opts.optflag("H", "heading", "print line of column headings");
opts.optflag("l", "login", "print system login processes");
opts.optflag("", "lookup", "attempt to canonicalize hostnames via DNS");
opts.optflag("m", "m", "only hostname and user associated with stdin");
opts.optflag("m", "", "only hostname and user associated with stdin");
opts.optflag("p", "process", "print active processes spawned by init");
opts.optflag("q",
"count",

View file

@ -72,7 +72,7 @@ fn test_wrap_no_arg() {
new_ucmd!()
.arg(wrap_param)
.fails()
.stderr_only(format!("base32: error: Argument to option '{}' missing.\n",
.stderr_only(format!("base32: error: Argument to option '{}' missing\n",
if wrap_param == "-w" { "w" } else { "wrap" }));
}
}

View file

@ -64,7 +64,7 @@ fn test_wrap_no_arg() {
new_ucmd!()
.arg(wrap_param)
.fails()
.stderr_only(format!("base64: error: Argument to option '{}' missing.\n",
.stderr_only(format!("base64: error: Argument to option '{}' missing\n",
if wrap_param == "-w" { "w" } else { "wrap" }));
}
}

View file

@ -65,14 +65,14 @@ fn test_stdin_all_repeated() {
#[test]
fn test_stdin_all_repeated_separate() {
new_ucmd!()
.args(&["--all-repeated", "separate"]).pipe_in_fixture(INPUT)
.args(&["--all-repeated=separate"]).pipe_in_fixture(INPUT)
.run().stdout_is_fixture("sorted-all-repeated-separate.expected");
}
#[test]
fn test_stdin_all_repeated_prepend() {
new_ucmd!()
.args(&["--all-repeated", "prepend"]).pipe_in_fixture(INPUT)
.args(&["--all-repeated=prepend"]).pipe_in_fixture(INPUT)
.run().stdout_is_fixture("sorted-all-repeated-prepend.expected");
}