Skip to content
Snippets Groups Projects
Commit 95424b3c authored by Paul Sajna's avatar Paul Sajna
Browse files

Merge branch 'master' of github.com:redox-os/relibc

parents ffd9176c 851e4d39
No related branches found
No related tags found
1 merge request!28implement perror
......@@ -75,6 +75,14 @@ name = "dtoa"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "errno"
version = "0.1.0"
dependencies = [
"cbindgen 0.5.0",
"platform 0.1.0",
]
[[package]]
name = "fcntl"
version = "0.1.0"
......@@ -244,6 +252,7 @@ version = "0.1.0"
dependencies = [
"compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)",
"ctype 0.1.0",
"errno 0.1.0",
"fcntl 0.1.0",
"grp 0.1.0",
"mman 0.1.0",
......@@ -453,7 +462,9 @@ name = "string"
version = "0.1.0"
dependencies = [
"cbindgen 0.5.0",
"errno 0.1.0",
"platform 0.1.0",
"stdlib 0.1.0",
]
[[package]]
......
......@@ -14,6 +14,7 @@ members = ["src/crt0"]
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] }
platform = { path = "src/platform" }
ctype = { path = "src/ctype" }
errno = { path = "src/errno" }
fcntl = { path = "src/fcntl" }
grp = { path = "src/grp" }
semaphore = { path = "src/semaphore" }
......
extern int errno;
extern __thread int errno;
[package]
name = "errno"
version = "0.1.0"
authors = ["Alex Lyon <arcterus@mail.com>"]
build = "build.rs"
[build-dependencies]
cbindgen = { path = "../../cbindgen" }
[dependencies]
platform = { path = "../platform" }
extern crate cbindgen;
use std::{env, fs};
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
fs::create_dir_all("../../target/include").expect("failed to create include directory");
cbindgen::generate(crate_dir)
.expect("failed to generate bindings")
.write_to_file("../../target/include/errno.h");
}
sys_includes = []
include_guard = "_ERRNO_H"
language = "C"
[enum]
prefix_with_name = true
//! errno implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/errno.h.html
#![no_std]
extern crate platform;
pub enum Errno {
// Argument list too long
E2BIG = 1,
// Permission denied
EACCES,
// Address in use
EADDRINUSE,
// Address not available
EADDRNOTAVAIL,
// Address family not supported
EAFNOSUPPORT,
// Resource unavailable, try again (may be the same value as [EWOULDBLOCK])
EAGAIN,
// Connection already in progress
EALREADY,
// Bad file descriptor
EBADF,
// Bad message
EBADMSG,
// Device or resource busy
EBUSY,
// Operation canceled
ECANCELED,
// No child processes
ECHILD,
// Connection aborted
ECONNABORTED,
// Connection refused
ECONNREFUSED,
// Connection reset
ECONNRESET,
// Resource deadlock would occur
EDEADLK,
// Destination address required
EDESTADDRREQ,
// Mathematics argument out of domain of function
EDOM,
// Reserved
EDQUOT,
// File exists
EEXIST,
// Bad address
EFAULT,
// File too large
EFBIG,
// Host is unreachable
EHOSTUNREACH,
// Identifier removed
EIDRM,
// Illegal byte sequence
EILSEQ,
// Operation in progress
EINPROGRESS,
// Interrupted function
EINTR,
// Invalid argument
EINVAL,
// I/O error
EIO,
// Socket is connected
EISCONN,
// Is a directory
EISDIR,
// Too many levels of symbolic links
ELOOP,
// Too many open files
EMFILE,
// Too many links
EMLINK,
// Message too large
EMSGSIZE,
// Reserved
EMULTIHOP,
// Filename too long
ENAMETOOLONG,
// Network is down
ENETDOWN,
// Connection aborted by network
ENETRESET,
// Network unreachable
ENETUNREACH,
// Too many files open in system
ENFILE,
// No buffer space available
ENOBUFS,
// No message is available on the STREAM head read queue
ENODATA,
// No such device
ENODEV,
// No such file or directory
ENOENT,
// Executable file format error
ENOEXEC,
// No locks available
ENOLCK,
// Reserved
ENOLINK,
// Not enough space
ENOMEM,
// No message of the desired type
ENOMSG,
// Protocol not available
ENOPROTOOPT,
// No space left on device
ENOSPC,
// No STREAM resources
ENOSR,
// Not a STREAM
ENOSTR,
// Function not supported
ENOSYS,
// The socket is not connected
ENOTCONN,
// Not a directory
ENOTDIR,
// Directory not empty
ENOTEMPTY,
// Not a socket
ENOTSOCK,
// Not supported
ENOTSUP,
// Inappropriate I/O control operation
ENOTTY,
// No such device or address
ENXIO,
// Operation not supported on socket
EOPNOTSUPP,
// Value too large to be stored in data type
EOVERFLOW,
// Operation not permitted
EPERM,
// Broken pipe
EPIPE,
// Protocol error
EPROTO,
// Protocol not supported
EPROTONOSUPPORT,
// Protocol wrong type for socket
EPROTOTYPE,
// Result too large
ERANGE,
// Read-only file system
EROFS,
// Invalid seek
ESPIPE,
// No such process
ESRCH,
// Reserved
ESTALE,
// Stream ioctl() timeout
ETIME,
// Connection timed out
ETIMEDOUT,
// Text file busy
ETXTBSY,
// Operation would block (may be the same value as [EAGAIN])
EWOULDBLOCK,
// Cross-device link
EXDEV,
}
......@@ -5,9 +5,11 @@ extern crate compiler_builtins;
extern crate platform;
extern crate ctype;
extern crate errno;
extern crate fcntl;
extern crate grp;
extern crate mman;
extern crate semaphore;
extern crate stdio;
extern crate stdlib;
extern crate string;
......
......@@ -33,18 +33,9 @@ use types::*;
pub static mut errno: c_int = 0;
pub unsafe fn c_str(s: *const c_char) -> &'static [u8] {
use core::slice;
let mut size = 0;
loop {
if *s.offset(size) == 0 {
break;
}
size += 1;
}
use core::usize;
slice::from_raw_parts(s as *const u8, size as usize)
c_str_n(s, usize::MAX)
}
pub unsafe fn c_str_n(s: *const c_char, n: usize) -> &'static [u8] {
......
......@@ -9,3 +9,5 @@ cbindgen = { path = "../../cbindgen" }
[dependencies]
platform = { path = "../platform" }
stdlib = { path = "../stdlib" }
errno = { path = "../errno" }
\ No newline at end of file
......@@ -2,10 +2,14 @@
#![no_std]
extern crate errno;
extern crate platform;
extern crate stdlib;
use platform::types::*;
use errno::*;
use core::cmp;
use core::usize;
#[no_mangle]
pub extern "C" fn memccpy(s1: *mut c_void, s2: *const c_void, c: c_int, n: usize) -> *mut c_void {
......@@ -54,8 +58,8 @@ pub extern "C" fn memchr(s: *const c_void, c: c_int, n: usize) -> *mut c_void {
// }
#[no_mangle]
pub extern "C" fn strcat(s1: *mut c_char, s2: *const c_char) -> *mut c_char {
unimplemented!();
pub unsafe extern "C" fn strcat(s1: *mut c_char, s2: *const c_char) -> *mut c_char {
strncat(s1, s2, usize::MAX)
}
#[no_mangle]
......@@ -64,8 +68,8 @@ pub extern "C" fn strchr(s: *const c_char, c: c_int) -> *mut c_char {
}
#[no_mangle]
pub extern "C" fn strcmp(s1: *const c_char, s2: *const c_char) -> c_int {
unimplemented!();
pub unsafe extern "C" fn strcmp(s1: *const c_char, s2: *const c_char) -> c_int {
strncmp(s1, s2, usize::MAX)
}
#[no_mangle]
......@@ -74,8 +78,8 @@ pub extern "C" fn strcoll(s1: *const c_char, s2: *const c_char) -> c_int {
}
#[no_mangle]
pub extern "C" fn strcpy(s1: *mut c_char, s2: *const c_char) -> *mut c_char {
unimplemented!();
pub unsafe extern "C" fn strcpy(s1: *mut c_char, s2: *const c_char) -> *mut c_char {
strncpy(s1, s2, usize::MAX)
}
#[no_mangle]
......@@ -84,8 +88,27 @@ pub extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> c_ulong {
}
#[no_mangle]
pub extern "C" fn strdup(s1: *const c_char) -> *mut c_char {
unimplemented!();
pub unsafe extern "C" fn strdup(s1: *const c_char) -> *mut c_char {
strndup(s1, usize::MAX)
}
#[no_mangle]
pub unsafe extern "C" fn strndup(s1: *const c_char, size: usize) -> *mut c_char {
let len = strnlen(s1, size);
// the "+ 1" is to account for the NUL byte
let buffer = stdlib::malloc(len + 1) as *mut c_char;
if buffer.is_null() {
platform::errno = Errno::ENOMEM as c_int;
} else {
//memcpy(buffer, s1, len)
for i in 0..len as isize {
*buffer.offset(i) = *s1.offset(i);
}
*buffer.offset(len as isize) = 0;
}
buffer
}
#[no_mangle]
......@@ -95,7 +118,12 @@ pub extern "C" fn strerror(errnum: c_int) -> *mut c_char {
#[no_mangle]
pub unsafe extern "C" fn strlen(s: *const c_char) -> size_t {
platform::c_str(s).len() as size_t
strnlen(s, usize::MAX)
}
#[no_mangle]
pub unsafe extern "C" fn strnlen(s: *const c_char, size: usize) -> size_t {
platform::c_str_n(s, size).len() as size_t
}
#[no_mangle]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment