2 * Copyright (C) 2012, 2013
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do
10 * so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 FILE *fs_file_open(const char *filename, const char *mode) {
27 return platform_fopen(filename, mode);
30 size_t fs_file_read(void *buffer, size_t size, size_t count, FILE *fp) {
31 return platform_fread(buffer, size, count, fp);
34 int fs_file_printf(FILE *fp, const char *format, ...) {
38 rt = platform_vfprintf(fp, format, va);
44 void fs_file_close(FILE *fp) {
48 size_t fs_file_write (
54 return platform_fwrite(buffer, size, count, fp);
57 int fs_file_error(FILE *fp) {
58 return platform_ferror(fp);
61 int fs_file_getc(FILE *fp) {
62 return platform_fgetc(fp);
65 int fs_file_puts(FILE *fp, const char *str) {
66 return platform_fputs(str, fp);
69 int fs_file_seek(FILE *fp, long int off, int whence) {
70 return platform_fseek(fp, off, whence);
73 long int fs_file_tell(FILE *fp) {
74 return platform_ftell(fp);
78 * Implements libc getline for systems that don't have it, which is
79 * assmed all. This works the same as getline().
81 int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
86 if (!lineptr || !n || !stream)
89 if (!(*lineptr = (char*)mem_a((*n=64))))
97 int c = fs_file_getc(stream);
100 *n += (*n > 16) ? *n : 64;
101 chr = *n + *lineptr - pos;
102 if (!(*lineptr = (char*)mem_r(*lineptr,*n)))
104 pos = *n - chr + *lineptr;
122 return (ret = pos - *lineptr);
125 int fs_dir_make(const char *path) {
126 return platform_mkdir(path, 0700);
129 DIR *fs_dir_open(const char *name) {
130 return platform_opendir(name);
133 int fs_dir_close(DIR *dir) {
134 return platform_closedir(dir);
137 struct dirent *fs_dir_read(DIR *dir) {
138 return platform_readdir(dir);