Fixed the memory functions required for LLVM to properly work.
This required the fixing of the features section to properly handle passing on the use_std feature. It also required that the memory functions were moved to the main library module instead of within the rust module as was previously desired. The C module then correctly skips defining the external C library functions. Basic time functionality was also added.
This commit is contained in:
12
src/c/mod.rs
Normal file
12
src/c/mod.rs
Normal file
@ -0,0 +1,12 @@
|
||||
//! Handle defining the external functions from what ever C library is
|
||||
//! being linked against. These will use the C99 definitions so that
|
||||
//! this library is as up-to-date as it can be.
|
||||
|
||||
|
||||
mod string;
|
||||
mod time;
|
||||
|
||||
|
||||
|
||||
pub use self::string::*;
|
||||
pub use self::time::*;
|
56
src/c/string.rs
Normal file
56
src/c/string.rs
Normal file
@ -0,0 +1,56 @@
|
||||
#[link(name="c")]
|
||||
extern
|
||||
{
|
||||
}
|
||||
|
||||
#[cfg(not(feature="no_mem_manip"))]
|
||||
#[link(name="c")]
|
||||
extern
|
||||
{
|
||||
/// Copies the values of n bytes from the location pointed to by
|
||||
/// src directly to the memory block pointed to by dest.
|
||||
///
|
||||
/// The underlying type of the objects pointed to by both the src
|
||||
/// and dest pointers are irrelevant for this function; The
|
||||
/// result is a binary copy of the data.
|
||||
///
|
||||
/// The function does not check for any terminating null character
|
||||
/// in source - it always copies exactly n bytes.
|
||||
///
|
||||
/// To avoid overflows, the size of the arrays pointed to by both
|
||||
/// the dest and src parameters, shall be at least n bytes,
|
||||
/// and should not overlap (for overlapping memory blocks, memmove
|
||||
/// is a safer approach).
|
||||
pub fn memcpy(dest: *mut u8, src: *const u8, n: usize);
|
||||
|
||||
/// Copies the values of n bytes from the location pointed by src
|
||||
/// to the memory block pointed by dest. Copying takes place
|
||||
/// as if an intermediate buffer were used, allowing the dest
|
||||
/// and src to overlap.
|
||||
///
|
||||
/// The underlying type of the objects pointed by both the src and
|
||||
/// dest pointers are irrelevant for this function; The result
|
||||
/// is a binary copy of the data.
|
||||
///
|
||||
/// The function does not check for any terminating null character
|
||||
/// in source - it always copies exactly n bytes.
|
||||
///
|
||||
/// To avoid overflows, the size of the arrays pointed by both
|
||||
/// the dest and src parameters, shall be at least n bytes.
|
||||
pub fn memmove(dest: *mut u8, src: *const u8, n: usize);
|
||||
|
||||
|
||||
/// Compares the first n bytes of the block of memory pointed by
|
||||
/// s1 to the first num bytes pointed by s2, returning zero if
|
||||
/// they all match or a value different from zero representing which
|
||||
/// is greater if they do not.
|
||||
///
|
||||
/// Notice that, unlike strcmp, the function does not stop comparing
|
||||
/// after finding a null character.
|
||||
pub fn memcmp(s1: *const u8, s2: *const u8, n: usize);
|
||||
|
||||
|
||||
/// Sets the first n bytes of the block of memory pointed by s
|
||||
/// to the specified value c (interpreted as an unsigned char).
|
||||
pub fn memset(s: *mut u8, c: i32, n: usize);
|
||||
}
|
55
src/c/time.rs
Normal file
55
src/c/time.rs
Normal file
@ -0,0 +1,55 @@
|
||||
use binding::{CInt, CLong};
|
||||
|
||||
|
||||
|
||||
/// The type used for seconds in the time structures.
|
||||
pub type Seconds = CLong;
|
||||
|
||||
|
||||
|
||||
/// The local time of the system. This can be used
|
||||
/// to get more specific calendar type information.
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct LocalTime
|
||||
{
|
||||
/// Seconds [0-60] **Note** 1 leap second.
|
||||
second: CInt,
|
||||
|
||||
/// Minutes [0-59].
|
||||
minute: CInt,
|
||||
|
||||
/// Hours [0-23].
|
||||
hour: CInt,
|
||||
|
||||
/// Day of the month [1-31].
|
||||
day_of_month: CInt,
|
||||
|
||||
/// Month of the year [0-11].
|
||||
month: CInt,
|
||||
|
||||
/// Years since 1900.
|
||||
year: CInt,
|
||||
|
||||
/// Days since Sunday [0-6].
|
||||
day_of_week: CInt,
|
||||
|
||||
/// Days since January 1 [0-365].
|
||||
day_of_year: CInt,
|
||||
|
||||
/// DST [-1/0/1]. Greater than zero if DST is in effect,
|
||||
/// zero if DST is not in effect, and less than zero if
|
||||
/// the information is not available.
|
||||
is_dst: CInt,
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[link(name="c")]
|
||||
extern
|
||||
{
|
||||
/// Uses the value pointed by time to fill a LocalTime structure with
|
||||
/// the values that represent the corresponding time, expressed
|
||||
/// for the local timezone.
|
||||
pub fn localtime(time: *const Seconds) -> *const LocalTime;
|
||||
}
|
Reference in New Issue
Block a user