Add errno crate and set errno in strndup
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
[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" }
|
||||
@@ -0,0 +1,11 @@
|
||||
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");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
sys_includes = []
|
||||
include_guard = "_ERRNO_H"
|
||||
language = "C"
|
||||
|
||||
[enum]
|
||||
prefix_with_name = true
|
||||
@@ -0,0 +1,166 @@
|
||||
//! 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,6 +5,7 @@ extern crate compiler_builtins;
|
||||
extern crate platform;
|
||||
|
||||
extern crate ctype;
|
||||
extern crate errno;
|
||||
extern crate fcntl;
|
||||
extern crate grp;
|
||||
extern crate mman;
|
||||
|
||||
@@ -10,3 +10,4 @@ cbindgen = { path = "../../cbindgen" }
|
||||
[dependencies]
|
||||
platform = { path = "../platform" }
|
||||
stdlib = { path = "../stdlib" }
|
||||
errno = { path = "../errno" }
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
extern crate platform;
|
||||
extern crate stdlib;
|
||||
extern crate errno;
|
||||
|
||||
use platform::types::*;
|
||||
use errno::*;
|
||||
use core::cmp;
|
||||
use core::usize;
|
||||
|
||||
@@ -95,9 +97,9 @@ pub unsafe extern "C" fn strndup(s1: *const c_char, size: usize) -> *mut c_char
|
||||
// the "+ 1" is to account for the NUL byte
|
||||
let len = strnlen(s1, size) + 1;
|
||||
|
||||
let buffer = stdlib::malloc(len) as *mut _;
|
||||
let buffer = stdlib::malloc(len) as *mut c_char;
|
||||
if buffer.is_null() {
|
||||
// TODO: set errno
|
||||
platform::errno = Errno::ENOMEM as c_int;
|
||||
} else {
|
||||
//memcpy(buffer, s1, len)
|
||||
for i in 0..len as isize {
|
||||
|
||||
Reference in New Issue
Block a user