share/gui: don't use less of widget width for truncation than available
[neverball] / share / fs_rwops.c
1 #include "fs_rwops.h"
2
3 static int rwops_seek(SDL_RWops *ctx, int offset, int whence)
4 {
5     fs_file fh = ctx->hidden.unknown.data1;
6     return fs_seek(fh, offset, whence) ? fs_tell(fh) : -1;
7 }
8
9 static int rwops_read(SDL_RWops *ctx, void *ptr, int size, int maxnum)
10 {
11     return fs_read(ptr, size, maxnum, ctx->hidden.unknown.data1);
12 }
13
14 static int rwops_write(SDL_RWops *ctx, const void *ptr, int size, int num)
15 {
16     return fs_write(ptr, size, num, ctx->hidden.unknown.data1);
17 }
18
19 static int rwops_close(SDL_RWops *ctx)
20 {
21     fs_file fh = ctx->hidden.unknown.data1;
22
23     if (!fs_close(fh))
24         return -1;
25
26     SDL_FreeRW(ctx);
27     return 0;
28 }
29
30 SDL_RWops *fs_rwops_make(fs_file fh)
31 {
32     SDL_RWops *ctx;
33
34     if ((ctx = SDL_AllocRW()))
35     {
36         ctx->seek  = rwops_seek;
37         ctx->read  = rwops_read;
38         ctx->write = rwops_write;
39         ctx->close = rwops_close;
40
41         ctx->hidden.unknown.data1 = fh;
42     }
43
44     return ctx;
45 }
46
47 SDL_RWops *fs_rwops_open(const char *path, const char *mode)
48 {
49     fs_file fh;
50
51     if ((fh = fs_open(path, mode)))
52         return fs_rwops_make(fh);
53
54     return NULL;
55 }