This commit is contained in:
Jeremy Soller
2018-11-27 10:07:47 -07:00
34 changed files with 79 additions and 112 deletions
+4 -3
View File
@@ -35,6 +35,7 @@ all: | libc libm
clean:
$(CARGO) clean
make -C tests clean
rm -rf sysroot
check:
$(CARGO) check
@@ -43,16 +44,16 @@ fmt:
./fmt.sh
install: all
mkdir -pv "$(DESTDIR)/lib"
mkdir -pv "$(DESTDIR)/include"
cp -rv "include"/* "$(DESTDIR)/include"
cp -rv "$(BUILD)/include"/* "$(DESTDIR)/include"
cp -v "openlibm/include"/*.h "$(DESTDIR)/include"
cp -v "openlibm/src"/*.h "$(DESTDIR)/include"
mkdir -pv "$(DESTDIR)/lib"
cp -v "$(BUILD)/release/libc.a" "$(DESTDIR)/lib"
cp -v "$(BUILD)/release/crt0.o" "$(DESTDIR)/lib"
cp -v "$(BUILD)/release/crti.o" "$(DESTDIR)/lib"
cp -v "$(BUILD)/release/crtn.o" "$(DESTDIR)/lib"
cp -rv "openlibm/include"/* "$(DESTDIR)/include"
cp -rv "openlibm/src"/*.h "$(DESTDIR)/include"
cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a"
libc: $(BUILD)/release/libc.a $(BUILD)/release/crt0.o $(BUILD)/release/crti.o $(BUILD)/release/crtn.o $(BUILD)/include
+1 -2
View File
@@ -1,2 +1 @@
#define OPENLIBM_USE_HOST_FENV_H 1
#include <openlibm.h>
#include <openlibm_complex.h>
+1 -4
View File
@@ -1,4 +1 @@
#define OPENLIBM_USE_HOST_FENV_H 1
#include <openlibm.h>
#undef I
#undef complex
#include <openlibm_math.h>
+3
View File
@@ -5,3 +5,6 @@ style = "Tag"
[enum]
prefix_with_name = true
[export.rename]
"in_addr" = "struct in_addr"
+1 -1
View File
@@ -1,8 +1,8 @@
sys_includes = []
include_guard = "_LIMITS_H"
trailer = "#include <bits/limits.h>"
language = "C"
style = "Tag"
trailer = "#include <bits/limits.h>"
[enum]
prefix_with_name = true
+3 -3
View File
@@ -1,4 +1,4 @@
pub mod aio;
pub mod _aio;
pub mod arpa_inet;
pub mod assert;
pub mod ctype;
@@ -9,7 +9,7 @@ pub mod fenv;
pub mod float;
pub mod fnmatch;
pub mod getopt;
pub mod grp;
pub mod _grp;
pub mod inttypes;
pub mod libgen;
pub mod limits;
@@ -45,4 +45,4 @@ pub mod time;
pub mod unistd;
pub mod utime;
pub mod wchar;
pub mod wctype;
pub mod _wctype;
-7
View File
@@ -1,7 +0,0 @@
[package]
name = "netinet"
version = "0.1.0"
authors = ["Dan Robertson <danlrobertson89@gmail.com>"]
[dependencies]
in_h = { path = "in" }
+1 -1
View File
@@ -1,7 +1,7 @@
sys_includes = ["sys/types.h", "sys/socket.h"]
include_guard = "_NETINET_IN_H"
style = "Both"
language = "C"
style = "Tag"
[export]
include = ["sockaddr_in6", "sockaddr_in", "ipv6_mreq"]
+1 -1
View File
@@ -1,7 +1,7 @@
sys_includes = ["sys/ioctl.h"]
include_guard = "_SGTTY_H"
style = "Tag"
language = "C"
style = "Tag"
[enum]
prefix_with_name = true
+1 -1
View File
@@ -1,7 +1,7 @@
sys_includes = ["stdint.h", "sys/types.h", "bits/signal.h"]
include_guard = "_SIGNAL_H"
style = "Tag"
language = "C"
style = "Tag"
[defines]
"target_os=linux" = "__linux__"
+1 -4
View File
@@ -1,9 +1,6 @@
include_guard = "_SYS_IOCTL_H"
language = "C"
# WORKAROUND:
# sgtty is used by another header, and cbindgen doesn't prefix that with `struct` :|
style = "Both"
style = "Tag"
[defines]
"target_os=linux" = "__linux__"
+4 -4
View File
@@ -2,10 +2,10 @@ sys_includes = ["sys/types.h", "stdint.h", "sys/time.h"]
include_guard = "_SYS_RESOURCE_H"
trailer = "#include <bits/sys/resource.h>"
language = "C"
# WORKAROUND:
# Rusage is used by another header, and cbindgen does not prefix that usage with `struct` :|
style = "Both"
style = "Tag"
[enum]
prefix_with_name = true
[export.rename]
"timeval" = "struct timeval"
+3 -1
View File
@@ -8,5 +8,7 @@ prefix_with_name = true
[export]
# fd_set is also defined in C because cbindgen is incompatible with mem::size_of booo
exclude = ["FD_SETSIZE", "fd_set"]
[export.rename]
"timeval" = "struct timeval"
+1 -1
View File
@@ -1,7 +1,7 @@
sys_includes = ["stddef.h", "stdint.h", "sys/types.h"]
include_guard = "_SYS_SOCKET_H"
style = "Both"
language = "C"
style = "Tag"
[defines]
"target_os=linux" = "__linux__"
+3
View File
@@ -6,3 +6,6 @@ style = "Tag"
[enum]
prefix_with_name = true
[export.rename]
"timespec" = "struct timespec"
+1 -4
View File
@@ -2,10 +2,7 @@ sys_includes = ["sys/types.h"]
include_guard = "_SYS_TIME_H"
language = "C"
trailer = "#include <bits/sys/time.h>"
# WORKAROUND:
# Timeval is used by another header, and cbindgen doesn't prefix that with `struct` :|
style = "Both"
style = "Tag"
[enum]
prefix_with_name = true
+1 -1
View File
@@ -1,8 +1,8 @@
sys_includes = ["sys/types.h", "sys/resource.h"]
include_guard = "_SYS_WAIT_H"
style = "Type"
trailer = "#include <bits/sys/wait.h>"
language = "C"
style = "Tag"
[enum]
prefix_with_name = true
+1 -4
View File
@@ -1,10 +1,7 @@
sys_includes = ["sys/types.h", "stdint.h", "stddef.h"]
include_guard = "_TIME_H"
language = "C"
# WORKAROUND:
# Tm is used by another header, and cbindgen doesn't prefix that with `struct` :|
style = "Both"
style = "Tag"
[enum]
prefix_with_name = true
+33 -57
View File
@@ -7,7 +7,6 @@ use core::{mem, ptr, slice};
use spin::{Mutex, MutexGuard, Once};
use syscall::data::Stat as redox_stat;
use syscall::data::TimeSpec as redox_timespec;
use syscall::flag::*;
use syscall::{self, Result};
use c_str::{CStr, CString};
@@ -22,7 +21,7 @@ use header::sys_time::{timeval, timezone};
use header::sys_utsname::{utsname, UTSLENGTH};
use header::termios::termios;
use header::time::timespec;
use header::unistd::{F_OK, R_OK, SEEK_SET, W_OK, X_OK};
use header::unistd::{F_OK, R_OK, W_OK, X_OK};
use io::prelude::*;
use io::{self, BufReader, SeekFrom};
@@ -113,24 +112,16 @@ impl Pal for Sys {
}
fn chmod(path: &CStr, mode: mode_t) -> c_int {
match syscall::open(path.to_bytes(), O_WRONLY | O_CLOEXEC) {
Err(err) => e(Err(err)) as c_int,
Ok(fd) => {
let res = syscall::fchmod(fd as usize, mode as u16);
let _ = syscall::close(fd);
e(res) as c_int
}
match File::open(path, fcntl::O_PATH | fcntl::O_CLOEXEC) {
Ok(file) => Self::fchmod(*file, mode),
Err(_) => -1,
}
}
fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int {
match syscall::open(path.to_bytes(), O_WRONLY | O_CLOEXEC) {
Err(err) => e(Err(err)) as c_int,
Ok(fd) => {
let res = syscall::fchown(fd as usize, owner as u32, group as u32);
let _ = syscall::close(fd);
e(res) as c_int
}
match File::open(path, fcntl::O_PATH | fcntl::O_CLOEXEC) {
Ok(file) => Self::fchown(*file, owner, group),
Err(_) => -1,
}
}
@@ -402,13 +393,9 @@ impl Pal for Sys {
}
fn utimens(path: &CStr, times: *const timespec) -> c_int {
match syscall::open(path.to_bytes(), O_STAT | O_CLOEXEC) {
Err(err) => e(Err(err)) as c_int,
Ok(fd) => {
let res = Self::futimens(fd as c_int, times);
let _ = syscall::close(fd);
res
}
match File::open(path, fcntl::O_PATH | fcntl::O_CLOEXEC) {
Ok(file) => Self::futimens(*file, times),
Err(_) => -1,
}
}
@@ -427,7 +414,7 @@ impl Pal for Sys {
fn getdents(fd: c_int, mut dirents: *mut dirent, max_bytes: usize) -> c_int {
// Get initial reading position
let mut read = match syscall::lseek(fd as usize, 0, SEEK_CUR) {
let mut read = match syscall::lseek(fd as usize, 0, syscall::SEEK_CUR) {
Ok(pos) => pos as isize,
Err(err) => return -err.errno,
};
@@ -447,7 +434,7 @@ impl Pal for Sys {
let size = mem::size_of::<dirent>() - name.len().saturating_sub(*i + 1);
if *written + size > max_bytes {
// Seek back to after last read entry and return
match syscall::lseek(fd as usize, read, SEEK_SET as usize) {
match syscall::lseek(fd as usize, read, syscall::SEEK_SET) {
Ok(_) => return Some(*written as c_int),
Err(err) => return Some(-err.errno),
}
@@ -612,24 +599,16 @@ impl Pal for Sys {
}
fn mkdir(path: &CStr, mode: mode_t) -> c_int {
let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777;
match syscall::open(path.to_bytes(), flags) {
Ok(fd) => {
let _ = syscall::close(fd);
0
}
Err(err) => e(Err(err)) as c_int,
match File::create(path, fcntl::O_DIRECTORY | fcntl::O_EXCL | fcntl::O_CLOEXEC, 0o777) {
Ok(_fd) => 0,
Err(_) => -1,
}
}
fn mkfifo(path: &CStr, mode: mode_t) -> c_int {
let flags = O_CREAT | O_CLOEXEC | MODE_FIFO as usize | mode as usize & 0o777;
match syscall::open(path.to_bytes(), flags) {
Ok(fd) => {
let _ = syscall::close(fd);
0
}
Err(err) => e(Err(err)) as c_int,
match File::create(path, fcntl::O_CREAT | fcntl::O_CLOEXEC, syscall::MODE_FIFO as mode_t | (mode & 0o777)) {
Ok(fd) => 0,
Err(_) => -1,
}
}
@@ -642,7 +621,7 @@ impl Pal for Sys {
off: off_t,
) -> *mut c_void {
if flags & MAP_ANON == MAP_ANON {
let fd = e(syscall::open("memory:", O_STAT | O_CLOEXEC)); // flags don't matter currently
let fd = e(syscall::open("memory:", syscall::O_STAT | syscall::O_CLOEXEC)); // flags don't matter currently
if fd == !0 {
return !0 as *mut c_void;
}
@@ -695,7 +674,7 @@ impl Pal for Sys {
fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int {
e(syscall::open(
path.to_bytes(),
((oflag as usize) << 16) | (mode as usize),
((oflag as usize) << 16) | ((mode as usize) & 0xFFFF),
)) as c_int
}
@@ -836,8 +815,8 @@ impl Pal for Sys {
}
fn readlink(pathname: &CStr, out: &mut [u8]) -> ssize_t {
let file = match File::open(pathname, fcntl::O_PATH | fcntl::O_SYMLINK) {
Ok(fd) => fd,
let file = match File::open(pathname, fcntl::O_PATH | fcntl::O_SYMLINK | fcntl::O_CLOEXEC) {
Ok(ok) => ok,
Err(_) => return -1,
};
@@ -856,8 +835,8 @@ impl Pal for Sys {
}
fn realpath(pathname: &CStr, out: &mut [u8]) -> c_int {
let file = match File::open(pathname, fcntl::O_PATH) {
Ok(fd) => fd,
let file = match File::open(pathname, fcntl::O_PATH | fcntl::O_CLOEXEC) {
Ok(ok) => ok,
Err(_) => return -1,
};
@@ -876,13 +855,9 @@ impl Pal for Sys {
}
fn rename(oldpath: &CStr, newpath: &CStr) -> c_int {
match syscall::open(oldpath.to_bytes(), O_WRONLY | O_CLOEXEC) {
Ok(fd) => {
let retval = syscall::frename(fd, newpath.to_bytes());
let _ = syscall::close(fd);
e(retval) as c_int
}
err => e(err) as c_int,
match File::open(oldpath, fcntl::O_WRONLY | fcntl::O_CLOEXEC) {
Ok(file) => e(syscall::frename(*file as usize, newpath.to_bytes())) as c_int,
Err(_) => -1,
}
}
@@ -1040,11 +1015,12 @@ impl Pal for Sys {
}
fn symlink(path1: &CStr, path2: &CStr) -> c_int {
let mut file = match File::open(
let mut file = match File::create(
path2,
fcntl::O_CREAT | fcntl::O_WRONLY | fcntl::O_SYMLINK | 0o777,
fcntl::O_WRONLY | fcntl::O_SYMLINK | fcntl::O_CLOEXEC,
0o777,
) {
Ok(fd) => fd,
Ok(ok) => ok,
Err(_) => return -1,
};
@@ -1095,9 +1071,9 @@ impl Pal for Sys {
fn uname(utsname: *mut utsname) -> c_int {
fn inner(utsname: *mut utsname) -> CoreResult<(), i32> {
let file_path = c_str!("sys:uname\0");
let file_path = c_str!("sys:uname");
let mut file = match File::open(file_path, fcntl::O_RDONLY | fcntl::O_CLOEXEC) {
Ok(file) => file,
Ok(ok) => ok,
Err(_) => return Err(EIO),
};
let mut lines = BufReader::new(&mut file).lines();
+1 -1
View File
@@ -8,5 +8,5 @@ int main() {
}
char buffer[256];
printf("%s", fgets(buffer, 256, f));
printf("ftell: %d\n", ftello(f));
printf("ftell: %ld\n", ftello(f));
}
+1
View File
@@ -1,3 +1,4 @@
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
+1 -1
View File
@@ -14,6 +14,6 @@ int main() {
printf("release: '%s'\n", system_info.release);
printf("version: '%s'\n", system_info.version);
printf("machine: '%s'\n", system_info.machine);
printf("domainname: '%s'\n", system_info.domainname);
//printf("domainname: '%s'\n", system_info.domainname);
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
int main(int argc, char** argv) {
time_t a = 0;
tm *time_info = gmtime(&a);
struct tm *time_info = gmtime(&a);
char *time_string = asctime(time_info);
+2 -2
View File
@@ -5,10 +5,10 @@
int main(int argc, char** argv) {
time_t a = 0;
tm expected = { .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, .tm_year = 70,
struct tm expected = { .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, .tm_year = 70,
.tm_wday = 4, .tm_yday = 0, .tm_isdst = 0, .tm_gmtoff = 0, .tm_zone = "UTC" };
tm *info = gmtime(&a);
struct tm *info = gmtime(&a);
if (info->tm_sec != expected.tm_sec || info->tm_min != expected.tm_min ||
info->tm_hour != expected.tm_hour || info->tm_mday != expected.tm_mday ||
info->tm_year != expected.tm_year || info->tm_wday != expected.tm_wday ||
+1 -1
View File
@@ -2,7 +2,7 @@
#include <stdio.h>
int main(int argc, char** argv) {
timespec tm = {0, 0};
struct timespec tm = {0, 0};
clock_gettime(CLOCK_REALTIME, &tm);
perror("clock_gettime");
time(NULL);
+2 -2
View File
@@ -32,7 +32,7 @@ int main()
perror("pipe write");
return 1;
} else if (bytes != strlen(outstring)) {
fprintf(stderr, "pipe write: %d != %d\n", bytes, strlen(outstring));
fprintf(stderr, "pipe write: %d != %ld\n", bytes, strlen(outstring));
return 1;
}
@@ -57,7 +57,7 @@ int main()
perror("pipe read");
return 1;
} else if (bytes != strlen(outstring)) {
fprintf(stderr, "pipe read: %d != %d\n", bytes, strlen(outstring));
fprintf(stderr, "pipe read: %d != %ld\n", bytes, strlen(outstring));
return 1;
} else if (memcmp(instring, outstring, sizeof(outstring)) != 0) {
fprintf(stderr, "pipe read does not match pipe write\n");
+1 -1
View File
@@ -7,7 +7,7 @@ int main(int argc, char** argv) {
perror("sleep");
usleep(1000);
perror("usleep");
timespec tm = {0, 10000};
struct timespec tm = {0, 10000};
nanosleep(&tm, NULL);
perror("nanosleep");
return 0;
+5 -4
View File
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#include <wchar.h>
void print_as_wide(const char* mbstr)
{
mbstate_t state;
@@ -10,14 +11,14 @@ void print_as_wide(const char* mbstr)
mbsrtowcs(&wstr[0], &mbstr, len, &state);
//Should be 5
printf("The length, including '\\0': %i \n",len);
printf("The length, including '\\0': %li \n",len);
//missing wprintf to print this wide string
//wprintf(L"The wide string: %ls \n", &wstr[0]);
}
int main()
{
const char* mbstr = u8"z\u00df\u6c34\U0001f34c"; // or u8"zß水🍌"
print_as_wide(mbstr);
}
}