︙ | | | ︙ | |
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef __wii__
# define BOOL OGC_BOOL
# include <fat.h>
# undef BOOL
#endif
#ifdef OF_NINTENDO_DS
# include <stdbool.h>
|
>
>
|
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include "platform.h"
#ifdef OF_WII
# define BOOL OGC_BOOL
# include <fat.h>
# undef BOOL
#endif
#ifdef OF_NINTENDO_DS
# include <stdbool.h>
|
︙ | | | ︙ | |
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#import "OFInvalidArgumentException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSeekFailedException.h"
#import "OFWriteFailedException.h"
#ifdef _WIN32
# include <windows.h>
#endif
#ifndef O_BINARY
# define O_BINARY 0
#endif
#ifndef O_CLOEXEC
|
|
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#import "OFInvalidArgumentException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSeekFailedException.h"
#import "OFWriteFailedException.h"
#ifdef OF_WINDOWS
# include <windows.h>
#endif
#ifndef O_BINARY
# define O_BINARY 0
#endif
#ifndef O_CLOEXEC
|
︙ | | | ︙ | |
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
@implementation OFFile
+ (void)initialize
{
if (self != [OFFile class])
return;
#ifdef __wii__
if (!fatInitDefault())
@throw [OFInitializationFailedException
exceptionWithClass: self];
#endif
#ifdef OF_NINTENDO_DS
if (!nitroFSInit(NULL))
|
|
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
@implementation OFFile
+ (void)initialize
{
if (self != [OFFile class])
return;
#ifdef OF_WII
if (!fatInitDefault())
@throw [OFInitializationFailedException
exceptionWithClass: self];
#endif
#ifdef OF_NINTENDO_DS
if (!nitroFSInit(NULL))
|
︙ | | | ︙ | |
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
int flags;
if ((flags = parseMode([mode UTF8String])) == -1)
@throw [OFInvalidArgumentException exception];
flags |= O_CLOEXEC;
#if defined(_WIN32)
if ((_fd = _wopen([path UTF16String], flags,
DEFAULT_MODE)) == -1)
#elif defined(OF_HAVE_OFF64_T)
if ((_fd = open64([path cStringWithEncoding: [OFSystemInfo
native8BitEncoding]], flags, DEFAULT_MODE)) == -1)
#else
if ((_fd = open([path cStringWithEncoding: [OFSystemInfo
|
|
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
int flags;
if ((flags = parseMode([mode UTF8String])) == -1)
@throw [OFInvalidArgumentException exception];
flags |= O_CLOEXEC;
#if defined(OF_WINDOWS)
if ((_fd = _wopen([path UTF16String], flags,
DEFAULT_MODE)) == -1)
#elif defined(OF_HAVE_OFF64_T)
if ((_fd = open64([path cStringWithEncoding: [OFSystemInfo
native8BitEncoding]], flags, DEFAULT_MODE)) == -1)
#else
if ((_fd = open([path cStringWithEncoding: [OFSystemInfo
|
︙ | | | ︙ | |
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
{
ssize_t ret;
if (_fd == -1 || _atEndOfStream)
@throw [OFReadFailedException exceptionWithObject: self
requestedLength: length];
#ifndef _WIN32
if ((ret = read(_fd, buffer, length)) < 0)
@throw [OFReadFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
#else
if (length > UINT_MAX)
@throw [OFOutOfRangeException exception];
|
|
|
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
{
ssize_t ret;
if (_fd == -1 || _atEndOfStream)
@throw [OFReadFailedException exceptionWithObject: self
requestedLength: length];
#ifndef OF_WINDOWS
if ((ret = read(_fd, buffer, length)) < 0)
@throw [OFReadFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
#else
if (length > UINT_MAX)
@throw [OFOutOfRangeException exception];
|
︙ | | | ︙ | |
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
- (void)lowlevelWriteBuffer: (const void*)buffer
length: (size_t)length
{
if (_fd == -1 || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
#ifndef _WIN32
if (length > SSIZE_MAX)
@throw [OFOutOfRangeException exception];
if (write(_fd, buffer, length) != (ssize_t)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
|
|
|
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
- (void)lowlevelWriteBuffer: (const void*)buffer
length: (size_t)length
{
if (_fd == -1 || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
#ifndef OF_WINDOWS
if (length > SSIZE_MAX)
@throw [OFOutOfRangeException exception];
if (write(_fd, buffer, length) != (ssize_t)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
|
︙ | | | ︙ | |
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
errNo: errno];
#endif
}
- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset
whence: (int)whence
{
#if defined(_WIN32)
of_offset_t ret = _lseeki64(_fd, offset, whence);
#elif defined(OF_HAVE_OFF64_T)
of_offset_t ret = lseek64(_fd, offset, whence);
#else
of_offset_t ret = lseek(_fd, offset, whence);
#endif
|
|
|
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
errNo: errno];
#endif
}
- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset
whence: (int)whence
{
#if defined(OF_WINDOWS)
of_offset_t ret = _lseeki64(_fd, offset, whence);
#elif defined(OF_HAVE_OFF64_T)
of_offset_t ret = lseek64(_fd, offset, whence);
#else
of_offset_t ret = lseek(_fd, offset, whence);
#endif
|
︙ | | | ︙ | |