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
23 #define GMQCC_PLATFORM_HEADER
27 fs_file_t *fs_file_open(const char *filename, const char *mode) {
28 return (fs_file_t*)platform_fopen(filename, mode);
31 size_t fs_file_read(void *buffer, size_t size, size_t count, fs_file_t *fp) {
32 return platform_fread(buffer, size, count, (FILE*)fp);
35 int fs_file_printf(fs_file_t *fp, const char *format, ...) {
39 rt = platform_vfprintf((FILE*)fp, format, va);
45 void fs_file_close(fs_file_t *fp) {
46 platform_fclose((FILE*)fp);
49 size_t fs_file_write (
55 return platform_fwrite(buffer, size, count, (FILE*)fp);
58 int fs_file_error(fs_file_t *fp) {
59 return platform_ferror((FILE*)fp);
62 int fs_file_getc(fs_file_t *fp) {
63 int get = platform_fgetc((FILE*)fp);
64 return (get == EOF) ? FS_FILE_EOF : get;
67 int fs_file_puts(fs_file_t *fp, const char *str) {
68 return platform_fputs(str, (FILE*)fp);
71 int fs_file_seek(fs_file_t *fp, long int off, int whence) {
73 case FS_FILE_SEEK_CUR: whence = SEEK_CUR; break;
74 case FS_FILE_SEEK_SET: whence = SEEK_SET; break;
75 case FS_FILE_SEEK_END: whence = SEEK_END; break;
77 return platform_fseek((FILE*)fp, off, whence);
80 long int fs_file_tell(fs_file_t *fp) {
81 return platform_ftell((FILE*)fp);
84 int fs_file_flush(fs_file_t *fp) {
85 return platform_fflush((FILE*)fp);
89 * Implements libc getline for systems that don't have it, which is
90 * assmed all. This works the same as getline().
92 int fs_file_getline(char **lineptr, size_t *n, fs_file_t *stream) {
97 if (!lineptr || !n || !stream)
100 if (!(*lineptr = (char*)mem_a((*n=64))))
108 int c = fs_file_getc(stream);
111 *n += (*n > 16) ? *n : 64;
112 chr = *n + *lineptr - pos;
113 if (!(*lineptr = (char*)mem_r(*lineptr,*n)))
115 pos = *n - chr + *lineptr;
118 if (fs_file_error(stream))
133 return (ret = pos - *lineptr);
136 int fs_dir_make(const char *path) {
137 return platform_mkdir(path, 0700);
140 fs_dir_t *fs_dir_open(const char *name) {
141 return (fs_dir_t*)platform_opendir(name);
144 int fs_dir_close(fs_dir_t *dir) {
145 return platform_closedir((DIR*)dir);
148 fs_dirent_t *fs_dir_read(fs_dir_t *dir) {
149 return (fs_dirent_t*)platform_readdir((DIR*)dir);