Commit 79d05d7e authored by Jeremy Soller's avatar Jeremy Soller

Build variadic functions as part of relibc

parent b8491654
......@@ -263,6 +263,7 @@ dependencies = [
name = "relibc"
version = "0.1.0"
dependencies = [
"cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)",
"ctype 0.1.0",
"errno 0.1.0",
......
......@@ -10,6 +10,9 @@ crate-type = ["staticlib"]
[workspace]
members = ["src/crt0"]
[build-dependencies]
cc = "1.0"
[dependencies]
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] }
ctype = { path = "src/ctype" }
......
extern crate cc;
use std::env;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
cc::Build::new()
.flag("-nostdinc")
.flag("-nostdlib")
.flag("-I").flag(&format!("{}/include", crate_dir))
.flag("-fno-stack-protector")
.file("src/c/fcntl.c")
.file("src/c/stdio.c")
.compile("relibc_c");
println!("cargo:rustc-link-lib=static=relibc_c");
}
#ifndef _BITS_FCNTL_H
#define _BITS_FCNTL_H
int open(const char* filename, int flags, ...) {
mode_t mode = 0;
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, mode_t);
va_end(ap);
return sys_open(filename, flags, mode);
}
int fcntl(int fildes, int cmd, ...) {
int args = 0;
va_list ap;
va_start(ap, cmd);
args = va_arg(ap, int);
va_end(ap);
return sys_fcntl(fildes, cmd, args);
}
int open(const char* filename, int flags, ...);
int fcntl(int fildes, int cmd, ...);
#endif
#ifndef _BITS_STDIO_H
#define _BITS_STDIO_H
int fprintf(FILE * stream, const char * fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = vfprintf(stream, fmt, ap);
va_end(ap);
return ret;
}
int printf(const char * fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = vprintf(fmt, ap);
va_end(ap);
return ret;
}
int snprintf(char *s, size_t n, const char * fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsnprintf(s, n, fmt, ap);
va_end(ap);
return ret;
}
int sprintf(char *s, const char * fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsprintf(s, fmt, ap);
va_end(ap);
return ret;
}
int fprintf(FILE * stream, const char * fmt, ...);
int printf(const char * fmt, ...);
int snprintf(char *s, size_t n, const char * fmt, ...);
int sprintf(char *s, const char * fmt, ...);
#endif /* _BITS_STDIO_H */
#ifndef _BITS_STDIO_H
#define _BITS_STDIO_H
#ifndef _BITS_STRING_H
#define _BITS_STRING_H
int memcmp(const void *s1, const void *s2, size_t n);
void *memcpy(void *dest, const void *src, size_t n);
void *memmove(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
#endif /* _BITS_STDIO_H */
#endif /* _BITS_STRING_H */
#include <stdarg.h>
#include <sys/types.h>
int sys_open(const char* filename, int flags, mode_t mode);
int open(const char* filename, int flags, ...) {
mode_t mode = 0;
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, mode_t);
va_end(ap);
return sys_open(filename, flags, mode);
}
int sys_fcntl(int fildes, int cmd, int args);
int fcntl(int fildes, int cmd, ...) {
int args = 0;
va_list ap;
va_start(ap, cmd);
args = va_arg(ap, int);
va_end(ap);
return sys_fcntl(fildes, cmd, args);
}
#include <stdarg.h>
#include <stddef.h>
typedef struct FILE FILE;
int vfprintf(FILE * stream, const char * fmt, va_list ap);
int fprintf(FILE * stream, const char * fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = vfprintf(stream, fmt, ap);
va_end(ap);
return ret;
}
int vprintf(const char * fmt, va_list ap);
int printf(const char * fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = vprintf(fmt, ap);
va_end(ap);
return ret;
}
int vsnprintf(char * s, size_t n, const char * fmt, va_list ap);
int snprintf(char * s, size_t n, const char * fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsnprintf(s, n, fmt, ap);
va_end(ap);
return ret;
}
int vsprintf(char * s, const char * fmt, va_list ap);
int sprintf(char *s, const char * fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsprintf(s, fmt, ap);
va_end(ap);
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment