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 !135
parents 05f7371e 0a3c8abe
No related branches found
No related tags found
1 merge request!135Add empty locale functions
...@@ -158,6 +158,14 @@ name = "libc" ...@@ -158,6 +158,14 @@ name = "libc"
version = "0.2.40" version = "0.2.40"
source = "registry+https://github.com/rust-lang/crates.io-index" 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]] [[package]]
name = "log" name = "log"
version = "0.3.9" version = "0.3.9"
...@@ -271,6 +279,7 @@ dependencies = [ ...@@ -271,6 +279,7 @@ dependencies = [
"fenv 0.1.0", "fenv 0.1.0",
"float 0.1.0", "float 0.1.0",
"grp 0.1.0", "grp 0.1.0",
"locale 0.1.0",
"netinet 0.1.0", "netinet 0.1.0",
"platform 0.1.0", "platform 0.1.0",
"semaphore 0.1.0", "semaphore 0.1.0",
......
...@@ -21,6 +21,7 @@ fcntl = { path = "src/fcntl" } ...@@ -21,6 +21,7 @@ fcntl = { path = "src/fcntl" }
fenv = { path = "src/fenv" } fenv = { path = "src/fenv" }
float = { path = "src/float" } float = { path = "src/float" }
grp = { path = "src/grp" } grp = { path = "src/grp" }
locale = { path = "src/locale" }
netinet = { path = "src/netinet" } netinet = { path = "src/netinet" }
platform = { path = "src/platform" } platform = { path = "src/platform" }
semaphore = { path = "src/semaphore" } 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; ...@@ -10,6 +10,7 @@ pub extern crate fcntl;
pub extern crate fenv; pub extern crate fenv;
pub extern crate float; pub extern crate float;
pub extern crate grp; pub extern crate grp;
pub extern crate locale;
pub extern crate netinet; pub extern crate netinet;
pub extern crate semaphore; pub extern crate semaphore;
pub extern crate stdio; 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 @@ ...@@ -2,7 +2,6 @@
#![no_std] #![no_std]
#![feature(alloc)] #![feature(alloc)]
#![feature(global_allocator)]
extern crate alloc; extern crate alloc;
extern crate errno; extern crate errno;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
/getid /getid
/getc_unget /getc_unget
/link /link
/locale
/math /math
/mem /mem
/pipe /pipe
......
...@@ -15,6 +15,7 @@ EXPECT_BINS=\ ...@@ -15,6 +15,7 @@ EXPECT_BINS=\
getid \ getid \
getc_unget \ getc_unget \
link \ link \
locale \
math \ math \
mem \ mem \
pipe \ 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