Skip to content
Snippets Groups Projects
Commit ccb74c6e authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'master' into 'master'

Add empty locale functions

See merge request redox-os/relibc!135
parents 05f7371e 0a3c8abe
No related branches found
No related tags found
No related merge requests found
......@@ -158,6 +158,14 @@ name = "libc"
version = "0.2.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "locale"
version = "0.1.0"
dependencies = [
"cbindgen 0.5.2",
"platform 0.1.0",
]
[[package]]
name = "log"
version = "0.3.9"
......@@ -271,6 +279,7 @@ dependencies = [
"fenv 0.1.0",
"float 0.1.0",
"grp 0.1.0",
"locale 0.1.0",
"netinet 0.1.0",
"platform 0.1.0",
"semaphore 0.1.0",
......
......@@ -21,6 +21,7 @@ fcntl = { path = "src/fcntl" }
fenv = { path = "src/fenv" }
float = { path = "src/float" }
grp = { path = "src/grp" }
locale = { path = "src/locale" }
netinet = { path = "src/netinet" }
platform = { path = "src/platform" }
semaphore = { path = "src/semaphore" }
......
#define LC_ALL 0
#define LC_COLLATE 1
#define LC_CTYPE 2
#define LC_MESSAGES 3
#define LC_MONETARY 4
#define LC_NUMERIC 5
#define LC_TIME 6
......@@ -10,6 +10,7 @@ pub extern crate fcntl;
pub extern crate fenv;
pub extern crate float;
pub extern crate grp;
pub extern crate locale;
pub extern crate netinet;
pub extern crate semaphore;
pub extern crate stdio;
......
[package]
name = "locale"
version = "0.1.0"
authors = ["Jeremy Soller <jackpot51@gmail.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/locale.h");
}
include_guard = "_LOCALE_H"
trailer = "#include <bits/locale.h>"
language = "C"
[enum]
prefix_with_name = true
//! locale implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/locale.h.html
#![no_std]
#![feature(alloc)]
extern crate platform;
use core::ptr;
use platform::types::*;
const EMPTY_PTR: *const c_char = "\0" as *const _ as *const c_char;
static mut C_LOCALE: [c_char; 2] = [b'C' as c_char, 0];
#[repr(C)]
#[no_mangle]
pub struct lconv {
currency_symbol: *const c_char,
decimal_point: *const c_char,
frac_digits: c_char,
grouping: *const c_char,
int_curr_symbol: *const c_char,
int_frac_digits: c_char,
mon_decimal_point: *const c_char,
mon_grouping: *const c_char,
mon_thousands_sep: *const c_char,
negative_sign: *const c_char,
n_cs_precedes: c_char,
n_sep_by_space: c_char,
n_sign_posn: c_char,
positive_sign: *const c_char,
p_cs_precedes: c_char,
p_sep_by_space: c_char,
p_sign_posn: c_char,
thousands_sep: *const c_char,
}
unsafe impl Sync for lconv {}
static CURRENT_LOCALE: lconv = lconv {
currency_symbol: EMPTY_PTR,
decimal_point: ".\0" as *const _ as *const c_char,
frac_digits: c_char::max_value(),
grouping: EMPTY_PTR,
int_curr_symbol: EMPTY_PTR,
int_frac_digits: c_char::max_value(),
mon_decimal_point: EMPTY_PTR,
mon_grouping: EMPTY_PTR,
mon_thousands_sep: EMPTY_PTR,
negative_sign: EMPTY_PTR,
n_cs_precedes: c_char::max_value(),
n_sep_by_space: c_char::max_value(),
n_sign_posn: c_char::max_value(),
positive_sign: EMPTY_PTR,
p_cs_precedes: c_char::max_value(),
p_sep_by_space: c_char::max_value(),
p_sign_posn: c_char::max_value(),
thousands_sep: EMPTY_PTR
};
#[no_mangle]
pub extern "C" fn localeconv() -> *const lconv {
&CURRENT_LOCALE as *const _
}
#[no_mangle]
pub unsafe extern "C" fn setlocale(_option: c_int, val: *const c_char) -> *mut c_char {
if val.is_null() {
// Can't use string``
return C_LOCALE.as_mut_ptr() as *mut c_char;
}
// TODO actually implement
ptr::null_mut()
}
......@@ -2,7 +2,6 @@
#![no_std]
#![feature(alloc)]
#![feature(global_allocator)]
extern crate alloc;
extern crate errno;
......
......@@ -17,6 +17,7 @@
/getid
/getc_unget
/link
/locale
/math
/mem
/pipe
......
......@@ -15,6 +15,7 @@ EXPECT_BINS=\
getid \
getc_unget \
link \
locale \
math \
mem \
pipe \
......
success!
#include <locale.h>
#include <stdio.h>
#include <string.h>
int main() {
// TODO: Implement locale properly and test it here
char* val = setlocale(LC_ALL, NULL);
if (strcmp(val, "C") == 0) {
puts("success!");
} else {
printf("setlocale returned the wrong value: %s", val);
}
}
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