Add missing credit for Esperanto translation
[neverball.git] / share / fs_rwops.c
blob6ec16b1ca1a471644aa516268360311034178725
1 /*
2 * Copyright (C) 2003-2010 Neverball authors
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #include "fs_rwops.h"
17 static Sint64 rwops_seek(SDL_RWops *ctx, Sint64 offset, int whence)
19 fs_file fh = ctx->hidden.unknown.data1;
20 return fs_seek(fh, offset, whence) ? fs_tell(fh) : -1;
23 static size_t rwops_read(SDL_RWops *ctx, void *ptr, size_t size, size_t maxnum)
25 return fs_read(ptr, size, maxnum, ctx->hidden.unknown.data1);
28 static size_t rwops_write(SDL_RWops *ctx, const void *ptr, size_t size, size_t num)
30 return fs_write(ptr, size, num, ctx->hidden.unknown.data1);
33 static int rwops_close(SDL_RWops *ctx)
35 fs_file fh = ctx->hidden.unknown.data1;
37 if (!fs_close(fh))
38 return -1;
40 SDL_FreeRW(ctx);
41 return 0;
44 SDL_RWops *fs_rwops_make(fs_file fh)
46 SDL_RWops *ctx;
48 if ((ctx = SDL_AllocRW()))
50 ctx->seek = rwops_seek;
51 ctx->read = rwops_read;
52 ctx->write = rwops_write;
53 ctx->close = rwops_close;
55 ctx->hidden.unknown.data1 = fh;
58 return ctx;
61 SDL_RWops *fs_rwops_open(const char *path, const char *mode)
63 fs_file fh;
65 if ((fh = fs_open(path, mode)))
66 return fs_rwops_make(fh);
68 return NULL;