From 8dce85d6635d577b7dc4751db1143d39cd6b30c7 Mon Sep 17 00:00:00 2001 From: LegionMammal978 Date: Mon, 12 Dec 2022 19:02:00 -0500 Subject: [PATCH] Add missing functions from ISO C90 and C99, fix definition of clock_t --- libc-test/semver/android.txt | 16 ++++++++- libc-test/semver/apple.txt | 3 -- libc-test/semver/dragonfly.txt | 3 -- libc-test/semver/freebsd.txt | 3 -- libc-test/semver/fuchsia.txt | 12 +++++++ libc-test/semver/linux.txt | 3 -- libc-test/semver/netbsd.txt | 3 -- libc-test/semver/openbsd.txt | 3 -- libc-test/semver/unix.txt | 13 +++++++ libc-test/semver/windows.txt | 11 ++++++ src/fuchsia/mod.rs | 33 +++++++++++++++-- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/aarch64.rs | 1 + src/unix/bsd/freebsdlike/freebsd/arm.rs | 1 + src/unix/bsd/freebsdlike/freebsd/mod.rs | 1 - src/unix/bsd/freebsdlike/freebsd/powerpc.rs | 1 + src/unix/bsd/freebsdlike/freebsd/powerpc64.rs | 1 + src/unix/bsd/freebsdlike/freebsd/riscv64.rs | 1 + src/unix/bsd/freebsdlike/freebsd/x86.rs | 1 + .../bsd/freebsdlike/freebsd/x86_64/mod.rs | 1 + src/unix/bsd/mod.rs | 3 -- src/unix/haiku/mod.rs | 3 -- src/unix/hermit/mod.rs | 3 -- src/unix/linux_like/emscripten/mod.rs | 5 +-- src/unix/linux_like/linux/gnu/b32/mod.rs | 2 +- src/unix/linux_like/linux/mod.rs | 3 -- src/unix/linux_like/linux/uclibc/arm/mod.rs | 1 - .../linux/uclibc/mips/mips32/mod.rs | 1 - src/unix/linux_like/linux/uclibc/mod.rs | 1 + .../linux_like/linux/uclibc/x86_64/mod.rs | 1 - src/unix/mod.rs | 34 ++++++++++++++++++ src/unix/newlib/aarch64/mod.rs | 1 - src/unix/newlib/arm/mod.rs | 1 - src/unix/newlib/espidf/mod.rs | 1 - src/unix/newlib/horizon/mod.rs | 1 - src/unix/newlib/mod.rs | 4 +-- src/unix/newlib/powerpc/mod.rs | 1 - src/unix/solarish/mod.rs | 3 -- src/vxworks/mod.rs | 31 ++++++++++++++++ src/wasi.rs | 25 ++++++++++++- src/windows/mod.rs | 35 ++++++++++++++++--- 41 files changed, 213 insertions(+), 60 deletions(-) diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index 815a97eeb3c49..4db9d1ed70ff1 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -2663,6 +2663,7 @@ W_STOPCODE XFS_SUPER_MAGIC XTABS X_OK +_Exit _IOFBF _IOLBF _IONBF @@ -2839,6 +2840,7 @@ __system_property_get __system_property_set _exit abort +abs accept accept4 access @@ -2854,7 +2856,10 @@ arphdr arpreq arpreq_old atexit +atof atoi +atol +atoll bind blkcnt_t blksize_t @@ -2888,6 +2893,7 @@ chown chroot clearenv clearerr +clock clock_getcpuclockid clock_getres clock_gettime @@ -2910,6 +2916,7 @@ difftime dirent dirent64 dirfd +div dladdr dlclose dlerror @@ -3010,6 +3017,7 @@ fwrite gai_strerror genlmsghdr getaddrinfo +getc getchar getchar_unlocked getcwd @@ -3119,15 +3127,19 @@ itimerval key_t kill killpg +labs lastlog lchown lconv +ldiv lgetxattr linger link linkat listen listxattr +llabs +lldiv llistxattr locale_t localeconv @@ -3318,7 +3330,7 @@ ptrace_peeksiginfo_args ptrdiff_t ptsname ptsname_r - +putc putchar putchar_unlocked putenv @@ -3504,7 +3516,9 @@ strtod strtof strtok strtol +strtoll strtoul +strtoull strxfrm suseconds_t swapoff diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 329c8cdaac15b..db55a63b889b2 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1804,7 +1804,6 @@ _dyld_get_image_header _dyld_get_image_name _dyld_get_image_vmaddr_slide _dyld_image_count -abs acct aio_cancel aio_error @@ -1818,7 +1817,6 @@ arc4random arc4random_buf arc4random_uniform arphdr -atof attrgroup_t attribute_set_t attrlist @@ -1938,7 +1936,6 @@ kevent64_s key_t killpg kqueue -labs lio_listio listxattr load_command diff --git a/libc-test/semver/dragonfly.txt b/libc-test/semver/dragonfly.txt index 8d0172c112adf..2fb1ff7c9fd9f 100644 --- a/libc-test/semver/dragonfly.txt +++ b/libc-test/semver/dragonfly.txt @@ -1204,7 +1204,6 @@ _UTX_IDSIZE _UTX_LINESIZE _UTX_USERSIZE __errno_location -abs accept_filter_arg accept4 acct @@ -1221,7 +1220,6 @@ arc4random arc4random_buf arc4random_uniform arphdr -atof backtrace backtrace_symbols backtrace_symbols_fd @@ -1346,7 +1344,6 @@ kvm_vm_map_entry_first kvm_vm_map_entry_next kvm_write kqueue -labs lastlog lchflags lcong48 diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 8a7756c2a2812..532e0359eaa21 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -1476,7 +1476,6 @@ __error __xuname _sem _umtx_op -abs accept4 accept_filter_arg acct @@ -1493,7 +1492,6 @@ arc4random arc4random_buf arc4random_uniform arphdr -atof au_asid_t au_id_t au_mask_t @@ -1672,7 +1670,6 @@ kinfo_vmentry kqueue kld_isloaded kld_load -labs lchflags lcong48 lio_listio diff --git a/libc-test/semver/fuchsia.txt b/libc-test/semver/fuchsia.txt index a4ff41defe586..b6a58a8365809 100644 --- a/libc-test/semver/fuchsia.txt +++ b/libc-test/semver/fuchsia.txt @@ -1003,6 +1003,7 @@ XATTR_REPLACE XTABS YESEXPR YESSTR +_Exit _IOFBF _IOLBF _IONBF @@ -1168,18 +1169,24 @@ accept4 acct aiocb atof +atoi +atol +atoll blkcnt64_t brk clearenv +clock clock_getres clock_nanosleep clock_settime +clock_t clone cmsghdr cpu_set_t daemon dirent64 dirfd +div dl_iterate_phdr dl_phdr_info dqblk @@ -1245,6 +1252,9 @@ ipc_perm itimerspec key_t labs +ldiv +llabs +lldiv loff_t lutimes madvise @@ -1366,6 +1376,8 @@ stat64 statfs statfs64 statvfs64 +strtoll +strtoull swapoff swapon sync diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 087b1fc10c586..7c70a052c6837 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2859,7 +2859,6 @@ __u16 __u32 __u64 __u8 -abs accept4 acct addmntent @@ -2868,7 +2867,6 @@ arpd_request arphdr arpreq arpreq_old -atof blkcnt64_t brk bsearch @@ -3022,7 +3020,6 @@ j1939_filter jrand48 key_t killpg -labs lcong48 lgetxattr listxattr diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index d6d519fd58ddb..773592ca5d9d6 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -1150,7 +1150,6 @@ _cpuset_isset _cpuset_set _cpuset_zero _lwp_self -abs accept4 accept_filter_arg acct @@ -1166,7 +1165,6 @@ arc4random arc4random_buf arc4random_uniform arphdr -atof bsearch chflags chroot @@ -1303,7 +1301,6 @@ kinfo_proc2 kinfo_vmentry kqueue kqueue1 -labs lastlog lastlogx lchflags diff --git a/libc-test/semver/openbsd.txt b/libc-test/semver/openbsd.txt index 0dcd2b40c8ae4..692c93d915bcd 100644 --- a/libc-test/semver/openbsd.txt +++ b/libc-test/semver/openbsd.txt @@ -970,14 +970,12 @@ _SC_XOPEN_UNIX _SC_XOPEN_UUCP _SC_XOPEN_VERSION __errno -abs accept4 acct arc4random arc4random_buf arc4random_uniform arphdr -atof backtrace backtrace_symbols backtrace_symbols_fd @@ -1078,7 +1076,6 @@ killpg kinfo_proc kinfo_vmentry kqueue -labs lastlog lcong48 lcong48_deterministic diff --git a/libc-test/semver/unix.txt b/libc-test/semver/unix.txt index 269c0ff0e5846..ccae639ec836d 100644 --- a/libc-test/semver/unix.txt +++ b/libc-test/semver/unix.txt @@ -422,6 +422,7 @@ WTERMSIG WUNTRACED W_OK X_OK +_Exit _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON @@ -451,7 +452,10 @@ access addrinfo alarm atexit +atof atoi +atol +atoll bind blkcnt_t blksize_t @@ -480,6 +484,7 @@ cfsetspeed chdir chmod chown +clock clock_gettime clock_t clockid_t @@ -490,6 +495,7 @@ connect creat dev_t dirent +div dladdr dlclose dlerror @@ -548,6 +554,7 @@ futimens fwrite gai_strerror getaddrinfo +getc getchar getchar_unlocked getcwd @@ -614,10 +621,13 @@ itimerval kill lchown lconv +ldiv linger link linkat listen +llabs +lldiv locale_t localeconv localtime @@ -715,6 +725,7 @@ pthread_setspecific pthread_t ptrdiff_t ptsname +putc putchar putchar_unlocked putenv @@ -818,7 +829,9 @@ strtod strtof strtok strtol +strtoll strtoul +strtoull strxfrm suseconds_t symlink diff --git a/libc-test/semver/windows.txt b/libc-test/semver/windows.txt index 1ddf031b1440f..b586138de0271 100644 --- a/libc-test/semver/windows.txt +++ b/libc-test/semver/windows.txt @@ -152,6 +152,8 @@ aligned_free atexit atof atoi +atol +atoll bind c_char c_double @@ -170,12 +172,14 @@ c_void calloc chdir chmod +clock clock_t close commit connect creat dev_t +div dup dup2 errno_t @@ -211,6 +215,7 @@ fstat ftell fwrite get_osfhandle +getc getchar getcwd getenv @@ -240,7 +245,10 @@ isspace isupper isxdigit labs +ldiv listen +llabs +lldiv localtime_s lseek lseek64 @@ -260,6 +268,7 @@ pipe popen printf ptrdiff_t +putc putchar putenv putenv_s @@ -307,7 +316,9 @@ strtod strtof strtok strtol +strtoll strtoul +strtoull strxfrm system time diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 7a9edada1f50b..c8281e03b1ace 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -979,6 +979,21 @@ s_no_extra_traits! { pub sigev_notify_attributes: *mut pthread_attr_t, pub __pad: [::c_char; 56 - 3 * 8 /* 8 == sizeof(long) */], } + + pub struct div_t { + pub quot: ::c_int, + pub rem: ::c_int, + } + + pub struct ldiv_t { + pub quot: ::c_long, + pub rem: ::c_long, + } + + pub struct lldiv_t { + pub quot: ::c_longlong, + pub rem: ::c_longlong, + } } cfg_if! { @@ -3390,6 +3405,8 @@ extern "C" { pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; + pub fn getc(stream: *mut FILE) -> c_int; + pub fn putc(c: c_int, stream: *mut FILE) -> c_int; pub fn puts(s: *const c_char) -> c_int; pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t; @@ -3402,17 +3419,29 @@ extern "C" { pub fn feof(stream: *mut FILE) -> c_int; pub fn ferror(stream: *mut FILE) -> c_int; pub fn perror(s: *const c_char); + pub fn abs(i: c_int) -> c_int; + pub fn labs(i: c_long) -> c_long; + pub fn llabs(i: c_longlong) -> c_longlong; + pub fn div(numer: c_int, denom: c_int) -> div_t; + pub fn ldiv(numer: c_long, denom: c_long) -> ldiv_t; + pub fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t; + pub fn atof(s: *const c_char) -> c_double; pub fn atoi(s: *const c_char) -> c_int; + pub fn atol(s: *const c_char) -> c_long; + pub fn atoll(s: *const c_char) -> c_longlong; pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; pub fn strtof(s: *const c_char, endp: *mut *mut c_char) -> c_float; pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long; + pub fn strtoll(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_longlong; pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong; + pub fn strtoull(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulonglong; pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; pub fn malloc(size: size_t) -> *mut c_void; pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; pub fn free(p: *mut c_void); pub fn abort() -> !; pub fn exit(status: c_int) -> !; + pub fn _Exit(status: c_int) -> !; pub fn _exit(status: c_int) -> !; pub fn atexit(cb: extern "C" fn()) -> c_int; pub fn system(s: *const c_char) -> c_int; @@ -3447,9 +3476,6 @@ extern "C" { pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn abs(i: c_int) -> c_int; - pub fn atof(s: *const c_char) -> c_double; - pub fn labs(i: c_long) -> c_long; pub fn rand() -> c_int; pub fn srand(seed: c_uint); @@ -3760,6 +3786,7 @@ extern "C" { pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char; pub fn res_init() -> ::c_int; + pub fn clock() -> ::clock_t; pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; pub fn mktime(tm: *mut tm) -> time_t; diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 70fe6e2edd03b..b2acea4ceacb7 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -1,7 +1,7 @@ pub type dev_t = u32; pub type c_char = i8; pub type wchar_t = i32; -pub type clock_t = u64; +pub type clock_t = ::c_ulong; pub type ino_t = u64; pub type lwpid_t = i32; pub type nlink_t = u32; diff --git a/src/unix/bsd/freebsdlike/freebsd/aarch64.rs b/src/unix/bsd/freebsdlike/freebsd/aarch64.rs index e8be8815c028e..a3c4fb37fd6bc 100644 --- a/src/unix/bsd/freebsdlike/freebsd/aarch64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/aarch64.rs @@ -2,6 +2,7 @@ pub type c_char = u8; pub type c_long = i64; pub type c_ulong = u64; pub type wchar_t = u32; +pub type clock_t = i32; pub type time_t = i64; pub type suseconds_t = i64; pub type register_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/arm.rs b/src/unix/bsd/freebsdlike/freebsd/arm.rs index 300b3dd45ca9d..d71b4e02c497f 100644 --- a/src/unix/bsd/freebsdlike/freebsd/arm.rs +++ b/src/unix/bsd/freebsdlike/freebsd/arm.rs @@ -2,6 +2,7 @@ pub type c_char = u8; pub type c_long = i32; pub type c_ulong = u32; pub type wchar_t = u32; +pub type clock_t = u32; pub type time_t = i64; pub type suseconds_t = i32; pub type register_t = i32; diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 2a4fbbf05f3a7..0937f8edfcfb8 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -1,5 +1,4 @@ pub type fflags_t = u32; -pub type clock_t = i32; pub type vm_prot_t = u_char; pub type kvaddr_t = u64; diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs index a0120c337e0ad..d8f1aa44b4713 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs @@ -2,6 +2,7 @@ pub type c_char = u8; pub type c_long = i32; pub type c_ulong = u32; pub type wchar_t = i32; +pub type clock_t = u32; pub type time_t = i64; pub type suseconds_t = i32; pub type register_t = i32; diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs index 7f5b9752264e3..15e97065fd83a 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs @@ -2,6 +2,7 @@ pub type c_char = u8; pub type c_long = i64; pub type c_ulong = u64; pub type wchar_t = i32; +pub type clock_t = u32; pub type time_t = i64; pub type suseconds_t = i64; pub type register_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/riscv64.rs b/src/unix/bsd/freebsdlike/freebsd/riscv64.rs index f9fa1c2750b22..e912ce0292d87 100644 --- a/src/unix/bsd/freebsdlike/freebsd/riscv64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/riscv64.rs @@ -2,6 +2,7 @@ pub type c_char = u8; pub type c_long = i64; pub type c_ulong = u64; pub type wchar_t = ::c_int; +pub type clock_t = i32; pub type time_t = i64; pub type suseconds_t = ::c_long; pub type register_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86.rs b/src/unix/bsd/freebsdlike/freebsd/x86.rs index d3a3f34b0f61f..2983e852956b4 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86.rs @@ -2,6 +2,7 @@ pub type c_char = i8; pub type c_long = i32; pub type c_ulong = u32; pub type wchar_t = i32; +pub type clock_t = ::c_ulong; pub type time_t = i32; pub type suseconds_t = i32; pub type register_t = i32; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs b/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs index ae1fcf781047a..65a5b3616fb9b 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs @@ -2,6 +2,7 @@ pub type c_char = i8; pub type c_long = i64; pub type c_ulong = u64; pub type wchar_t = i32; +pub type clock_t = i32; pub type time_t = i64; pub type suseconds_t = i64; pub type register_t = i64; diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index d49e3c44028c9..ccaff0422a517 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -612,9 +612,6 @@ extern "C" { pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; #[cfg_attr( all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), link_name = "rand@FBSD_1.0" diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index 005b1d9df5c56..4cbe5bd7bea6b 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -1591,9 +1591,6 @@ extern "C" { pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; pub fn _errnop() -> *mut ::c_int; - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; pub fn rand() -> ::c_int; pub fn srand(seed: ::c_uint); pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; diff --git a/src/unix/hermit/mod.rs b/src/unix/hermit/mod.rs index eedfd28a49c23..c4089ee482c62 100644 --- a/src/unix/hermit/mod.rs +++ b/src/unix/hermit/mod.rs @@ -965,9 +965,6 @@ extern "C" { pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, value: ::c_uint) -> ::c_int; - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; pub fn rand() -> ::c_int; pub fn srand(seed: ::c_uint); diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 11fbb31c3830d..5fa3a4c76d7a3 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -19,7 +19,7 @@ pub type idtype_t = ::c_uint; pub type loff_t = i64; pub type pthread_key_t = ::c_uint; -pub type clock_t = c_long; +pub type clock_t = ::c_int; pub type time_t = c_long; pub type suseconds_t = c_long; pub type ino_t = u64; @@ -1762,9 +1762,6 @@ extern "C" { pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; pub fn rand() -> ::c_int; pub fn srand(seed: ::c_uint); diff --git a/src/unix/linux_like/linux/gnu/b32/mod.rs b/src/unix/linux_like/linux/gnu/b32/mod.rs index ad0d64c51d5b4..e9b055e955744 100644 --- a/src/unix/linux_like/linux/gnu/b32/mod.rs +++ b/src/unix/linux_like/linux/gnu/b32/mod.rs @@ -4,7 +4,7 @@ use pthread_mutex_t; pub type c_long = i32; pub type c_ulong = u32; -pub type clock_t = i32; +pub type clock_t = ::c_long; pub type shmatt_t = ::c_ulong; pub type msgqnum_t = ::c_ulong; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 743927e5172f2..c20385cf47b72 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -3803,9 +3803,6 @@ extern "C" { #[cfg_attr(not(target_env = "musl"), link_name = "__xpg_strerror_r")] pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; pub fn rand() -> ::c_int; pub fn srand(seed: ::c_uint); diff --git a/src/unix/linux_like/linux/uclibc/arm/mod.rs b/src/unix/linux_like/linux/uclibc/arm/mod.rs index 25125bcc9b3d8..f7a23338bb4d6 100644 --- a/src/unix/linux_like/linux/uclibc/arm/mod.rs +++ b/src/unix/linux_like/linux/uclibc/arm/mod.rs @@ -4,7 +4,6 @@ pub type c_long = i32; pub type c_ulong = u32; pub type time_t = ::c_long; -pub type clock_t = ::c_long; pub type fsblkcnt_t = ::c_ulong; pub type fsfilcnt_t = ::c_ulong; pub type ino_t = ::c_ulong; diff --git a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs index 7f9d3c03137ac..2bcce21bbb094 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs @@ -1,7 +1,6 @@ pub type c_char = i8; pub type c_long = i32; pub type c_ulong = u32; -pub type clock_t = i32; pub type time_t = i32; pub type suseconds_t = i32; pub type wchar_t = i32; diff --git a/src/unix/linux_like/linux/uclibc/mod.rs b/src/unix/linux_like/linux/uclibc/mod.rs index 4a01e0cd81c85..e3ede30209007 100644 --- a/src/unix/linux_like/linux/uclibc/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mod.rs @@ -1,3 +1,4 @@ +pub type clock_t = ::c_long; pub type shmatt_t = ::c_ulong; pub type msgqnum_t = ::c_ulong; pub type msglen_t = ::c_ulong; diff --git a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs index 43ac79296b368..9bd1ab06cb577 100644 --- a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs +++ b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs @@ -1,7 +1,6 @@ //! Definitions for uclibc on 64bit systems pub type blkcnt_t = i64; pub type blksize_t = i64; -pub type clock_t = i64; pub type c_char = u8; pub type c_long = i64; pub type c_ulong = u64; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index fb9ebf792e53d..28e24cf85b226 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -201,6 +201,21 @@ s! { pub p_aliases: *mut *mut ::c_char, pub p_proto: ::c_int, } + + pub struct div_t { + pub quot: ::c_int, + pub rem: ::c_int, + } + + pub struct ldiv_t { + pub quot: ::c_long, + pub rem: ::c_long, + } + + pub struct lldiv_t { + pub quot: ::c_longlong, + pub rem: ::c_longlong, + } } pub const INT_MIN: c_int = -2147483648; @@ -473,6 +488,8 @@ extern "C" { link_name = "fputs$UNIX2003" )] pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; + pub fn getc(stream: *mut FILE) -> c_int; + pub fn putc(c: c_int, stream: *mut FILE) -> c_int; pub fn puts(s: *const c_char) -> c_int; pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t; @@ -492,7 +509,16 @@ extern "C" { pub fn ferror(stream: *mut FILE) -> c_int; pub fn clearerr(stream: *mut FILE); pub fn perror(s: *const c_char); + pub fn abs(i: c_int) -> c_int; + pub fn labs(i: c_long) -> c_long; + pub fn llabs(i: c_longlong) -> c_longlong; + pub fn div(numer: c_int, denom: c_int) -> div_t; + pub fn ldiv(numer: c_long, denom: c_long) -> ldiv_t; + pub fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t; + pub fn atof(s: *const c_char) -> c_double; pub fn atoi(s: *const c_char) -> c_int; + pub fn atol(s: *const c_char) -> c_long; + pub fn atoll(s: *const c_char) -> c_longlong; #[cfg_attr( all(target_os = "macos", target_arch = "x86"), link_name = "strtod$UNIX2003" @@ -500,13 +526,16 @@ extern "C" { pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; pub fn strtof(s: *const c_char, endp: *mut *mut c_char) -> c_float; pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long; + pub fn strtoll(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_longlong; pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong; + pub fn strtoull(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulonglong; pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; pub fn malloc(size: size_t) -> *mut c_void; pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; pub fn free(p: *mut c_void); pub fn abort() -> !; pub fn exit(status: c_int) -> !; + pub fn _Exit(status: c_int) -> !; pub fn _exit(status: c_int) -> !; pub fn atexit(cb: extern "C" fn()) -> c_int; #[cfg_attr( @@ -1215,6 +1244,11 @@ extern "C" { )] pub fn res_init() -> ::c_int; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "clock$UNIX2003" + )] + pub fn clock() -> ::clock_t; #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")] #[cfg_attr(target_env = "musl", allow(deprecated))] // FIXME: for `time_t` diff --git a/src/unix/newlib/aarch64/mod.rs b/src/unix/newlib/aarch64/mod.rs index d686b3692d86d..2c12037ac817c 100644 --- a/src/unix/newlib/aarch64/mod.rs +++ b/src/unix/newlib/aarch64/mod.rs @@ -1,4 +1,3 @@ -pub type clock_t = ::c_long; pub type c_char = u8; pub type wchar_t = u32; diff --git a/src/unix/newlib/arm/mod.rs b/src/unix/newlib/arm/mod.rs index f644349cb997f..694f4e5dc3082 100644 --- a/src/unix/newlib/arm/mod.rs +++ b/src/unix/newlib/arm/mod.rs @@ -1,4 +1,3 @@ -pub type clock_t = ::c_long; pub type c_char = u8; pub type wchar_t = u32; diff --git a/src/unix/newlib/espidf/mod.rs b/src/unix/newlib/espidf/mod.rs index 804cd66454f46..a07aa2f30c942 100644 --- a/src/unix/newlib/espidf/mod.rs +++ b/src/unix/newlib/espidf/mod.rs @@ -1,4 +1,3 @@ -pub type clock_t = ::c_ulong; pub type c_char = i8; pub type wchar_t = u32; diff --git a/src/unix/newlib/horizon/mod.rs b/src/unix/newlib/horizon/mod.rs index bcb93ad9df4f1..dc46b437f5ddc 100644 --- a/src/unix/newlib/horizon/mod.rs +++ b/src/unix/newlib/horizon/mod.rs @@ -14,7 +14,6 @@ pub type u_long = c_ulong; pub type ushort = ::c_ushort; pub type uint = ::c_uint; pub type ulong = c_ulong; -pub type clock_t = c_ulong; pub type daddr_t = c_long; pub type caddr_t = *mut c_char; pub type sbintime_t = ::c_longlong; diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index 1a694691a635f..150416c5f7f78 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -1,3 +1,4 @@ +pub type clock_t = ::c_ulong; pub type blkcnt_t = i32; pub type blksize_t = i32; pub type clockid_t = ::c_ulong; @@ -620,9 +621,6 @@ extern "C" { pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, value: ::c_uint) -> ::c_int; - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; pub fn rand() -> ::c_int; pub fn srand(seed: ::c_uint); diff --git a/src/unix/newlib/powerpc/mod.rs b/src/unix/newlib/powerpc/mod.rs index 6bed1ce27acbf..5b5244f67d5a7 100644 --- a/src/unix/newlib/powerpc/mod.rs +++ b/src/unix/newlib/powerpc/mod.rs @@ -1,4 +1,3 @@ -pub type clock_t = ::c_ulong; pub type c_char = u8; pub type wchar_t = ::c_int; diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index abe304e8ea52b..32da7773b1d67 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -2708,11 +2708,8 @@ extern "C" { pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, value: ::c_uint) -> ::c_int; - pub fn abs(i: ::c_int) -> ::c_int; pub fn acct(filename: *const ::c_char) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - pub fn labs(i: ::c_long) -> ::c_long; pub fn rand() -> ::c_int; pub fn srand(seed: ::c_uint); pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int; diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index 2772d68d2f4b1..d142bc38efb66 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -42,6 +42,7 @@ pub type ino_t = ::c_ulong; pub type rlim_t = ::c_ulong; pub type suseconds_t = ::c_long; +pub type clock_t = ::c_long; pub type time_t = ::c_long; pub type errno_t = ::c_int; @@ -411,6 +412,21 @@ s! { pub mq_flags: ::c_long, pub mq_curmsgs: ::c_long, } + + pub struct div_t { + pub quot: ::c_int, + pub rem: ::c_int, + } + + pub struct ldiv_t { + pub quot: ::c_long, + pub rem: ::c_long, + } + + pub struct lldiv_t { + pub quot: ::c_longlong, + pub rem: ::c_longlong, + } } s_no_extra_traits! { @@ -1107,6 +1123,8 @@ extern "C" { pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; + pub fn getc(stream: *mut FILE) -> c_int; + pub fn putc(c: c_int, stream: *mut FILE) -> c_int; pub fn puts(s: *const c_char) -> c_int; pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t; @@ -1119,17 +1137,29 @@ extern "C" { pub fn feof(stream: *mut FILE) -> c_int; pub fn ferror(stream: *mut FILE) -> c_int; pub fn perror(s: *const c_char); + pub fn abs(i: c_int) -> c_int; + pub fn labs(i: c_long) -> c_long; + pub fn llabs(i: c_longlong) -> c_longlong; + pub fn div(numer: c_int, denom: c_int) -> div_t; + pub fn ldiv(numer: c_long, denom: c_long) -> ldiv_t; + pub fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t; + pub fn atof(s: *const c_char) -> c_double; pub fn atoi(s: *const c_char) -> c_int; + pub fn atol(s: *const c_char) -> c_long; + pub fn atoll(s: *const c_char) -> c_longlong; pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; pub fn strtof(s: *const c_char, endp: *mut *mut c_char) -> c_float; pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long; + pub fn strtoll(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_longlong; pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong; + pub fn strtoull(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulonglong; pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; pub fn malloc(size: size_t) -> *mut c_void; pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; pub fn free(p: *mut c_void); pub fn abort() -> !; pub fn exit(status: c_int) -> !; + pub fn _Exit(status: c_int) -> !; pub fn atexit(cb: extern "C" fn()) -> c_int; pub fn system(s: *const c_char) -> c_int; pub fn getenv(s: *const c_char) -> *mut c_char; @@ -1242,6 +1272,7 @@ extern "C" { pub fn dladdr(addr: *mut ::c_void, info: *mut Dl_info) -> ::c_int; // time.h + pub fn clock() -> ::clock_t; pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; pub fn mktime(tm: *mut tm) -> time_t; diff --git a/src/wasi.rs b/src/wasi.rs index c5dd670477129..345ced81b0713 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -174,6 +174,21 @@ s! { pub st_ctim: timespec, __reserved: [c_longlong; 3], } + + pub struct div_t { + pub quot: ::c_int, + pub rem: ::c_int, + } + + pub struct ldiv_t { + pub quot: ::c_long, + pub rem: ::c_long, + } + + pub struct lldiv_t { + pub quot: ::c_longlong, + pub rem: ::c_longlong, + } } // Declare dirent outside of s! so that it doesn't implement Copy, Eq, Hash, @@ -540,12 +555,19 @@ extern "C" { pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, size: size_t) -> c_int; pub fn setbuf(stream: *mut FILE, buf: *mut c_char); pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; - pub fn atoi(s: *const c_char) -> c_int; + pub fn div(numer: c_int, denom: c_int) -> div_t; + pub fn ldiv(numer: c_long, denom: c_long) -> ldiv_t; + pub fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t; pub fn atof(s: *const c_char) -> c_double; + pub fn atoi(s: *const c_char) -> c_int; + pub fn atol(s: *const c_char) -> c_long; + pub fn atoll(s: *const c_char) -> c_longlong; pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; pub fn strtof(s: *const c_char, endp: *mut *mut c_char) -> c_float; pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long; + pub fn strtoll(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_longlong; pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong; + pub fn strtoull(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulonglong; pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char; @@ -714,6 +736,7 @@ extern "C" { pub fn memrchr(cx: *const ::c_void, c: ::c_int, n: ::size_t) -> *mut ::c_void; pub fn abs(i: c_int) -> c_int; pub fn labs(i: c_long) -> c_long; + pub fn llabs(i: c_longlong) -> c_longlong; pub fn duplocale(base: ::locale_t) -> ::locale_t; pub fn freelocale(loc: ::locale_t); pub fn newlocale(mask: ::c_int, locale: *const ::c_char, base: ::locale_t) -> ::locale_t; diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 916019b1f211b..739dc82ba2cfe 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -25,7 +25,7 @@ pub type c_long = i32; pub type c_ulong = u32; pub type wchar_t = u16; -pub type clock_t = i32; +pub type clock_t = ::c_long; pub type errno_t = ::c_int; @@ -100,6 +100,21 @@ s! { pub sa_family: c_ushort, pub sa_data: [c_char; 14], } + + pub struct div_t { + pub quot: ::c_int, + pub rem: ::c_int, + } + + pub struct ldiv_t { + pub quot: ::c_long, + pub rem: ::c_long, + } + + pub struct lldiv_t { + pub quot: ::c_longlong, + pub rem: ::c_longlong, + } } pub const INT_MIN: c_int = -2147483648; @@ -317,6 +332,8 @@ extern "C" { pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; + pub fn getc(stream: *mut FILE) -> c_int; + pub fn putc(c: c_int, stream: *mut FILE) -> c_int; pub fn puts(s: *const c_char) -> c_int; pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t; @@ -329,17 +346,29 @@ extern "C" { pub fn feof(stream: *mut FILE) -> c_int; pub fn ferror(stream: *mut FILE) -> c_int; pub fn perror(s: *const c_char); + pub fn abs(i: c_int) -> c_int; + pub fn labs(i: c_long) -> c_long; + pub fn llabs(i: c_longlong) -> c_longlong; + pub fn div(numer: c_int, denom: c_int) -> div_t; + pub fn ldiv(numer: c_long, denom: c_long) -> ldiv_t; + pub fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t; + pub fn atof(s: *const c_char) -> c_double; pub fn atoi(s: *const c_char) -> c_int; + pub fn atol(s: *const c_char) -> c_long; + pub fn atoll(s: *const c_char) -> c_longlong; pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; pub fn strtof(s: *const c_char, endp: *mut *mut c_char) -> c_float; pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long; + pub fn strtoll(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_longlong; pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong; + pub fn strtoull(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulonglong; pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; pub fn malloc(size: size_t) -> *mut c_void; pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; pub fn free(p: *mut c_void); pub fn abort() -> !; pub fn exit(status: c_int) -> !; + pub fn _Exit(status: c_int) -> !; pub fn _exit(status: c_int) -> !; pub fn atexit(cb: extern "C" fn()) -> c_int; pub fn system(s: *const c_char) -> c_int; @@ -373,15 +402,13 @@ extern "C" { pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn abs(i: c_int) -> c_int; - pub fn atof(s: *const c_char) -> c_double; - pub fn labs(i: c_long) -> c_long; pub fn rand() -> c_int; pub fn srand(seed: c_uint); pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; pub fn raise(signum: c_int) -> c_int; + pub fn clock() -> ::clock_t; #[link_name = "_gmtime64_s"] pub fn gmtime_s(destTime: *mut tm, srcTime: *const time_t) -> ::c_int; #[link_name = "_localtime64_s"]