1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
pub use self::os::{FILE};
pub use self::os::{fpos_t};
pub use self::os::{BUFSIZ};
pub use self::os::{L_ctermid};
pub use self::os::{L_tmpnam};
pub use self::os::{_IOFBF};
pub use self::os::{_IOLBF};
pub use self::os::{_IONBF};
pub use self::os::{SEEK_CUR};
pub use self::os::{SEEK_END};
pub use self::os::{SEEK_SET};
pub use self::os::{FILENAME_MAX};
pub use self::os::{FOPEN_MAX};
pub use self::os::{TMP_MAX};
pub use self::os::{EOF};
pub use self::os::{stdin};
pub use self::os::{stdout};
pub use self::os::{stderr};

use {NTStr, char_t, size_t, int_t, ssize_t, void_t, long_t};
use sys::types::{off_t};

#[cfg(target_os = "linux")]
#[path = "linux/mod.rs"]
mod os;

pub fn clearerr(stream: *mut FILE) {
    extern { fn clearerr(stream: *mut FILE); }
    unsafe { clearerr(stream); }
}

extern {
    pub fn ctermid(s: *mut char_t) -> *mut char_t;
}

extern {
    pub fn dprintf(fd: int_t, fmt: *const char_t, ...) -> int_t;
}

pub fn fclose(stream: *mut FILE) -> int_t {
    extern { fn fclose(stream: *mut FILE) -> int_t; }
    unsafe { fclose(stream) }
}

pub fn fdopen<T: NTStr>(fd: int_t, modes: &T) -> *mut FILE {
    extern { fn fdopen(fd: int_t, modes: *const char_t) -> *mut FILE; }
    unsafe { fdopen(fd, modes.as_ptr()) }
}

pub fn feof(stream: *mut FILE) -> int_t {
    extern { fn feof(stream: *mut FILE) -> int_t; }
    unsafe { feof(stream) }
}

pub fn ferror(stream: *mut FILE) -> int_t {
    extern { fn ferror(stream: *mut FILE) -> int_t; }
    unsafe { ferror(stream) }
}

pub fn fflush(stream: *mut FILE) -> int_t {
    extern { fn fflush(stream: *mut FILE) -> int_t; }
    unsafe { fflush(stream) }
}

pub fn fgetc(stream: *mut FILE) -> int_t {
    extern { fn fgetc(stream: *mut FILE) -> int_t; }
    unsafe { fgetc(stream) }
}

pub fn fgetpos(stream: *mut FILE, pos: &mut fpos_t) -> int_t {
    extern { fn fgetpos(stream: *mut FILE, pos: *mut fpos_t) -> int_t; }
    unsafe { fgetpos(stream, pos as *mut _) }
}

pub fn fgets(s: &mut [u8], stream: *mut FILE) -> *mut char_t {
    extern { fn fgets(s: *mut char_t, n: int_t, stream: *mut FILE) -> *mut char_t; }
    unsafe { fgets(s.as_mut_ptr() as *mut _, s.len() as int_t, stream) }
}

pub fn fileno(stream: *mut FILE) -> int_t {
    extern { fn fileno(stream: *mut FILE) -> int_t; }
    unsafe { fileno(stream) }
}

pub fn flockfile(stream: *mut FILE) {
    extern { fn flockfile(stream: *mut FILE); }
    unsafe { flockfile(stream); }
}

pub fn fmemopen(s: &mut [u8], modes: *const char_t) -> *mut FILE {
    extern { fn fmemopen(s: *mut void_t, len: size_t, modes: *const char_t) -> *mut FILE; }
    unsafe { fmemopen(s.as_ptr() as *mut _, s.len() as size_t, modes) }
}

pub fn fopen<T: NTStr, U: NTStr>(filename: &T, modes: &U) -> *mut FILE {
    extern { fn fopen(filename: *const char_t, modes: *const char_t) -> *mut FILE; }
    unsafe { fopen(filename.as_ptr(), modes.as_ptr()) }
}

extern {
    pub fn fprintf(stream: *mut FILE, format: *const char_t, ...) -> int_t;
}

pub fn fputc(c: int_t, stream: *mut FILE) -> int_t {
    extern { fn fputc(c: int_t, stream: *mut FILE) -> int_t; }
    unsafe { fputc(c, stream) }
}

pub fn fputs<T: NTStr>(s: &T, stream: *mut FILE) -> int_t {
    extern { fn fputs(s: *const char_t, stream: *mut FILE) -> int_t; }
    unsafe { fputs(s.as_ptr(), stream) }
}

extern {
    pub fn fread(ptr: *mut void_t, size: size_t, n: size_t, stream: *mut FILE) -> size_t;
    pub fn fread_unlocked(ptr: *mut void_t, size: size_t, n: size_t,
                          stream: *mut FILE) -> size_t;
}

pub fn freopen<T: NTStr, U: NTStr>(filename: &T, modes: &U,
                                   stream: *mut FILE) -> *mut FILE {
    extern { fn freopen(filename: *const char_t, modes: *const char_t,
                        stream: *mut FILE) -> *mut FILE; }
    unsafe { freopen(filename.as_ptr(), modes.as_ptr(), stream) }
}

extern {
    pub fn fscanf(stream: *mut FILE, format: *const char_t, ...) -> int_t;
}

pub fn fseeko(stream: *mut FILE, off: off_t, whence: int_t) -> int_t {
    extern { fn fseeko(stream: *mut FILE, off: off_t, whence: int_t) -> int_t; }
    unsafe { fseeko(stream, off, whence) }
}

pub fn fseek(stream: *mut FILE, off: long_t, whence: int_t) -> int_t {
    extern { fn fseek(stream: *mut FILE, off: long_t, whence: int_t) -> int_t; }
    unsafe { fseek(stream, off, whence) }
}

pub fn fsetpos(stream: *mut FILE, pos: &fpos_t) -> int_t {
    extern { fn fsetpos(stream: *mut FILE, pos: *const fpos_t) -> int_t; }
    unsafe { fsetpos(stream, pos as *const _) }
}

pub fn ftello(stream: *mut FILE) -> off_t {
    extern { fn ftello(stream: *mut FILE) -> off_t; }
    unsafe { ftello(stream) }
}

pub fn ftell(stream: *mut FILE) -> long_t {
    extern { fn ftell(stream: *mut FILE) -> long_t; }
    unsafe { ftell(stream) }
}

pub fn ftrylockfile(stream: *mut FILE) -> int_t {
    extern { fn ftrylockfile(stream: *mut FILE) -> int_t; }
    unsafe { ftrylockfile(stream) }
}

pub fn funlockfile(stream: *mut FILE) {
    extern { fn funlockfile(stream: *mut FILE); }
    unsafe { funlockfile(stream); }
}

extern {
    pub fn fwrite(ptr: *const void_t, size: size_t, n: size_t, s: *mut FILE) -> size_t;
}

pub fn getchar() -> int_t {
    extern { fn getchar() -> int_t; }
    unsafe { getchar() }
}

pub fn getchar_unlocked() -> int_t {
    extern { fn getchar_unlocked() -> int_t; }
    unsafe { getchar_unlocked() }
}

pub fn getc(stream: *mut FILE) -> int_t {
    extern { fn getc(stream: *mut FILE) -> int_t; }
    unsafe { getc(stream) }
}

pub fn getc_unlocked(stream: *mut FILE) -> int_t {
    extern { fn getc_unlocked(stream: *mut FILE) -> int_t; }
    unsafe { getc_unlocked(stream) }
}

extern {
    pub fn getdelim(lineptr: *mut *mut char_t, n: *mut size_t, delimiter: int_t,
                    stream: *mut FILE) -> ssize_t;
    pub fn getline(lineptr: *mut *mut char_t, n: *mut size_t, stream: *mut FILE) -> ssize_t;
    pub fn gets(s: *mut char_t) -> *mut char_t;
}

pub fn getw(stream: *mut FILE) -> int_t {
    extern { fn getw(stream: *mut FILE) -> int_t; }
    unsafe { getw(stream) }
}

extern {
    pub fn open_memstream(bufloc: *mut *mut char_t, sizeloc: *mut size_t) -> *mut FILE;
}

pub fn pclose(stream: *mut FILE) -> int_t {
    extern { fn pclose(stream: *mut FILE) -> int_t; }
    unsafe { pclose(stream) }
}

pub fn perror<T: NTStr>(s: &T) {
    extern { fn perror(s: *const char_t); }
    unsafe { perror(s.as_ptr()); }
}

pub fn popen<T: NTStr, U: NTStr>(command: &T, modes: &U) -> *mut FILE {
    extern { fn popen(command: *const char_t, modes: *const char_t) -> *mut FILE; }
    unsafe { popen(command.as_ptr(), modes.as_ptr()) }
}

extern {
    pub fn printf(format: *const char_t, ...) -> int_t;
}

pub fn putc(c: int_t, stream: *mut FILE) -> int_t {
    extern { fn putc(c: int_t, stream: *mut FILE) -> int_t; }
    unsafe { putc(c, stream) }
}

pub fn putchar(c: int_t) -> int_t {
    extern { fn putchar(c: int_t) -> int_t; }
    unsafe { putchar(c) }
}

pub fn putchar_unlocked(c: int_t) -> int_t {
    extern { fn putchar_unlocked(c: int_t) -> int_t; }
    unsafe { putchar_unlocked(c) }
}

pub fn putc_unlocked(c: int_t, stream: *mut FILE) -> int_t {
    extern { fn putc_unlocked(c: int_t, stream: *mut FILE) -> int_t; }
    unsafe { putc_unlocked(c, stream) }
}

pub fn puts<T: NTStr>(s: &T) -> int_t {
    extern { fn puts(s: *const char_t) -> int_t; }
    unsafe { puts(s.as_ptr()) }
}

pub fn putw(w: int_t, stream: *mut FILE) -> int_t {
    extern { fn putw(w: int_t, stream: *mut FILE) -> int_t; }
    unsafe { putw(w, stream) }
}

pub fn remove<T: NTStr>(filename: &T) -> int_t {
    extern { fn remove(filename: *const char_t) -> int_t; }
    unsafe { remove(filename.as_ptr()) }
}

pub fn renameat<T: NTStr, U: NTStr>(oldfd: int_t, old: &T, newfd: int_t,
                                    new: &T) -> int_t {
    extern { fn renameat(oldfd: int_t, old: *const char_t, newfd: int_t,
                         new: *const char_t) -> int_t; }
    unsafe { renameat(oldfd, old.as_ptr(), newfd, new.as_ptr()) }
}

pub fn rename<T: NTStr, U: NTStr>(old: &T, new: &U) -> int_t {
    extern { fn rename(old: *const char_t, new: *const char_t) -> int_t; }
    unsafe { rename(old.as_ptr(), new.as_ptr()) }
}

pub fn rewind(stream: *mut FILE) {
    extern { fn rewind(stream: *mut FILE); }
    unsafe { rewind(stream); }
}

extern {
    pub fn scanf(format: *const char_t, ...) -> int_t;
}

extern {
    pub fn setbuf(stream: *mut FILE, buf: *mut char_t);
    pub fn setvbuf(stream: *mut FILE, buf: *mut char_t, modes: int_t, n: size_t) -> int_t;
    pub fn snprintf(s: *mut char_t, maxlen: size_t, format: *const char_t, ...) -> int_t;
    pub fn sprintf(s: *mut char_t, format: *const char_t, ...) -> int_t;
    pub fn sscanf(s: *const char_t, format: *const char_t, ...) -> int_t;
    pub fn tempnam(dir: *const char_t, pfx: *const char_t) -> *mut char_t;
}

pub fn tmpfile() -> *mut FILE {
    extern { fn tmpfile() -> *mut FILE; }
    unsafe { tmpfile() }
}

extern {
    pub fn tmpnam(s: *mut char_t) -> *mut char_t;
}

pub fn ungetc(c: int_t, stream: *mut FILE) -> int_t {
    extern { fn ungetc(c: int_t, stream: *mut FILE) -> int_t; }
    unsafe { ungetc(c, stream) }
}