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.
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
;
44 SDL_RWops
*fs_rwops_make(fs_file fh
)
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
;
61 SDL_RWops
*fs_rwops_open(const char *path
, const char *mode
)
65 if ((fh
= fs_open(path
, mode
)))
66 return fs_rwops_make(fh
);