flibc/
cstdio.rs

1#[allow(unused_imports)]
2use {
3    super::libc,
4    super::types
5};
6
7pub use super::libc::{
8    FILE,
9    STDERR_FILENO as STDERR,
10    STDOUT_FILENO as STDOUT,
11    STDIN_FILENO as STDIN,
12};
13
14pub fn fopen(path: *const types::c_char, mode: *const types::c_char) -> *mut FILE {
15    unsafe { libc::fopen(path, mode) }
16}
17
18#[cfg(any(target_pointer_width = "64", feature = "bit64"))]
19pub fn fopen64(path: *const types::c_char, mode: *const types::c_char) -> *mut FILE {
20    unsafe { libc::fopen64(path, mode) }
21}
22
23pub fn fclose(stream: *mut FILE) -> types::c_int {
24    unsafe { libc::fclose(stream) }
25}
26
27pub fn fread(ptr: *mut types::c_void, size: types::size_t, nmemb: types::size_t, stream: *mut FILE) -> types::size_t {
28    unsafe { libc::fread(ptr, size, nmemb, stream) }
29}
30
31pub fn fwrite(ptr: *const types::c_void, size: types::size_t, nmemb: types::size_t, stream: *mut FILE) -> types::size_t {
32    unsafe { libc::fwrite(ptr, size, nmemb, stream) }
33}
34
35#[cfg(any(target_pointer_width = "64", feature = "bit64"))] // TODO: Used only on 64 bit, cause off_t is an 64 bit type
36pub fn fseek(stream: *mut FILE, offset: types::off_t, whence: types::c_int) -> types::c_int {
37    unsafe { libc::fseek(stream, offset, whence) }
38}
39
40#[cfg(any(target_pointer_width = "64", feature = "bit64"))]
41pub fn ftell(stream: *mut FILE) -> types::off_t {
42    unsafe { libc::ftell(stream) }
43}
44
45pub fn fflush(stream: *mut FILE) -> types::c_int {
46    unsafe { libc::fflush(stream) }
47}
48
49pub fn fgetc(stream: *mut FILE) -> types::c_int {
50    unsafe { libc::fgetc(stream) }
51}
52
53pub fn rewind(stream: *mut FILE) {
54    unsafe { libc::rewind(stream) }
55}
56
57pub fn fgets(s: *mut types::c_char, n: types::c_int, stream: *mut FILE) -> *mut types::c_char {
58    unsafe { libc::fgets(s, n, stream) }
59}
60
61pub fn fputc(c: types::c_int, stream: *mut FILE) -> types::c_int {
62    unsafe { libc::fputc(c, stream) }
63}
64
65pub fn fputs(s: *const types::c_char, stream: *mut FILE) -> types::c_int {
66    unsafe { libc::fputs(s, stream) }
67}
68
69pub fn ungetc(c: types::c_int, stream: *mut FILE) -> types::c_int {
70    unsafe { libc::ungetc(c, stream) }
71}
72
73pub fn clearerr(stream: *mut FILE) {
74    unsafe { libc::clearerr(stream) }
75}
76
77pub fn feof(stream: *mut FILE) -> types::c_int {
78    unsafe { libc::feof(stream) }
79}
80
81pub fn ferror(stream: *mut FILE) -> types::c_int {
82    unsafe { libc::ferror(stream) }
83}
84
85pub fn setbuf(stream: *mut FILE, buf: *mut types::c_char) {
86    unsafe { libc::setbuf(stream, buf) }
87}
88
89pub fn setvbuf(stream: *mut FILE, buf: *mut types::c_char, mode: types::c_int, size: types::size_t) -> types::c_int {
90    unsafe { libc::setvbuf(stream, buf, mode, size) }
91}
92
93pub fn freopen(path: *const types::c_char, mode: *const types::c_char, stream: *mut FILE) -> *mut FILE {
94    unsafe { libc::freopen(path, mode, stream) }
95}
96
97pub fn fgetpos(stream: *mut FILE, ptr: *mut types::fpos_t) -> types::c_int {
98    unsafe { libc::fgetpos(stream, ptr) }
99}
100
101pub fn fsetpos(stream: *mut FILE, ptr: *mut types::fpos_t) -> types::c_int {
102    unsafe { libc::fsetpos(stream, ptr)}
103}
104
105pub fn tmpfile() -> *mut FILE {
106    unsafe { libc::tmpfile() }
107}
108
109pub fn tmpnam(s: *mut types::c_char) -> *mut types::c_char {
110    unsafe { libc::tmpnam(s) }
111}
112
113pub fn remove(path: *const types::c_char) -> types::c_int {
114    unsafe { libc::remove(path) }
115}
116
117pub fn fileno(stream: *mut FILE) -> types::c_int {
118    unsafe { libc::fileno(stream) }
119}
120
121pub fn rename(old: *const types::c_char, new: *const types::c_char) -> types::c_int {
122    unsafe { libc::rename(old, new) }
123}
124
125pub fn popen(command: *const types::c_char, mode: *const types::c_char) -> *mut FILE {
126    unsafe { libc::popen(command, mode) }
127}
128
129pub fn pclose(stream: *mut FILE) -> types::c_int {
130    unsafe { libc::pclose(stream) }
131}
132
133pub fn getchar() -> types::c_int {
134    unsafe { libc::getchar() }
135}
136
137pub fn putchar(c: types::c_int) -> types::c_int {
138    unsafe { libc::putchar(c) }
139}
140
141pub fn puts(s: *const types::c_char) -> types::c_int {
142    unsafe { libc::puts(s) }
143}
144
145pub fn perror(s: *const types::c_char) {
146    unsafe { libc::perror(s) }
147}
148
149pub fn printf(format: *const types::c_char) -> types::c_int {
150    unsafe { libc::printf(format) }
151}
152
153pub fn fprintf(stream: *mut FILE, format: *const types::c_char) -> types::c_int {
154    unsafe { libc::fprintf(stream, format) }
155}
156
157pub fn sprintf(s: *mut types::c_char, format: *const types::c_char) -> types::c_int {
158    unsafe { libc::sprintf(s, format) }
159}
160
161pub fn snprintf(s: *mut types::c_char, n: types::size_t, format: *const types::c_char) -> types::c_int {
162    unsafe { libc::snprintf(s, n, format) }
163}
164
165pub fn scanf(format: *const types::c_char) -> types::c_int {
166    unsafe { libc::scanf(format) }
167}
168
169pub fn fscanf(stream: *mut FILE, format: *const types::c_char) -> types::c_int {
170    unsafe { libc::fscanf(stream, format) }
171}
172
173pub fn sscanf(s: *const types::c_char, format: *const types::c_char) -> types::c_int {
174    unsafe { libc::sscanf(s, format) }
175}
176
177pub fn fdopen(fd: types::c_int, mode: *const types::c_char) -> *mut FILE {
178    unsafe { libc::fdopen(fd, mode) }
179}