diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-05-06 17:35:13 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-05-06 17:35:13 +0000 |
commit | 0a1d7c28b7e9da555d26d489cde2da26e2cc9ca0 (patch) | |
tree | a21521e6e4b8fe0131c4d9e8bae6d8cc78125fe9 | |
parent | c61e89c0eda126c2c1a4a3983520c35fe30db156 (diff) | |
download | rockbox-0a1d7c28b7e9da555d26d489cde2da26e2cc9ca0.tar.gz rockbox-0a1d7c28b7e9da555d26d489cde2da26e2cc9ca0.zip |
Make open() posix compliant api-wise. A few calls (those with O_CREAT) need the additional optional mode parameter so add it. Impact for the core is almost zero, as open() is a wrapper macro for the real open function which doesn't take the variable parameter.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25844 a1c6a512-1295-4272-9138-f99709370657
76 files changed, 179 insertions, 122 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c index f02ac25111..c48810c19c 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c | |||
@@ -259,7 +259,7 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, | |||
259 | snprintf(global_temp_buffer, sizeof(global_temp_buffer), | 259 | snprintf(global_temp_buffer, sizeof(global_temp_buffer), |
260 | "%s.tmp", bookmark_file_name); | 260 | "%s.tmp", bookmark_file_name); |
261 | temp_bookmark_file = open(global_temp_buffer, | 261 | temp_bookmark_file = open(global_temp_buffer, |
262 | O_WRONLY | O_CREAT | O_TRUNC); | 262 | O_WRONLY | O_CREAT | O_TRUNC, 0666); |
263 | if (temp_bookmark_file < 0) | 263 | if (temp_bookmark_file < 0) |
264 | return false; /* can't open the temp file */ | 264 | return false; /* can't open the temp file */ |
265 | 265 | ||
@@ -814,7 +814,7 @@ static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id) | |||
814 | snprintf(global_temp_buffer, sizeof(global_temp_buffer), | 814 | snprintf(global_temp_buffer, sizeof(global_temp_buffer), |
815 | "%s.tmp", bookmark_file_name); | 815 | "%s.tmp", bookmark_file_name); |
816 | temp_bookmark_file = open(global_temp_buffer, | 816 | temp_bookmark_file = open(global_temp_buffer, |
817 | O_WRONLY | O_CREAT | O_TRUNC); | 817 | O_WRONLY | O_CREAT | O_TRUNC, 0666); |
818 | 818 | ||
819 | if (temp_bookmark_file < 0) | 819 | if (temp_bookmark_file < 0) |
820 | return false; /* can't open the temp file */ | 820 | return false; /* can't open the temp file */ |
diff --git a/apps/codecs.c b/apps/codecs.c index 8976871abd..b20aa7f969 100644 --- a/apps/codecs.c +++ b/apps/codecs.c | |||
@@ -73,6 +73,26 @@ size_t codec_size; | |||
73 | 73 | ||
74 | extern void* plugin_get_audio_buffer(size_t *buffer_size); | 74 | extern void* plugin_get_audio_buffer(size_t *buffer_size); |
75 | 75 | ||
76 | #undef open | ||
77 | static int open(const char* pathname, int flags, ...) | ||
78 | { | ||
79 | #ifdef SIMULATOR | ||
80 | int fd; | ||
81 | if (flags & O_CREAT) | ||
82 | { | ||
83 | va_list ap; | ||
84 | va_start(ap, flags); | ||
85 | fd = sim_open(pathname, flags, va_arg(ap, mode_t)); | ||
86 | va_end(ap); | ||
87 | } | ||
88 | else | ||
89 | fd = sim_open(pathname, flags); | ||
90 | |||
91 | return fd; | ||
92 | #else | ||
93 | return file_open(pathname, flags); | ||
94 | #endif | ||
95 | } | ||
76 | struct codec_api ci = { | 96 | struct codec_api ci = { |
77 | 97 | ||
78 | 0, /* filesize */ | 98 | 0, /* filesize */ |
diff --git a/apps/codecs.h b/apps/codecs.h index 6f28f0ef0f..34fd3940ad 100644 --- a/apps/codecs.h +++ b/apps/codecs.h | |||
@@ -222,7 +222,7 @@ struct codec_api { | |||
222 | size_t (*enc_unget_pcm_data)(size_t size); | 222 | size_t (*enc_unget_pcm_data)(size_t size); |
223 | 223 | ||
224 | /* file */ | 224 | /* file */ |
225 | int (*open)(const char* pathname, int flags); | 225 | int (*open)(const char* pathname, int flags, ...); |
226 | int (*close)(int fd); | 226 | int (*close)(int fd); |
227 | ssize_t (*read)(int fd, void* buf, size_t count); | 227 | ssize_t (*read)(int fd, void* buf, size_t count); |
228 | off_t (*lseek)(int fd, off_t offset, int whence); | 228 | off_t (*lseek)(int fd, off_t offset, int whence); |
diff --git a/apps/codecs/aiff_enc.c b/apps/codecs/aiff_enc.c index 87358f3df8..f728d6f6a5 100644 --- a/apps/codecs/aiff_enc.c +++ b/apps/codecs/aiff_enc.c | |||
@@ -136,7 +136,7 @@ static bool on_start_file(struct enc_file_event_data *data) | |||
136 | if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0') | 136 | if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0') |
137 | return false; | 137 | return false; |
138 | 138 | ||
139 | data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC); | 139 | data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
140 | 140 | ||
141 | if (data->rec_file < 0) | 141 | if (data->rec_file < 0) |
142 | return false; | 142 | return false; |
diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c index 71d02fb736..25e263dd60 100644 --- a/apps/codecs/libcook/main.c +++ b/apps/codecs/libcook/main.c | |||
@@ -171,7 +171,7 @@ int main(int argc, char *argv[]) | |||
171 | /* output raw audio frames that are sent to the decoder into separate files */ | 171 | /* output raw audio frames that are sent to the decoder into separate files */ |
172 | #ifdef DUMP_RAW_FRAMES | 172 | #ifdef DUMP_RAW_FRAMES |
173 | snprintf(filename,sizeof(filename),"dump%d.raw",++x); | 173 | snprintf(filename,sizeof(filename),"dump%d.raw",++x); |
174 | fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND); | 174 | fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND, 0666); |
175 | write(fd_out,pkt.frames[i],sps); | 175 | write(fd_out,pkt.frames[i],sps); |
176 | close(fd_out); | 176 | close(fd_out); |
177 | #endif | 177 | #endif |
diff --git a/apps/codecs/libffmpegFLAC/main.c b/apps/codecs/libffmpegFLAC/main.c index 5d232a8896..e6d4b2f4fd 100644 --- a/apps/codecs/libffmpegFLAC/main.c +++ b/apps/codecs/libffmpegFLAC/main.c | |||
@@ -62,7 +62,7 @@ static unsigned char wav_header[44]={ | |||
62 | int open_wav(char* filename) { | 62 | int open_wav(char* filename) { |
63 | int fd; | 63 | int fd; |
64 | 64 | ||
65 | fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR); | 65 | fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR); |
66 | if (fd >= 0) { | 66 | if (fd >= 0) { |
67 | if (write(fd,wav_header,sizeof(wav_header)) < sizeof(wav_header)) { | 67 | if (write(fd,wav_header,sizeof(wav_header)) < sizeof(wav_header)) { |
68 | fprintf(stderr,"[ERR} Failed to write wav header\n"); | 68 | fprintf(stderr,"[ERR} Failed to write wav header\n"); |
diff --git a/apps/codecs/libspc/spc_profiler.c b/apps/codecs/libspc/spc_profiler.c index 3184ad7b52..0ced8b5bd3 100644 --- a/apps/codecs/libspc/spc_profiler.c +++ b/apps/codecs/libspc/spc_profiler.c | |||
@@ -45,7 +45,7 @@ void reset_profile_timers(void) | |||
45 | 45 | ||
46 | void print_timers(char * path) | 46 | void print_timers(char * path) |
47 | { | 47 | { |
48 | int logfd = ci->open("/spclog.txt",O_WRONLY|O_CREAT|O_APPEND); | 48 | int logfd = ci->open("/spclog.txt",O_WRONLY|O_CREAT|O_APPEND, 0666); |
49 | ci->fdprintf(logfd,"%s:\t",path); | 49 | ci->fdprintf(logfd,"%s:\t",path); |
50 | ci->fdprintf(logfd,"%10ld total\t",READ_TIMER(total)); | 50 | ci->fdprintf(logfd,"%10ld total\t",READ_TIMER(total)); |
51 | PRINT_TIMER_PCT(render,total,"render"); | 51 | PRINT_TIMER_PCT(render,total,"render"); |
diff --git a/apps/codecs/mp3_enc.c b/apps/codecs/mp3_enc.c index d04b9e6c42..b35702b0d0 100644 --- a/apps/codecs/mp3_enc.c +++ b/apps/codecs/mp3_enc.c | |||
@@ -2434,7 +2434,7 @@ static bool on_start_file(struct enc_file_event_data *data) | |||
2434 | if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0') | 2434 | if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0') |
2435 | return false; | 2435 | return false; |
2436 | 2436 | ||
2437 | data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC); | 2437 | data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
2438 | 2438 | ||
2439 | if (data->rec_file < 0) | 2439 | if (data->rec_file < 0) |
2440 | return false; | 2440 | return false; |
diff --git a/apps/codecs/nsf.c b/apps/codecs/nsf.c index 6beb8fe3e6..f596f9dc68 100644 --- a/apps/codecs/nsf.c +++ b/apps/codecs/nsf.c | |||
@@ -98,7 +98,7 @@ void reset_profile_timers(void) { | |||
98 | int logfd=-1; | 98 | int logfd=-1; |
99 | 99 | ||
100 | void print_timers(char * path, int track) { | 100 | void print_timers(char * path, int track) { |
101 | logfd = ci->open("/nsflog.txt",O_WRONLY|O_CREAT|O_APPEND); | 101 | logfd = ci->open("/nsflog.txt",O_WRONLY|O_CREAT|O_APPEND, 0666); |
102 | ci->fdprintf(logfd,"%s[%d]:\t",path,track); | 102 | ci->fdprintf(logfd,"%s[%d]:\t",path,track); |
103 | ci->fdprintf(logfd,"%10ld total\t",READ_TIMER(total)); | 103 | ci->fdprintf(logfd,"%10ld total\t",READ_TIMER(total)); |
104 | PRINT_TIMER_PCT(cpu,total,"CPU"); | 104 | PRINT_TIMER_PCT(cpu,total,"CPU"); |
diff --git a/apps/codecs/wav_enc.c b/apps/codecs/wav_enc.c index 38230c846b..4cecb0b2b6 100644 --- a/apps/codecs/wav_enc.c +++ b/apps/codecs/wav_enc.c | |||
@@ -122,7 +122,7 @@ static bool on_start_file(struct enc_file_event_data *data) | |||
122 | if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0') | 122 | if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0') |
123 | return false; | 123 | return false; |
124 | 124 | ||
125 | data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC); | 125 | data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
126 | 126 | ||
127 | if (data->rec_file < 0) | 127 | if (data->rec_file < 0) |
128 | return false; | 128 | return false; |
diff --git a/apps/codecs/wavpack_enc.c b/apps/codecs/wavpack_enc.c index e7da6efa75..7a5f35a53a 100644 --- a/apps/codecs/wavpack_enc.c +++ b/apps/codecs/wavpack_enc.c | |||
@@ -227,7 +227,7 @@ static bool on_start_file(struct enc_file_event_data *data) | |||
227 | if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0') | 227 | if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0') |
228 | return false; | 228 | return false; |
229 | 229 | ||
230 | data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC); | 230 | data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
231 | 231 | ||
232 | if (data->rec_file < 0) | 232 | if (data->rec_file < 0) |
233 | return false; | 233 | return false; |
diff --git a/apps/logfdisp.c b/apps/logfdisp.c index 2057a3b886..41b84778ba 100644 --- a/apps/logfdisp.c +++ b/apps/logfdisp.c | |||
@@ -233,7 +233,7 @@ bool logfdump(void) | |||
233 | /* nothing is logged just yet */ | 233 | /* nothing is logged just yet */ |
234 | return false; | 234 | return false; |
235 | 235 | ||
236 | fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC); | 236 | fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC, 0666); |
237 | if(-1 != fd) { | 237 | if(-1 != fd) { |
238 | int i; | 238 | int i; |
239 | 239 | ||
diff --git a/apps/mpeg.c b/apps/mpeg.c index f903e86b15..7917015a9b 100644 --- a/apps/mpeg.c +++ b/apps/mpeg.c | |||
@@ -1923,7 +1923,7 @@ static void mpeg_thread(void) | |||
1923 | 1923 | ||
1924 | if (mpeg_file < 0) /* delayed file open */ | 1924 | if (mpeg_file < 0) /* delayed file open */ |
1925 | { | 1925 | { |
1926 | mpeg_file = open(delayed_filename, O_WRONLY|O_CREAT); | 1926 | mpeg_file = open(delayed_filename, O_WRONLY|O_CREAT, 0666); |
1927 | 1927 | ||
1928 | if (mpeg_file < 0) | 1928 | if (mpeg_file < 0) |
1929 | panicf("recfile: %d", mpeg_file); | 1929 | panicf("recfile: %d", mpeg_file); |
diff --git a/apps/playlist.c b/apps/playlist.c index d90de38f37..da801968ef 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -336,7 +336,7 @@ static void new_playlist(struct playlist_info* playlist, const char *dir, | |||
336 | static void create_control(struct playlist_info* playlist) | 336 | static void create_control(struct playlist_info* playlist) |
337 | { | 337 | { |
338 | playlist->control_fd = open(playlist->control_filename, | 338 | playlist->control_fd = open(playlist->control_filename, |
339 | O_CREAT|O_RDWR|O_TRUNC); | 339 | O_CREAT|O_RDWR|O_TRUNC, 0666); |
340 | if (playlist->control_fd < 0) | 340 | if (playlist->control_fd < 0) |
341 | { | 341 | { |
342 | if (check_rockboxdir()) | 342 | if (check_rockboxdir()) |
@@ -414,7 +414,7 @@ static int recreate_control(struct playlist_info* playlist) | |||
414 | return -1; | 414 | return -1; |
415 | 415 | ||
416 | playlist->control_fd = open(playlist->control_filename, | 416 | playlist->control_fd = open(playlist->control_filename, |
417 | O_CREAT|O_RDWR|O_TRUNC); | 417 | O_CREAT|O_RDWR|O_TRUNC, 0666); |
418 | if (playlist->control_fd < 0) | 418 | if (playlist->control_fd < 0) |
419 | return -1; | 419 | return -1; |
420 | 420 | ||
@@ -3375,7 +3375,7 @@ int playlist_save(struct playlist_info* playlist, char *filename) | |||
3375 | else | 3375 | else |
3376 | { | 3376 | { |
3377 | /* some applications require a BOM to read the file properly */ | 3377 | /* some applications require a BOM to read the file properly */ |
3378 | fd = open(path, O_CREAT|O_WRONLY|O_TRUNC); | 3378 | fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, 0666); |
3379 | } | 3379 | } |
3380 | if (fd < 0) | 3380 | if (fd < 0) |
3381 | { | 3381 | { |
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index 44fd42f7f2..4f3c8af231 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c | |||
@@ -349,7 +349,7 @@ static int add_to_playlist(const char* playlist, bool new_playlist, | |||
349 | if (new_playlist) | 349 | if (new_playlist) |
350 | fd = open_utf8(playlist, O_CREAT|O_WRONLY|O_TRUNC); | 350 | fd = open_utf8(playlist, O_CREAT|O_WRONLY|O_TRUNC); |
351 | else | 351 | else |
352 | fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND); | 352 | fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND, 0666); |
353 | 353 | ||
354 | if(fd < 0) | 354 | if(fd < 0) |
355 | return result; | 355 | return result; |
diff --git a/apps/plugin.c b/apps/plugin.c index 28d443321f..baf9b60eb8 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -93,9 +93,9 @@ static char current_plugin[MAX_PATH]; | |||
93 | 93 | ||
94 | char *plugin_get_current_filename(void); | 94 | char *plugin_get_current_filename(void); |
95 | 95 | ||
96 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | ||
97 | /* Some wrappers used to monitor open and close and detect leaks*/ | 96 | /* Some wrappers used to monitor open and close and detect leaks*/ |
98 | static int open_wrapper(const char* pathname, int flags); | 97 | static int open_wrapper(const char* pathname, int flags, ...); |
98 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | ||
99 | static int close_wrapper(int fd); | 99 | static int close_wrapper(int fd); |
100 | static int creat_wrapper(const char *pathname, mode_t mode); | 100 | static int creat_wrapper(const char *pathname, mode_t mode); |
101 | #endif | 101 | #endif |
@@ -299,13 +299,12 @@ static const struct plugin_api rockbox_api = { | |||
299 | 299 | ||
300 | /* file */ | 300 | /* file */ |
301 | open_utf8, | 301 | open_utf8, |
302 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | ||
303 | (open_func)open_wrapper, | 302 | (open_func)open_wrapper, |
303 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | ||
304 | close_wrapper, | 304 | close_wrapper, |
305 | #else | 305 | #else |
306 | (open_func)PREFIX(open), | ||
307 | PREFIX(close), | 306 | PREFIX(close), |
308 | #endif | 307 | #endif |
309 | (read_func)PREFIX(read), | 308 | (read_func)PREFIX(read), |
310 | PREFIX(lseek), | 309 | PREFIX(lseek), |
311 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | 310 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE |
@@ -979,17 +978,34 @@ char *plugin_get_current_filename(void) | |||
979 | return current_plugin; | 978 | return current_plugin; |
980 | } | 979 | } |
981 | 980 | ||
982 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | 981 | static int open_wrapper(const char* pathname, int flags, ...) |
983 | static int open_wrapper(const char* pathname, int flags) | ||
984 | { | 982 | { |
985 | int fd = PREFIX(open)(pathname,flags); | 983 | /* we don't have an 'open' function. it's a define. and we need |
984 | * the real file_open, hence PREFIX() doesn't work here */ | ||
985 | int fd; | ||
986 | #ifdef SIMULATOR | ||
987 | if (flags & O_CREAT) | ||
988 | { | ||
989 | va_list ap; | ||
990 | va_start(ap, flags); | ||
991 | int fd; | ||
992 | fd = sim_open(pathname, flags, va_arg(ap, mode_t)); | ||
993 | va_end(ap); | ||
994 | } | ||
995 | else | ||
996 | fd = sim_open(pathname, flags); | ||
997 | #else | ||
998 | fd = file_open(pathname,flags); | ||
999 | #endif | ||
986 | 1000 | ||
1001 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | ||
987 | if(fd >= 0) | 1002 | if(fd >= 0) |
988 | open_files |= 1<<fd; | 1003 | open_files |= 1<<fd; |
989 | 1004 | #endif | |
990 | return fd; | 1005 | return fd; |
991 | } | 1006 | } |
992 | 1007 | ||
1008 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | ||
993 | static int close_wrapper(int fd) | 1009 | static int close_wrapper(int fd) |
994 | { | 1010 | { |
995 | if((~open_files) & (1<<fd)) | 1011 | if((~open_files) & (1<<fd)) |
diff --git a/apps/plugin.h b/apps/plugin.h index aa6108a8ab..5f594e6cf5 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -397,7 +397,7 @@ struct plugin_api { | |||
397 | 397 | ||
398 | /* file */ | 398 | /* file */ |
399 | int (*open_utf8)(const char* pathname, int flags); | 399 | int (*open_utf8)(const char* pathname, int flags); |
400 | int (*open)(const char* pathname, int flags); | 400 | int (*open)(const char* pathname, int flags, ...); |
401 | int (*close)(int fd); | 401 | int (*close)(int fd); |
402 | ssize_t (*read)(int fd, void* buf, size_t count); | 402 | ssize_t (*read)(int fd, void* buf, size_t count); |
403 | off_t (*lseek)(int fd, off_t offset, int whence); | 403 | off_t (*lseek)(int fd, off_t offset, int whence); |
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index 5c04892d61..165ce54634 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c | |||
@@ -336,7 +336,7 @@ static void flush_buffer(void* data) | |||
336 | if (in_usb_mode || (buf_idx == 0)) | 336 | if (in_usb_mode || (buf_idx == 0)) |
337 | return; | 337 | return; |
338 | 338 | ||
339 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND); | 339 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND, 0666); |
340 | if (fd < 0) | 340 | if (fd < 0) |
341 | return; | 341 | return; |
342 | 342 | ||
@@ -446,7 +446,7 @@ void thread(void) | |||
446 | rb->unregister_storage_idle_func(flush_buffer, true); | 446 | rb->unregister_storage_idle_func(flush_buffer, true); |
447 | 447 | ||
448 | /* log end of bench and exit reason */ | 448 | /* log end of bench and exit reason */ |
449 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND); | 449 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND, 0666); |
450 | if (fd >= 0) | 450 | if (fd >= 0) |
451 | { | 451 | { |
452 | rb->fdprintf(fd, "--Battery bench ended, reason: %s--\n", exit_reason); | 452 | rb->fdprintf(fd, "--Battery bench ended, reason: %s--\n", exit_reason); |
@@ -525,7 +525,7 @@ int main(void) | |||
525 | fd = rb->open(BATTERY_LOG, O_RDONLY); | 525 | fd = rb->open(BATTERY_LOG, O_RDONLY); |
526 | if (fd < 0) | 526 | if (fd < 0) |
527 | { | 527 | { |
528 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT); | 528 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT, 0666); |
529 | if (fd >= 0) | 529 | if (fd >= 0) |
530 | { | 530 | { |
531 | rb->fdprintf(fd, | 531 | rb->fdprintf(fd, |
diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c index 1af26f290f..7b3dbef805 100644 --- a/apps/plugins/blackjack.c +++ b/apps/plugins/blackjack.c | |||
@@ -871,7 +871,7 @@ static void blackjack_savegame(struct game_context* bj) { | |||
871 | if(!resume) | 871 | if(!resume) |
872 | return; | 872 | return; |
873 | /* write out the game state to the save file */ | 873 | /* write out the game state to the save file */ |
874 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT); | 874 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666); |
875 | if(fd < 0) | 875 | if(fd < 0) |
876 | return; | 876 | return; |
877 | rb->write(fd, bj, sizeof(struct game_context)); | 877 | rb->write(fd, bj, sizeof(struct game_context)); |
diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c index 60e8f3820b..98de3d439f 100644 --- a/apps/plugins/brickmania.c +++ b/apps/plugins/brickmania.c | |||
@@ -1265,7 +1265,7 @@ static void brickmania_savegame(void) | |||
1265 | int fd; | 1265 | int fd; |
1266 | 1266 | ||
1267 | /* write out the game state to the save file */ | 1267 | /* write out the game state to the save file */ |
1268 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT); | 1268 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666); |
1269 | if(fd < 0) return; | 1269 | if(fd < 0) return; |
1270 | 1270 | ||
1271 | if ((rb->write(fd, &pad_pos_x, sizeof(pad_pos_x)) <= 0) || | 1271 | if ((rb->write(fd, &pad_pos_x, sizeof(pad_pos_x)) <= 0) || |
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c index a3de9d2511..514621224a 100644 --- a/apps/plugins/bubbles.c +++ b/apps/plugins/bubbles.c | |||
@@ -2212,7 +2212,7 @@ static void bubbles_savedata(void) { | |||
2212 | if (last_highlevel >= highlevel) /* no need to save */ | 2212 | if (last_highlevel >= highlevel) /* no need to save */ |
2213 | return; | 2213 | return; |
2214 | 2214 | ||
2215 | fd = rb->open(DATA_FILE, O_WRONLY|O_CREAT); | 2215 | fd = rb->open(DATA_FILE, O_WRONLY|O_CREAT, 0666); |
2216 | if (fd < 0) return; | 2216 | if (fd < 0) return; |
2217 | 2217 | ||
2218 | rb->write(fd, &highlevel, sizeof(highlevel)); | 2218 | rb->write(fd, &highlevel, sizeof(highlevel)); |
@@ -2252,7 +2252,7 @@ static void bubbles_savegame(struct game_context* bb) { | |||
2252 | if (!resume) /* nothing to save */ | 2252 | if (!resume) /* nothing to save */ |
2253 | return; | 2253 | return; |
2254 | /* write out the game state to the save file */ | 2254 | /* write out the game state to the save file */ |
2255 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT); | 2255 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666); |
2256 | if (fd < 0) | 2256 | if (fd < 0) |
2257 | { | 2257 | { |
2258 | rb->splash(HZ/2, "Failed to save game"); | 2258 | rb->splash(HZ/2, "Failed to save game"); |
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 3589998e47..13abdfc29a 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c | |||
@@ -611,7 +611,7 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown) | |||
611 | { | 611 | { |
612 | int fp, fq; | 612 | int fp, fq; |
613 | /* use O_RDWR|O_CREAT so that file is created if it doesn't exist. */ | 613 | /* use O_RDWR|O_CREAT so that file is created if it doesn't exist. */ |
614 | fp = rb->open(MEMO_FILE, O_RDWR|O_CREAT); | 614 | fp = rb->open(MEMO_FILE, O_RDWR|O_CREAT, 0666); |
615 | fq = rb->creat(TEMP_FILE, 0666); | 615 | fq = rb->creat(TEMP_FILE, 0666); |
616 | if ( (fq > -1) && (fp > -1) ) | 616 | if ( (fq > -1) && (fp > -1) ) |
617 | { | 617 | { |
diff --git a/apps/plugins/chessbox/chessbox.c b/apps/plugins/chessbox/chessbox.c index 72a8b238a8..45f052d30a 100644 --- a/apps/plugins/chessbox/chessbox.c +++ b/apps/plugins/chessbox/chessbox.c | |||
@@ -275,7 +275,7 @@ void cb_saveposition ( void ) { | |||
275 | 275 | ||
276 | rb->splash ( 0 , "Saving position" ); | 276 | rb->splash ( 0 , "Saving position" ); |
277 | 277 | ||
278 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT); | 278 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666); |
279 | 279 | ||
280 | computer++; rb->write(fd, &(computer), sizeof(computer)); computer--; | 280 | computer++; rb->write(fd, &(computer), sizeof(computer)); computer--; |
281 | opponent++; rb->write(fd, &(opponent), sizeof(opponent)); opponent--; | 281 | opponent++; rb->write(fd, &(opponent), sizeof(opponent)); opponent--; |
diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c index a165e3ee8c..3d699a7c9e 100644 --- a/apps/plugins/chessbox/chessbox_pgn.c +++ b/apps/plugins/chessbox/chessbox_pgn.c | |||
@@ -670,7 +670,7 @@ void pgn_parse_game(const char* filename, | |||
670 | rb->read_line(fhandler, line_buffer, sizeof line_buffer); | 670 | rb->read_line(fhandler, line_buffer, sizeof line_buffer); |
671 | } | 671 | } |
672 | 672 | ||
673 | loghandler = rb->open(LOG_FILE, O_WRONLY | O_CREAT); | 673 | loghandler = rb->open(LOG_FILE, O_WRONLY | O_CREAT, 0666); |
674 | 674 | ||
675 | GNUChess_Initialize(); | 675 | GNUChess_Initialize(); |
676 | 676 | ||
@@ -829,7 +829,7 @@ void pgn_store_game(struct pgn_game_node* game){ | |||
829 | ply_count++; | 829 | ply_count++; |
830 | } | 830 | } |
831 | 831 | ||
832 | fhandler = rb->open(PGN_FILE, O_WRONLY|O_CREAT|O_APPEND); | 832 | fhandler = rb->open(PGN_FILE, O_WRONLY|O_CREAT|O_APPEND, 0666); |
833 | 833 | ||
834 | 834 | ||
835 | /* the first 7 tags are mandatory according to the PGN specification so we | 835 | /* the first 7 tags are mandatory according to the PGN specification so we |
diff --git a/apps/plugins/crypt_firmware.c b/apps/plugins/crypt_firmware.c index 36689b7e8c..051a3d1bd9 100644 --- a/apps/plugins/crypt_firmware.c +++ b/apps/plugins/crypt_firmware.c | |||
@@ -246,7 +246,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
246 | memcpy(buf + 1, "nn2x", 4); | 246 | memcpy(buf + 1, "nn2x", 4); |
247 | 247 | ||
248 | /* 4 - Write to disk */ | 248 | /* 4 - Write to disk */ |
249 | fd = rb->open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC); | 249 | fd = rb->open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC, 0666); |
250 | 250 | ||
251 | if (fd < 0) { | 251 | if (fd < 0) { |
252 | rb->splash(HZ*2, "Could not open output file"); | 252 | rb->splash(HZ*2, "Could not open output file"); |
@@ -307,7 +307,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
307 | memcpy(buf + 1, "nn2g", 4); | 307 | memcpy(buf + 1, "nn2g", 4); |
308 | 308 | ||
309 | /* 4 - Write to disk */ | 309 | /* 4 - Write to disk */ |
310 | fd = rb->open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC); | 310 | fd = rb->open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC, 0666); |
311 | 311 | ||
312 | if (fd < 0) { | 312 | if (fd < 0) { |
313 | rb->splash(HZ*2, "Could not open output file"); | 313 | rb->splash(HZ*2, "Could not open output file"); |
diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c index 21efbc4147..1383a2b520 100644 --- a/apps/plugins/doom/rockdoom.c +++ b/apps/plugins/doom/rockdoom.c | |||
@@ -63,13 +63,20 @@ int fileexists(const char * fname) | |||
63 | } | 63 | } |
64 | 64 | ||
65 | #ifndef SIMULATOR | 65 | #ifndef SIMULATOR |
66 | int my_open(const char *file, int flags) | 66 | int my_open(const char *file, int flags, ...) |
67 | { | 67 | { |
68 | if(fpoint==8) | 68 | if(fpoint==8) |
69 | return -1; | 69 | return -1; |
70 | #undef open | 70 | #undef open |
71 | filearray[fpoint]=rb->open(file, flags); | 71 | if (flags & O_CREAT) |
72 | 72 | { | |
73 | va_list ap; | ||
74 | va_start(ap, flags); | ||
75 | filearray[fpoint]=rb->open(file, flags, va_arg(ap, mode_t)); | ||
76 | va_end(ap); | ||
77 | } | ||
78 | else | ||
79 | filearray[fpoint]=rb->open(file, flags); | ||
73 | if(filearray[fpoint]<0) | 80 | if(filearray[fpoint]<0) |
74 | return filearray[fpoint]; | 81 | return filearray[fpoint]; |
75 | 82 | ||
diff --git a/apps/plugins/doom/rockmacros.h b/apps/plugins/doom/rockmacros.h index 98f908dc1d..e066fe861c 100644 --- a/apps/plugins/doom/rockmacros.h +++ b/apps/plugins/doom/rockmacros.h | |||
@@ -39,12 +39,12 @@ char *my_strtok( char * s, const char * delim ); | |||
39 | #define read_line(a,b,c) rb->read_line((a),(b),(c)) | 39 | #define read_line(a,b,c) rb->read_line((a),(b),(c)) |
40 | 40 | ||
41 | #ifdef SIMULATOR | 41 | #ifdef SIMULATOR |
42 | #define open(a,b) rb->open((a),(b)) | 42 | #define open(a, ...) rb->open((a), __VA_ARGS__) |
43 | #define close(a) rb->close((a)) | 43 | #define close(a) rb->close((a)) |
44 | #else | 44 | #else |
45 | int my_open(const char *file, int flags); | 45 | int my_open(const char *file, int flags, ...); |
46 | int my_close(int id); | 46 | int my_close(int id); |
47 | #define open(a,b) my_open((a),(b)) | 47 | #define open(a, ...) my_open((a), __VA_ARGS__) |
48 | #define close(a) my_close((a)) | 48 | #define close(a) my_close((a)) |
49 | #endif | 49 | #endif |
50 | 50 | ||
diff --git a/apps/plugins/frotz/fastmem.c b/apps/plugins/frotz/fastmem.c index ba0c95f5ce..ce424af1f2 100644 --- a/apps/plugins/frotz/fastmem.c +++ b/apps/plugins/frotz/fastmem.c | |||
@@ -837,7 +837,7 @@ void z_save (void) | |||
837 | 837 | ||
838 | /* Open auxilary file */ | 838 | /* Open auxilary file */ |
839 | 839 | ||
840 | if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC)) < 0) | 840 | if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
841 | goto finished; | 841 | goto finished; |
842 | 842 | ||
843 | /* Write auxilary file */ | 843 | /* Write auxilary file */ |
@@ -859,7 +859,7 @@ void z_save (void) | |||
859 | 859 | ||
860 | /* Open game file */ | 860 | /* Open game file */ |
861 | 861 | ||
862 | if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC)) < 0) | 862 | if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
863 | goto finished; | 863 | goto finished; |
864 | 864 | ||
865 | success = save_quetzal (gfp, story_fp); | 865 | success = save_quetzal (gfp, story_fp); |
diff --git a/apps/plugins/frotz/files.c b/apps/plugins/frotz/files.c index 1baaa4073f..7ca916186c 100644 --- a/apps/plugins/frotz/files.c +++ b/apps/plugins/frotz/files.c | |||
@@ -74,7 +74,7 @@ void script_open (void) | |||
74 | 74 | ||
75 | /* Opening in "at" mode doesn't work for script_erase_input... */ | 75 | /* Opening in "at" mode doesn't work for script_erase_input... */ |
76 | 76 | ||
77 | if ((sfp = rb->open (script_name, O_RDWR|O_CREAT)) != -1) { | 77 | if ((sfp = rb->open (script_name, O_RDWR|O_CREAT, 0666)) != -1) { |
78 | 78 | ||
79 | fseek (sfp, 0, SEEK_END); | 79 | fseek (sfp, 0, SEEK_END); |
80 | 80 | ||
@@ -290,7 +290,7 @@ void record_open (void) | |||
290 | 290 | ||
291 | strcpy (command_name, new_name); | 291 | strcpy (command_name, new_name); |
292 | 292 | ||
293 | if ((rfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC)) != -1) | 293 | if ((rfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) != -1) |
294 | ostream_record = TRUE; | 294 | ostream_record = TRUE; |
295 | else | 295 | else |
296 | print_string ("Cannot open file\n"); | 296 | print_string ("Cannot open file\n"); |
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c index 6bed9bf827..c2340aa557 100644 --- a/apps/plugins/jewels.c +++ b/apps/plugins/jewels.c | |||
@@ -498,7 +498,7 @@ static void jewels_savegame(struct game_context* bj) | |||
498 | { | 498 | { |
499 | int fd; | 499 | int fd; |
500 | /* write out the game state to the save file */ | 500 | /* write out the game state to the save file */ |
501 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT); | 501 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666); |
502 | if(fd < 0) return; | 502 | if(fd < 0) return; |
503 | 503 | ||
504 | rb->write(fd, &bj->tmp_type, sizeof(bj->tmp_type)); | 504 | rb->write(fd, &bj->tmp_type, sizeof(bj->tmp_type)); |
diff --git a/apps/plugins/keybox.c b/apps/plugins/keybox.c index f8da40f08e..c6b060c7fd 100644 --- a/apps/plugins/keybox.c +++ b/apps/plugins/keybox.c | |||
@@ -584,7 +584,7 @@ static int keybox(void) | |||
584 | 584 | ||
585 | if (data_changed) | 585 | if (data_changed) |
586 | { | 586 | { |
587 | fd = rb->open(KEYBOX_FILE, O_WRONLY | O_CREAT | O_TRUNC); | 587 | fd = rb->open(KEYBOX_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
588 | if (fd < 0) | 588 | if (fd < 0) |
589 | return FILE_OPEN_ERROR; | 589 | return FILE_OPEN_ERROR; |
590 | write_output(fd); | 590 | write_output(fd); |
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c index 9ada06e8fe..185930202a 100644 --- a/apps/plugins/lib/highscore.c +++ b/apps/plugins/lib/highscore.c | |||
@@ -33,7 +33,7 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores) | |||
33 | if(!highscore_updated) | 33 | if(!highscore_updated) |
34 | return 1; | 34 | return 1; |
35 | 35 | ||
36 | fd = rb->open(filename, O_WRONLY|O_CREAT); | 36 | fd = rb->open(filename, O_WRONLY|O_CREAT, 0666); |
37 | if(fd < 0) | 37 | if(fd < 0) |
38 | return -1; | 38 | return -1; |
39 | 39 | ||
diff --git a/apps/plugins/lua/liolib.c b/apps/plugins/lua/liolib.c index e50524ae89..7a43915f20 100644 --- a/apps/plugins/lua/liolib.c +++ b/apps/plugins/lua/liolib.c | |||
@@ -158,7 +158,7 @@ static int io_open (lua_State *L) { | |||
158 | } | 158 | } |
159 | if((*mode == 'w' || *mode == 'a') && !rb->file_exists(filename)) | 159 | if((*mode == 'w' || *mode == 'a') && !rb->file_exists(filename)) |
160 | flags |= O_CREAT; | 160 | flags |= O_CREAT; |
161 | *pf = rb->open(filename, flags); | 161 | *pf = rb->open(filename, flags, 0666); |
162 | return (*pf < 0) ? pushresult(L, 0, filename) : 1; | 162 | return (*pf < 0) ? pushresult(L, 0, filename) : 1; |
163 | } | 163 | } |
164 | 164 | ||
diff --git a/apps/plugins/md5sum.c b/apps/plugins/md5sum.c index 973ffb3237..9dd8f5a8a7 100644 --- a/apps/plugins/md5sum.c +++ b/apps/plugins/md5sum.c | |||
@@ -246,7 +246,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
246 | done = 0; | 246 | done = 0; |
247 | action( out, arg ); | 247 | action( out, arg ); |
248 | 248 | ||
249 | out = rb->open( filename, O_WRONLY|O_CREAT|O_TRUNC ); | 249 | out = rb->open( filename, O_WRONLY|O_CREAT|O_TRUNC , 0666); |
250 | if( out < 0 ) return PLUGIN_ERROR; | 250 | if( out < 0 ) return PLUGIN_ERROR; |
251 | action( out, arg ); | 251 | action( out, arg ); |
252 | rb->close( out ); | 252 | rb->close( out ); |
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c index 50aa99b2ae..fe417ce180 100644 --- a/apps/plugins/mp3_encoder.c +++ b/apps/plugins/mp3_encoder.c | |||
@@ -2598,7 +2598,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
2598 | { | 2598 | { |
2599 | init_mp3_encoder_engine(true, brate[srat], cfg.samplerate); | 2599 | init_mp3_encoder_engine(true, brate[srat], cfg.samplerate); |
2600 | get_mp3_filename(wav_filename); | 2600 | get_mp3_filename(wav_filename); |
2601 | mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC); | 2601 | mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC, 0666); |
2602 | frames = 0; | 2602 | frames = 0; |
2603 | 2603 | ||
2604 | tim = *rb->current_tick; | 2604 | tim = *rb->current_tick; |
diff --git a/apps/plugins/pdbox/PDa/intern/sfwrite~.c b/apps/plugins/pdbox/PDa/intern/sfwrite~.c index ba63322380..49df0b7eeb 100644 --- a/apps/plugins/pdbox/PDa/intern/sfwrite~.c +++ b/apps/plugins/pdbox/PDa/intern/sfwrite~.c | |||
@@ -91,11 +91,7 @@ static void sfwrite_open(t_sfwrite *x,t_symbol *filename) | |||
91 | 91 | ||
92 | sfwrite_close(x); | 92 | sfwrite_close(x); |
93 | 93 | ||
94 | #ifdef ROCKBOX | ||
95 | if ((x->x_file = open(fname, O_RDWR | O_CREAT)) < 0) | ||
96 | #else | ||
97 | if ((x->x_file = open(fname,O_RDWR | O_CREAT,0664)) < 0) | 94 | if ((x->x_file = open(fname,O_RDWR | O_CREAT,0664)) < 0) |
98 | #endif | ||
99 | { | 95 | { |
100 | error("can't create %s",fname); | 96 | error("can't create %s",fname); |
101 | return; | 97 | return; |
diff --git a/apps/plugins/pdbox/PDa/src/g_array.c b/apps/plugins/pdbox/PDa/src/g_array.c index 431cfeb31d..f0359e465a 100644 --- a/apps/plugins/pdbox/PDa/src/g_array.c +++ b/apps/plugins/pdbox/PDa/src/g_array.c | |||
@@ -1306,7 +1306,7 @@ static void garray_write(t_garray *x, t_symbol *filename) | |||
1306 | buf, MAXPDSTRING); | 1306 | buf, MAXPDSTRING); |
1307 | sys_bashfilename(buf, buf); | 1307 | sys_bashfilename(buf, buf); |
1308 | #ifdef ROCKBOX | 1308 | #ifdef ROCKBOX |
1309 | if(!(fd = open(buf, O_WRONLY|O_CREAT|O_TRUNC))) | 1309 | if(!(fd = open(buf, O_WRONLY|O_CREAT|O_TRUNC, 0666))) |
1310 | #else | 1310 | #else |
1311 | if (!(fd = fopen(buf, "w"))) | 1311 | if (!(fd = fopen(buf, "w"))) |
1312 | #endif | 1312 | #endif |
@@ -1388,7 +1388,7 @@ static void garray_write16(t_garray *x, t_symbol *filename, t_symbol *format) | |||
1388 | buf2, MAXPDSTRING); | 1388 | buf2, MAXPDSTRING); |
1389 | sys_bashfilename(buf2, buf2); | 1389 | sys_bashfilename(buf2, buf2); |
1390 | #ifdef ROCKBOX | 1390 | #ifdef ROCKBOX |
1391 | if(!(fd = open(buf2, O_WRONLY|O_CREAT|O_TRUNC))) | 1391 | if(!(fd = open(buf2, O_WRONLY|O_CREAT|O_TRUNC, 0666))) |
1392 | #else | 1392 | #else |
1393 | if (!(fd = fopen(buf2, BINWRITEMODE))) | 1393 | if (!(fd = fopen(buf2, BINWRITEMODE))) |
1394 | #endif | 1394 | #endif |
diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c index 6a62fee8ff..d5e7a10cdc 100644 --- a/apps/plugins/random_folder_advance_config.c +++ b/apps/plugins/random_folder_advance_config.c | |||
@@ -214,7 +214,7 @@ void generate(void) | |||
214 | { | 214 | { |
215 | dirs_count = 0; | 215 | dirs_count = 0; |
216 | abort = false; | 216 | abort = false; |
217 | fd = rb->open(RFA_FILE,O_CREAT|O_WRONLY); | 217 | fd = rb->open(RFA_FILE,O_CREAT|O_WRONLY, 0666); |
218 | rb->write(fd,&dirs_count,sizeof(int)); | 218 | rb->write(fd,&dirs_count,sizeof(int)); |
219 | if (fd < 0) | 219 | if (fd < 0) |
220 | { | 220 | { |
diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c index f1ad8399fb..4e261e4547 100644 --- a/apps/plugins/rockblox.c +++ b/apps/plugins/rockblox.c | |||
@@ -877,7 +877,7 @@ static void dump_resume(void) | |||
877 | { | 877 | { |
878 | int fd; | 878 | int fd; |
879 | 879 | ||
880 | fd = rb->open(RESUME_FILE, O_WRONLY|O_CREAT); | 880 | fd = rb->open(RESUME_FILE, O_WRONLY|O_CREAT, 0666); |
881 | if (fd < 0) | 881 | if (fd < 0) |
882 | goto fail; | 882 | goto fail; |
883 | 883 | ||
diff --git a/apps/plugins/rockboy/cpu.c b/apps/plugins/rockboy/cpu.c index 2fc7411411..e1d1324c4b 100644 --- a/apps/plugins/rockboy/cpu.c +++ b/apps/plugins/rockboy/cpu.c | |||
@@ -947,7 +947,7 @@ next: | |||
947 | int fd; | 947 | int fd; |
948 | blockcount++; | 948 | blockcount++; |
949 | snprintf(meow,499,"/dyna_0x%x_run.rb",PC); | 949 | snprintf(meow,499,"/dyna_0x%x_run.rb",PC); |
950 | fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC); | 950 | fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC, 0666); |
951 | if(fd>=0) | 951 | if(fd>=0) |
952 | { | 952 | { |
953 | fdprintf(fd,"Block 0x%x Blockcount: %d\n",PC,blockcount); | 953 | fdprintf(fd,"Block 0x%x Blockcount: %d\n",PC,blockcount); |
diff --git a/apps/plugins/rockboy/dynarec.c b/apps/plugins/rockboy/dynarec.c index afe6caaf1a..3c71115654 100644 --- a/apps/plugins/rockboy/dynarec.c +++ b/apps/plugins/rockboy/dynarec.c | |||
@@ -425,7 +425,7 @@ void dynamic_recompile (struct dynarec_block *newblock) | |||
425 | newblock->block=dynapointer; | 425 | newblock->block=dynapointer; |
426 | #ifdef DYNA_DEBUG | 426 | #ifdef DYNA_DEBUG |
427 | snprintf(meow,499,"/dyna_0x%x_asm.rb",PC); | 427 | snprintf(meow,499,"/dyna_0x%x_asm.rb",PC); |
428 | fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC); | 428 | fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC, 0666); |
429 | if(fd<0) | 429 | if(fd<0) |
430 | { | 430 | { |
431 | die("couldn't open dyna debug file"); | 431 | die("couldn't open dyna debug file"); |
@@ -1907,7 +1907,7 @@ void dynamic_recompile (struct dynarec_block *newblock) | |||
1907 | newblock->length=dynapointer-newblock->block; | 1907 | newblock->length=dynapointer-newblock->block; |
1908 | IF_COP(rb->cpucache_invalidate()); | 1908 | IF_COP(rb->cpucache_invalidate()); |
1909 | snprintf(meow,499,"/dyna_0x%x_code.rb",PC); | 1909 | snprintf(meow,499,"/dyna_0x%x_code.rb",PC); |
1910 | fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC); | 1910 | fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC, 0666); |
1911 | if(fd>=0) | 1911 | if(fd>=0) |
1912 | { | 1912 | { |
1913 | write(fd,newblock->block,newblock->length); | 1913 | write(fd,newblock->block,newblock->length); |
diff --git a/apps/plugins/rockboy/loader.c b/apps/plugins/rockboy/loader.c index 71ab4e78d7..e92b7d0a7e 100644 --- a/apps/plugins/rockboy/loader.c +++ b/apps/plugins/rockboy/loader.c | |||
@@ -249,7 +249,7 @@ static int sram_save(void) | |||
249 | /* If we crash before we ever loaded sram, DO NOT SAVE! */ | 249 | /* If we crash before we ever loaded sram, DO NOT SAVE! */ |
250 | if (!mbc.batt || !ram.loaded || !mbc.ramsize) | 250 | if (!mbc.batt || !ram.loaded || !mbc.ramsize) |
251 | return -1; | 251 | return -1; |
252 | fd = open(sramfile, O_WRONLY|O_CREAT|O_TRUNC); | 252 | fd = open(sramfile, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
253 | if (fd<0) return -1; | 253 | if (fd<0) return -1; |
254 | snprintf(meow,499,"Saving savedata to %s",sramfile); | 254 | snprintf(meow,499,"Saving savedata to %s",sramfile); |
255 | rb->splash(HZ*2, meow); | 255 | rb->splash(HZ*2, meow); |
@@ -263,7 +263,7 @@ static void rtc_save(void) | |||
263 | { | 263 | { |
264 | int fd; | 264 | int fd; |
265 | if (!rtc.batt) return; | 265 | if (!rtc.batt) return; |
266 | if ((fd = open(rtcfile, O_WRONLY|O_CREAT|O_TRUNC))<0) return; | 266 | if ((fd = open(rtcfile, O_WRONLY|O_CREAT|O_TRUNC, 0666))<0) return; |
267 | rtc_save_internal(fd); | 267 | rtc_save_internal(fd); |
268 | close(fd); | 268 | close(fd); |
269 | } | 269 | } |
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c index 710a47646a..2f6c3102ff 100644 --- a/apps/plugins/rockboy/menu.c +++ b/apps/plugins/rockboy/menu.c | |||
@@ -178,7 +178,7 @@ static bool do_file(char *path, char *desc, bool is_load) { | |||
178 | file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT); | 178 | file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT); |
179 | 179 | ||
180 | /* attempt to open file descriptor here */ | 180 | /* attempt to open file descriptor here */ |
181 | if ((fd = open(path, file_mode)) < 0) | 181 | if ((fd = open(path, file_mode, 0666)) < 0) |
182 | return false; | 182 | return false; |
183 | 183 | ||
184 | /* load/save state */ | 184 | /* load/save state */ |
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c index ba60b14f72..ec224a20db 100644 --- a/apps/plugins/rockboy/rockboy.c +++ b/apps/plugins/rockboy/rockboy.c | |||
@@ -325,7 +325,7 @@ static void savesettings(void) | |||
325 | { | 325 | { |
326 | options.dirty=0; | 326 | options.dirty=0; |
327 | snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); | 327 | snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); |
328 | fd = open(optionsave, O_WRONLY|O_CREAT|O_TRUNC); | 328 | fd = open(optionsave, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
329 | write(fd,&options, sizeof(options)); | 329 | write(fd,&options, sizeof(options)); |
330 | close(fd); | 330 | close(fd); |
331 | } | 331 | } |
diff --git a/apps/plugins/rockboy/rockmacros.h b/apps/plugins/rockboy/rockmacros.h index 0fd13f6ef9..e7f79a53d3 100644 --- a/apps/plugins/rockboy/rockmacros.h +++ b/apps/plugins/rockboy/rockmacros.h | |||
@@ -59,7 +59,9 @@ void dynamic_recompile (struct dynarec_block *newblock); | |||
59 | #define isalpha(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && ((c) <= 'Z'))) | 59 | #define isalpha(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && ((c) <= 'Z'))) |
60 | #define isalnum(c) (isdigit(c) || (isalpha(c))) | 60 | #define isalnum(c) (isdigit(c) || (isalpha(c))) |
61 | 61 | ||
62 | #define open(a,b) rb->open((a),(b)) | 62 | /* only 1 fixed argument for open, since variadic macros don't except empty |
63 | * variable parameters */ | ||
64 | #define open(a, ...) rb->open((a), __VA_ARGS__) | ||
63 | #define lseek(a,b,c) rb->lseek((a),(b),(c)) | 65 | #define lseek(a,b,c) rb->lseek((a),(b),(c)) |
64 | #define close(a) rb->close((a)) | 66 | #define close(a) rb->close((a)) |
65 | #define read(a,b,c) rb->read((a),(b),(c)) | 67 | #define read(a,b,c) rb->read((a),(b),(c)) |
diff --git a/apps/plugins/search.c b/apps/plugins/search.c index 4f60c82d08..ba16b8821b 100644 --- a/apps/plugins/search.c +++ b/apps/plugins/search.c | |||
@@ -123,7 +123,7 @@ static bool search_init(const char* file){ | |||
123 | if (bomsize) | 123 | if (bomsize) |
124 | fdw = rb->open_utf8(resultfile, O_WRONLY|O_CREAT|O_TRUNC); | 124 | fdw = rb->open_utf8(resultfile, O_WRONLY|O_CREAT|O_TRUNC); |
125 | else | 125 | else |
126 | fdw = rb->open(resultfile, O_WRONLY|O_CREAT|O_TRUNC); | 126 | fdw = rb->open(resultfile, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
127 | 127 | ||
128 | if (fdw < 0) { | 128 | if (fdw < 0) { |
129 | #ifdef HAVE_LCD_BITMAP | 129 | #ifdef HAVE_LCD_BITMAP |
diff --git a/apps/plugins/searchengine/searchengine.c b/apps/plugins/searchengine/searchengine.c index ddcd0ead0d..f737a27621 100644 --- a/apps/plugins/searchengine/searchengine.c +++ b/apps/plugins/searchengine/searchengine.c | |||
@@ -78,7 +78,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
78 | rb->close(parsefd); | 78 | rb->close(parsefd); |
79 | hits=0; | 79 | hits=0; |
80 | if(result!=0) { | 80 | if(result!=0) { |
81 | int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC); | 81 | int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC, 0666); |
82 | int i; | 82 | int i; |
83 | for(i=0;i<rb->tagdbheader->filecount;i++) | 83 | for(i=0;i<rb->tagdbheader->filecount;i++) |
84 | if(result[i]) { | 84 | if(result[i]) { |
diff --git a/apps/plugins/settings_dumper.c b/apps/plugins/settings_dumper.c index 68c2433ce6..ea69353e17 100644 --- a/apps/plugins/settings_dumper.c +++ b/apps/plugins/settings_dumper.c | |||
@@ -124,7 +124,7 @@ enum plugin_status plugin_start( | |||
124 | int fd; | 124 | int fd; |
125 | (void)parameter; | 125 | (void)parameter; |
126 | 126 | ||
127 | fd = rb->open(FILENAME, O_CREAT|O_TRUNC|O_WRONLY); | 127 | fd = rb->open(FILENAME, O_CREAT|O_TRUNC|O_WRONLY, 0666); |
128 | if (fd < 0) | 128 | if (fd < 0) |
129 | return PLUGIN_ERROR; | 129 | return PLUGIN_ERROR; |
130 | list = rb->get_settings_list(&setting_count); | 130 | list = rb->get_settings_list(&setting_count); |
diff --git a/apps/plugins/sokoban.c b/apps/plugins/sokoban.c index 838b4de5b0..3a853c81aa 100644 --- a/apps/plugins/sokoban.c +++ b/apps/plugins/sokoban.c | |||
@@ -1117,7 +1117,7 @@ static bool save(char *filename, bool solution) | |||
1117 | } | 1117 | } |
1118 | 1118 | ||
1119 | if (filename[0] == '\0' || | 1119 | if (filename[0] == '\0' || |
1120 | (fd = rb->open(filename, O_WRONLY|O_CREAT|O_TRUNC)) < 0) { | 1120 | (fd = rb->open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) { |
1121 | rb->splashf(HZ*2, "Unable to open %s", filename); | 1121 | rb->splashf(HZ*2, "Unable to open %s", filename); |
1122 | return false; | 1122 | return false; |
1123 | } | 1123 | } |
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index cf4e6475b0..1c7aefb1c3 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c | |||
@@ -1272,7 +1272,7 @@ int open_save_file( int flags ) | |||
1272 | { | 1272 | { |
1273 | char buf[MAX_PATH]; | 1273 | char buf[MAX_PATH]; |
1274 | get_save_filename( buf ); | 1274 | get_save_filename( buf ); |
1275 | return rb->open( buf, flags ); | 1275 | return rb->open( buf, flags, 0666); |
1276 | } | 1276 | } |
1277 | 1277 | ||
1278 | void delete_save_file( void ) | 1278 | void delete_save_file( void ) |
diff --git a/apps/plugins/sort.c b/apps/plugins/sort.c index 2ae788ebbd..05c45cce1e 100644 --- a/apps/plugins/sort.c +++ b/apps/plugins/sort.c | |||
@@ -147,7 +147,7 @@ static int write_file(void) | |||
147 | if (bomsize) | 147 | if (bomsize) |
148 | fd = rb->open_utf8(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC); | 148 | fd = rb->open_utf8(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC); |
149 | else | 149 | else |
150 | fd = rb->open(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC); | 150 | fd = rb->open(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
151 | 151 | ||
152 | if(fd < 0) | 152 | if(fd < 0) |
153 | return 10 * fd - 1; | 153 | return 10 * fd - 1; |
diff --git a/apps/plugins/splitedit.c b/apps/plugins/splitedit.c index a07769c390..3e5161b67f 100644 --- a/apps/plugins/splitedit.c +++ b/apps/plugins/splitedit.c | |||
@@ -687,7 +687,7 @@ static int save( | |||
687 | /* write the file 1 */ | 687 | /* write the file 1 */ |
688 | if (file_name1 != NULL) | 688 | if (file_name1 != NULL) |
689 | { | 689 | { |
690 | file1 = rb->open (file_name1, O_WRONLY | O_CREAT); | 690 | file1 = rb->open (file_name1, O_WRONLY | O_CREAT, 0666); |
691 | if (file1 >= 0) | 691 | if (file1 >= 0) |
692 | { | 692 | { |
693 | int rc = copy_file(file1, src_file, end, y*2 + 1, y -1); | 693 | int rc = copy_file(file1, src_file, end, y*2 + 1, y -1); |
@@ -727,7 +727,7 @@ static int save( | |||
727 | if (file_name2 != NULL) | 727 | if (file_name2 != NULL) |
728 | { | 728 | { |
729 | /* write file 2 */ | 729 | /* write file 2 */ |
730 | file2 = rb->open (file_name2, O_WRONLY | O_CREAT); | 730 | file2 = rb->open (file_name2, O_WRONLY | O_CREAT, 0666); |
731 | if (file2 >= 0) | 731 | if (file2 >= 0) |
732 | { | 732 | { |
733 | end = mp3->filesize - end; | 733 | end = mp3->filesize - end; |
diff --git a/apps/plugins/stopwatch.c b/apps/plugins/stopwatch.c index cb85e360db..b09dcdb030 100644 --- a/apps/plugins/stopwatch.c +++ b/apps/plugins/stopwatch.c | |||
@@ -358,7 +358,7 @@ void save_stopwatch(void) | |||
358 | { | 358 | { |
359 | int fd; | 359 | int fd; |
360 | 360 | ||
361 | fd = rb->open(STOPWATCH_FILE, O_CREAT|O_WRONLY|O_TRUNC); | 361 | fd = rb->open(STOPWATCH_FILE, O_CREAT|O_WRONLY|O_TRUNC, 0666); |
362 | 362 | ||
363 | if (fd < 0) | 363 | if (fd < 0) |
364 | { | 364 | { |
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c index 9e7e969eee..4a7fbd93a8 100644 --- a/apps/plugins/sudoku/sudoku.c +++ b/apps/plugins/sudoku/sudoku.c | |||
@@ -808,7 +808,7 @@ bool save_sudoku(struct sudoku_state_t* state) | |||
808 | return false; | 808 | return false; |
809 | } | 809 | } |
810 | 810 | ||
811 | fd=rb->open(state->filename, O_WRONLY|O_CREAT); | 811 | fd=rb->open(state->filename, O_WRONLY|O_CREAT, 0666); |
812 | if (fd >= 0) { | 812 | if (fd >= 0) { |
813 | for (r=0;r<9;r++) { | 813 | for (r=0;r<9;r++) { |
814 | i=0; | 814 | i=0; |
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index d26e98803e..d5d08fb162 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c | |||
@@ -626,7 +626,7 @@ int save_game(void) { | |||
626 | return -1; | 626 | return -1; |
627 | } | 627 | } |
628 | 628 | ||
629 | fd = rb->open(savepath, O_WRONLY|O_CREAT); | 629 | fd = rb->open(savepath, O_WRONLY|O_CREAT, 0666); |
630 | DEBUGF("savepath: %s\n", savepath); | 630 | DEBUGF("savepath: %s\n", savepath); |
631 | if(fd < 0) { | 631 | if(fd < 0) { |
632 | DEBUGF("Couldn't create/open file\n"); | 632 | DEBUGF("Couldn't create/open file\n"); |
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c index f3b826e04e..1ecf225529 100644 --- a/apps/plugins/test_codec.c +++ b/apps/plugins/test_codec.c | |||
@@ -59,7 +59,7 @@ static bool log_init(bool use_logfile) | |||
59 | if (use_logfile) { | 59 | if (use_logfile) { |
60 | rb->create_numbered_filename(logfilename, "/", "test_codec_log_", ".txt", | 60 | rb->create_numbered_filename(logfilename, "/", "test_codec_log_", ".txt", |
61 | 2 IF_CNFN_NUM_(, NULL)); | 61 | 2 IF_CNFN_NUM_(, NULL)); |
62 | log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC); | 62 | log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
63 | return log_fd >= 0; | 63 | return log_fd >= 0; |
64 | } | 64 | } |
65 | 65 | ||
diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c index 396e03c818..c83fb7e1d2 100644 --- a/apps/plugins/test_disk.c +++ b/apps/plugins/test_disk.c | |||
@@ -85,7 +85,7 @@ static bool log_init(void) | |||
85 | 85 | ||
86 | rb->create_numbered_filename(logfilename, "/", "test_disk_log_", ".txt", | 86 | rb->create_numbered_filename(logfilename, "/", "test_disk_log_", ".txt", |
87 | 2 IF_CNFN_NUM_(, NULL)); | 87 | 2 IF_CNFN_NUM_(, NULL)); |
88 | log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC); | 88 | log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
89 | return log_fd >= 0; | 89 | return log_fd >= 0; |
90 | } | 90 | } |
91 | 91 | ||
diff --git a/apps/plugins/test_gfx.c b/apps/plugins/test_gfx.c index 728eb5600e..0a2e02e43f 100644 --- a/apps/plugins/test_gfx.c +++ b/apps/plugins/test_gfx.c | |||
@@ -47,7 +47,7 @@ static int log_init(void) | |||
47 | 47 | ||
48 | rb->create_numbered_filename(logfilename, "/", "test_gfx_log_", ".txt", | 48 | rb->create_numbered_filename(logfilename, "/", "test_gfx_log_", ".txt", |
49 | 2 IF_CNFN_NUM_(, NULL)); | 49 | 2 IF_CNFN_NUM_(, NULL)); |
50 | fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC); | 50 | fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
51 | return fd; | 51 | return fd; |
52 | } | 52 | } |
53 | 53 | ||
diff --git a/apps/plugins/test_grey.c b/apps/plugins/test_grey.c index c2adaf06b5..be28bedfb3 100644 --- a/apps/plugins/test_grey.c +++ b/apps/plugins/test_grey.c | |||
@@ -237,7 +237,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
237 | case GREY_OK: | 237 | case GREY_OK: |
238 | rb->create_numbered_filename(filename, "/", "test_grey_", | 238 | rb->create_numbered_filename(filename, "/", "test_grey_", |
239 | ".txt", 2 IF_CNFN_NUM_(, NULL)); | 239 | ".txt", 2 IF_CNFN_NUM_(, NULL)); |
240 | fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC); | 240 | fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
241 | if (fd >= 0) | 241 | if (fd >= 0) |
242 | { | 242 | { |
243 | for (i = 0; i <= STEPS; i++) | 243 | for (i = 0; i <= STEPS; i++) |
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index 4d5812ba2c..e54935265c 100644 --- a/apps/plugins/text_editor.c +++ b/apps/plugins/text_editor.c | |||
@@ -180,7 +180,7 @@ bool save_changes(int overwrite) | |||
180 | } | 180 | } |
181 | } | 181 | } |
182 | 182 | ||
183 | fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC); | 183 | fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC, 0666); |
184 | if (fd < 0) | 184 | if (fd < 0) |
185 | { | 185 | { |
186 | newfile = true; | 186 | newfile = true; |
diff --git a/apps/plugins/theme_remove.c b/apps/plugins/theme_remove.c index 3bb41929f3..f818ac4afe 100644 --- a/apps/plugins/theme_remove.c +++ b/apps/plugins/theme_remove.c | |||
@@ -686,7 +686,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
686 | case 0: | 686 | case 0: |
687 | if(create_log) | 687 | if(create_log) |
688 | { | 688 | { |
689 | log_fd = rb->open(LOG_FILENAME, O_WRONLY|O_CREAT|O_APPEND); | 689 | log_fd = rb->open(LOG_FILENAME, O_WRONLY|O_CREAT|O_APPEND, 0666); |
690 | if(log_fd >= 0) | 690 | if(log_fd >= 0) |
691 | rb->fdprintf(log_fd, "---- %s ----\n", title); | 691 | rb->fdprintf(log_fd, "---- %s ----\n", title); |
692 | else | 692 | else |
diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index ed84d26f28..ffed414f68 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c | |||
@@ -2138,7 +2138,7 @@ static bool viewer_load_global_settings(void) | |||
2138 | 2138 | ||
2139 | static bool viewer_save_global_settings(void) | 2139 | static bool viewer_save_global_settings(void) |
2140 | { | 2140 | { |
2141 | int sfd = rb->open(GLOBAL_SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC); | 2141 | int sfd = rb->open(GLOBAL_SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
2142 | unsigned char buf[GLOBAL_SETTINGS_H_SIZE]; | 2142 | unsigned char buf[GLOBAL_SETTINGS_H_SIZE]; |
2143 | 2143 | ||
2144 | if (sfd < 0) | 2144 | if (sfd < 0) |
@@ -2219,7 +2219,7 @@ static bool viewer_convert_settings_file(void) | |||
2219 | if ((sfd = rb->open(SETTINGS_FILE, O_RDONLY)) < 0) | 2219 | if ((sfd = rb->open(SETTINGS_FILE, O_RDONLY)) < 0) |
2220 | return false; | 2220 | return false; |
2221 | 2221 | ||
2222 | if ((tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC)) < 0) | 2222 | if ((tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
2223 | { | 2223 | { |
2224 | rb->close(sfd); | 2224 | rb->close(sfd); |
2225 | return false; | 2225 | return false; |
@@ -2441,7 +2441,7 @@ static bool viewer_save_settings(void) | |||
2441 | bookmarks[bookmark_count-1].flag = BOOKMARK_LAST; | 2441 | bookmarks[bookmark_count-1].flag = BOOKMARK_LAST; |
2442 | } | 2442 | } |
2443 | 2443 | ||
2444 | tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC); | 2444 | tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
2445 | if (tfd < 0) | 2445 | if (tfd < 0) |
2446 | return false; | 2446 | return false; |
2447 | 2447 | ||
diff --git a/apps/plugins/wavrecord.c b/apps/plugins/wavrecord.c index 732a7b7645..a8aab92113 100644 --- a/apps/plugins/wavrecord.c +++ b/apps/plugins/wavrecord.c | |||
@@ -3492,7 +3492,7 @@ static int record_file(char *filename) | |||
3492 | {8, 32000}, {9, 44100}, {10, 48000} | 3492 | {8, 32000}, {9, 44100}, {10, 48000} |
3493 | }; | 3493 | }; |
3494 | 3494 | ||
3495 | fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC); | 3495 | fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666); |
3496 | if (fd < 0) | 3496 | if (fd < 0) |
3497 | { | 3497 | { |
3498 | rb->splash(2*HZ, "Couldn't create WAV file"); | 3498 | rb->splash(2*HZ, "Couldn't create WAV file"); |
diff --git a/apps/plugins/zxbox/spsound.c b/apps/plugins/zxbox/spsound.c index aae4ad9c8d..6a550e2033 100644 --- a/apps/plugins/zxbox/spsound.c +++ b/apps/plugins/zxbox/spsound.c | |||
@@ -223,12 +223,12 @@ void write_buf(void){ | |||
223 | 223 | ||
224 | #if 0 | 224 | #if 0 |
225 | /* can use to save and later analyze what we produce */ | 225 | /* can use to save and later analyze what we produce */ |
226 | i = rb->open ( "/sound.raw" , O_WRONLY | O_APPEND | O_CREAT ); | 226 | i = rb->open ( "/sound.raw" , O_WRONLY | O_APPEND | O_CREAT, 0666); |
227 | rb->write ( i , sp_sound_buf , TMNUM ); | 227 | rb->write ( i , sp_sound_buf , TMNUM ); |
228 | rb->close (i); | 228 | rb->close (i); |
229 | 229 | ||
230 | 230 | ||
231 | i = rb->open ( "/sound2.raw" , O_WRONLY | O_APPEND |O_CREAT); | 231 | i = rb->open ( "/sound2.raw" , O_WRONLY | O_APPEND |O_CREAT, 0666); |
232 | rb->write ( i , (unsigned char *)my_buf , TMNUM*4*3 ); | 232 | rb->write ( i , (unsigned char *)my_buf , TMNUM*4*3 ); |
233 | rb->close (i); | 233 | rb->close (i); |
234 | #endif | 234 | #endif |
diff --git a/apps/scrobbler.c b/apps/scrobbler.c index d7eebeee72..5ab13f3d15 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c | |||
@@ -86,7 +86,7 @@ static void write_cache(void) | |||
86 | Check at each write since file may be deleted at any time */ | 86 | Check at each write since file may be deleted at any time */ |
87 | if(!file_exists(SCROBBLER_FILE)) | 87 | if(!file_exists(SCROBBLER_FILE)) |
88 | { | 88 | { |
89 | fd = open(SCROBBLER_FILE, O_RDWR | O_CREAT); | 89 | fd = open(SCROBBLER_FILE, O_RDWR | O_CREAT, 0666); |
90 | if(fd >= 0) | 90 | if(fd >= 0) |
91 | { | 91 | { |
92 | fdprintf(fd, "#AUDIOSCROBBLER/" SCROBBLER_VERSION "\n" | 92 | fdprintf(fd, "#AUDIOSCROBBLER/" SCROBBLER_VERSION "\n" |
diff --git a/apps/settings.c b/apps/settings.c index 0c5560a522..690243b537 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -193,7 +193,7 @@ static bool write_nvram_data(char* buf, int max_len) | |||
193 | max_len-NVRAM_DATA_START-1,0xffffffff); | 193 | max_len-NVRAM_DATA_START-1,0xffffffff); |
194 | memcpy(&buf[4],&crc32,4); | 194 | memcpy(&buf[4],&crc32,4); |
195 | #ifndef HAVE_RTC_RAM | 195 | #ifndef HAVE_RTC_RAM |
196 | fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY); | 196 | fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666); |
197 | if (fd >= 0) | 197 | if (fd >= 0) |
198 | { | 198 | { |
199 | int len = write(fd,buf,max_len); | 199 | int len = write(fd,buf,max_len); |
@@ -532,7 +532,7 @@ static bool settings_write_config(const char* filename, int options) | |||
532 | int i; | 532 | int i; |
533 | int fd; | 533 | int fd; |
534 | char value[MAX_PATH]; | 534 | char value[MAX_PATH]; |
535 | fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); | 535 | fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY, 0666); |
536 | if (fd < 0) | 536 | if (fd < 0) |
537 | return false; | 537 | return false; |
538 | fdprintf(fd, "# .cfg file created by rockbox %s - " | 538 | fdprintf(fd, "# .cfg file created by rockbox %s - " |
diff --git a/apps/tagcache.c b/apps/tagcache.c index 1efb7a8625..ab76fbadfe 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -1705,7 +1705,7 @@ static void __attribute__ ((noinline)) add_tagcache(char *path, | |||
1705 | #ifdef SIMULATOR | 1705 | #ifdef SIMULATOR |
1706 | /* Crude logging for the sim - to aid in debugging */ | 1706 | /* Crude logging for the sim - to aid in debugging */ |
1707 | int logfd = open(ROCKBOX_DIR "/database.log", | 1707 | int logfd = open(ROCKBOX_DIR "/database.log", |
1708 | O_WRONLY | O_APPEND | O_CREAT); | 1708 | O_WRONLY | O_APPEND | O_CREAT, 0666); |
1709 | if (logfd >= 0) { | 1709 | if (logfd >= 0) { |
1710 | write(logfd, path, strlen(path)); | 1710 | write(logfd, path, strlen(path)); |
1711 | write(logfd, "\n", 1); | 1711 | write(logfd, "\n", 1); |
@@ -2494,7 +2494,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2494 | * anything whether the index type is sorted or not. | 2494 | * anything whether the index type is sorted or not. |
2495 | */ | 2495 | */ |
2496 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); | 2496 | snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); |
2497 | fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC); | 2497 | fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
2498 | if (fd < 0) | 2498 | if (fd < 0) |
2499 | { | 2499 | { |
2500 | logf("%s open fail", buf); | 2500 | logf("%s open fail", buf); |
@@ -2521,7 +2521,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2521 | if (masterfd < 0) | 2521 | if (masterfd < 0) |
2522 | { | 2522 | { |
2523 | logf("Creating new DB"); | 2523 | logf("Creating new DB"); |
2524 | masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC); | 2524 | masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
2525 | 2525 | ||
2526 | if (masterfd < 0) | 2526 | if (masterfd < 0) |
2527 | { | 2527 | { |
@@ -3447,7 +3447,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) | |||
3447 | return false; | 3447 | return false; |
3448 | 3448 | ||
3449 | /* Initialize the changelog */ | 3449 | /* Initialize the changelog */ |
3450 | clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC); | 3450 | clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
3451 | if (clfd < 0) | 3451 | if (clfd < 0) |
3452 | { | 3452 | { |
3453 | logf("failure to open changelog"); | 3453 | logf("failure to open changelog"); |
@@ -3820,7 +3820,7 @@ static bool tagcache_dumpsave(void) | |||
3820 | if (!tc_stat.ramcache) | 3820 | if (!tc_stat.ramcache) |
3821 | return false; | 3821 | return false; |
3822 | 3822 | ||
3823 | fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC); | 3823 | fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
3824 | if (fd < 0) | 3824 | if (fd < 0) |
3825 | { | 3825 | { |
3826 | logf("failed to create a statedump"); | 3826 | logf("failed to create a statedump"); |
@@ -4252,7 +4252,7 @@ void tagcache_build(const char *path) | |||
4252 | return ; | 4252 | return ; |
4253 | } | 4253 | } |
4254 | 4254 | ||
4255 | cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC); | 4255 | cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC, 0666); |
4256 | if (cachefd < 0) | 4256 | if (cachefd < 0) |
4257 | { | 4257 | { |
4258 | logf("master file open failed: %s", TAGCACHE_FILE_TEMP); | 4258 | logf("master file open failed: %s", TAGCACHE_FILE_TEMP); |
diff --git a/bootloader/tpj1022.c b/bootloader/tpj1022.c index 0f14d2355c..db709d1b58 100644 --- a/bootloader/tpj1022.c +++ b/bootloader/tpj1022.c | |||
@@ -63,20 +63,20 @@ void* main(void) | |||
63 | 63 | ||
64 | #if 0 | 64 | #if 0 |
65 | /* Dump the flash */ | 65 | /* Dump the flash */ |
66 | fd=open("/flash.bin",O_CREAT|O_RDWR); | 66 | fd=open("/flash.bin",O_CREAT|O_RDWR, 0666); |
67 | write(fd,(char*)0,1024*1024); | 67 | write(fd,(char*)0,1024*1024); |
68 | close(fd); | 68 | close(fd); |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | #if 1 | 71 | #if 1 |
72 | /* Dump what may be the framebuffer */ | 72 | /* Dump what may be the framebuffer */ |
73 | fd=open("/framebuffer.bin",O_CREAT|O_RDWR|O_TRUNC); | 73 | fd=open("/framebuffer.bin",O_CREAT|O_RDWR|O_TRUNC, 0666); |
74 | write(fd,framebuffer,220*176*4); | 74 | write(fd,framebuffer,220*176*4); |
75 | close(fd); | 75 | close(fd); |
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | 78 | ||
79 | fd=open("/gpio.txt",O_CREAT|O_RDWR|O_TRUNC); | 79 | fd=open("/gpio.txt",O_CREAT|O_RDWR|O_TRUNC, 0666); |
80 | unsigned int gpio_a = GPIOA_INPUT_VAL; | 80 | unsigned int gpio_a = GPIOA_INPUT_VAL; |
81 | unsigned int gpio_b = GPIOB_INPUT_VAL; | 81 | unsigned int gpio_b = GPIOB_INPUT_VAL; |
82 | unsigned int gpio_c = GPIOC_INPUT_VAL; | 82 | unsigned int gpio_c = GPIOC_INPUT_VAL; |
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 495366f5d8..225ed1aff1 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c | |||
@@ -557,7 +557,7 @@ int dircache_save(void) | |||
557 | return -1; | 557 | return -1; |
558 | 558 | ||
559 | logf("Saving directory cache"); | 559 | logf("Saving directory cache"); |
560 | fd = open(DIRCACHE_FILE, O_WRONLY | O_CREAT | O_TRUNC); | 560 | fd = open(DIRCACHE_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
561 | 561 | ||
562 | maindata.magic = DIRCACHE_MAGIC; | 562 | maindata.magic = DIRCACHE_MAGIC; |
563 | maindata.size = dircache_size; | 563 | maindata.size = dircache_size; |
diff --git a/firmware/common/file.c b/firmware/common/file.c index 05612cd75e..438a7106ca 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -57,7 +57,7 @@ static int flush_cache(int fd); | |||
57 | 57 | ||
58 | int file_creat(const char *pathname) | 58 | int file_creat(const char *pathname) |
59 | { | 59 | { |
60 | return open(pathname, O_WRONLY|O_CREAT|O_TRUNC); | 60 | return open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
61 | } | 61 | } |
62 | 62 | ||
63 | static int open_internal(const char* pathname, int flags, bool use_cache) | 63 | static int open_internal(const char* pathname, int flags, bool use_cache) |
@@ -228,7 +228,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache) | |||
228 | return fd; | 228 | return fd; |
229 | } | 229 | } |
230 | 230 | ||
231 | int open(const char* pathname, int flags) | 231 | int file_open(const char* pathname, int flags) |
232 | { | 232 | { |
233 | /* By default, use the dircache if available. */ | 233 | /* By default, use the dircache if available. */ |
234 | return open_internal(pathname, flags, true); | 234 | return open_internal(pathname, flags, true); |
diff --git a/firmware/font.c b/firmware/font.c index 6877d7e1ff..f1584713ed 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -607,7 +607,7 @@ void glyph_cache_save(struct font* pf) | |||
607 | if (pf->fd >= 0 && pf == &font_ui) | 607 | if (pf->fd >= 0 && pf == &font_ui) |
608 | { | 608 | { |
609 | #ifdef WPSEDITOR | 609 | #ifdef WPSEDITOR |
610 | cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC); | 610 | cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
611 | #else | 611 | #else |
612 | cache_fd = creat(GLYPH_CACHE_FILE, 0666); | 612 | cache_fd = creat(GLYPH_CACHE_FILE, 0666); |
613 | #endif | 613 | #endif |
diff --git a/firmware/include/file.h b/firmware/include/file.h index b60c744549..ec0ab87759 100644 --- a/firmware/include/file.h +++ b/firmware/include/file.h | |||
@@ -49,7 +49,7 @@ | |||
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #if defined(SIMULATOR) && !defined(PLUGIN) && !defined(CODEC) | 51 | #if defined(SIMULATOR) && !defined(PLUGIN) && !defined(CODEC) |
52 | #define open(x,y) sim_open(x,y) | 52 | #define open(x, ...) sim_open(x, __VA_ARGS__) |
53 | #define creat(x,m) sim_creat(x,m) | 53 | #define creat(x,m) sim_creat(x,m) |
54 | #define remove(x) sim_remove(x) | 54 | #define remove(x) sim_remove(x) |
55 | #define rename(x,y) sim_rename(x,y) | 55 | #define rename(x,y) sim_rename(x,y) |
@@ -61,16 +61,17 @@ | |||
61 | #define write(x,y,z) sim_write(x,y,z) | 61 | #define write(x,y,z) sim_write(x,y,z) |
62 | #define close(x) sim_close(x) | 62 | #define close(x) sim_close(x) |
63 | extern int sim_creat(const char *pathname, mode_t mode); | 63 | extern int sim_creat(const char *pathname, mode_t mode); |
64 | extern int sim_open(const char *pathname, int flags, ...); | ||
64 | #endif | 65 | #endif |
65 | 66 | ||
66 | typedef int (*open_func)(const char* pathname, int flags); | 67 | typedef int (*open_func)(const char* pathname, int flags, ...); |
67 | typedef ssize_t (*read_func)(int fd, void *buf, size_t count); | 68 | typedef ssize_t (*read_func)(int fd, void *buf, size_t count); |
68 | typedef int (*creat_func)(const char *pathname, mode_t mode); | 69 | typedef int (*creat_func)(const char *pathname, mode_t mode); |
69 | typedef ssize_t (*write_func)(int fd, const void *buf, size_t count); | 70 | typedef ssize_t (*write_func)(int fd, const void *buf, size_t count); |
70 | typedef void (*qsort_func)(void *base, size_t nmemb, size_t size, | 71 | typedef void (*qsort_func)(void *base, size_t nmemb, size_t size, |
71 | int(*_compar)(const void *, const void *)); | 72 | int(*_compar)(const void *, const void *)); |
72 | 73 | ||
73 | extern int open(const char* pathname, int flags); | 74 | extern int file_open(const char* pathname, int flags); |
74 | extern int close(int fd); | 75 | extern int close(int fd); |
75 | extern int fsync(int fd); | 76 | extern int fsync(int fd); |
76 | extern ssize_t read(int fd, void *buf, size_t count); | 77 | extern ssize_t read(int fd, void *buf, size_t count); |
@@ -83,6 +84,9 @@ static inline int creat(const char *pathname, mode_t mode) | |||
83 | (void)mode; | 84 | (void)mode; |
84 | return file_creat(pathname); | 85 | return file_creat(pathname); |
85 | } | 86 | } |
87 | #if !defined(CODEC) && !defined(PLUGIN) | ||
88 | #define open(x, y, ...) file_open(x,y) | ||
89 | #endif | ||
86 | #endif | 90 | #endif |
87 | extern ssize_t write(int fd, const void *buf, size_t count); | 91 | extern ssize_t write(int fd, const void *buf, size_t count); |
88 | extern int remove(const char* pathname); | 92 | extern int remove(const char* pathname); |
diff --git a/firmware/profile.c b/firmware/profile.c index 6700eca404..30a1e9fccc 100644 --- a/firmware/profile.c +++ b/firmware/profile.c | |||
@@ -189,7 +189,7 @@ void profstop() { | |||
189 | unsigned short current_index; | 189 | unsigned short current_index; |
190 | timer_unregister(); | 190 | timer_unregister(); |
191 | profiling = PROF_OFF; | 191 | profiling = PROF_OFF; |
192 | fd = open("/profile.out", O_WRONLY|O_CREAT|O_TRUNC); | 192 | fd = open("/profile.out", O_WRONLY|O_CREAT|O_TRUNC, 0666); |
193 | if (profiling_exit == PROF_ERROR) { | 193 | if (profiling_exit == PROF_ERROR) { |
194 | fdprintf(fd,"Profiling exited with an error.\n"); | 194 | fdprintf(fd,"Profiling exited with an error.\n"); |
195 | fdprintf(fd,"Overflow or timer stolen most likely.\n"); | 195 | fdprintf(fd,"Overflow or timer stolen most likely.\n"); |
diff --git a/firmware/target/sh/archos/recorder/powermgmt-recorder.c b/firmware/target/sh/archos/recorder/powermgmt-recorder.c index 7b1842016c..70373a30ec 100644 --- a/firmware/target/sh/archos/recorder/powermgmt-recorder.c +++ b/firmware/target/sh/archos/recorder/powermgmt-recorder.c | |||
@@ -125,7 +125,7 @@ static void debug_file_log(void) | |||
125 | debug_file_close(); | 125 | debug_file_close(); |
126 | } | 126 | } |
127 | else if (fd < 0) { | 127 | else if (fd < 0) { |
128 | fd = open(DEBUG_FILE_NAME, O_WRONLY | O_APPEND | O_CREAT); | 128 | fd = open(DEBUG_FILE_NAME, O_WRONLY | O_APPEND | O_CREAT, 0666); |
129 | 129 | ||
130 | if (fd >= 0) { | 130 | if (fd >= 0) { |
131 | snprintf(debug_message, DEBUG_MESSAGE_LEN, | 131 | snprintf(debug_message, DEBUG_MESSAGE_LEN, |
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c index e190d81045..1cb53deb6e 100644 --- a/firmware/test/fat/main.c +++ b/firmware/test/fat/main.c | |||
@@ -356,7 +356,7 @@ int dbg_test(char* name) | |||
356 | for (j=0; j<5; j++) { | 356 | for (j=0; j<5; j++) { |
357 | int num = 40960; | 357 | int num = 40960; |
358 | 358 | ||
359 | fd = open(name,O_WRONLY|O_CREAT|O_APPEND); | 359 | fd = open(name,O_WRONLY|O_CREAT|O_APPEND, 0666); |
360 | if (fd<0) { | 360 | if (fd<0) { |
361 | DEBUGF("Failed opening file\n"); | 361 | DEBUGF("Failed opening file\n"); |
362 | return -1; | 362 | return -1; |
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index f794d5fbc3..937c710e06 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c | |||
@@ -106,7 +106,9 @@ extern int _wrmdir(const wchar_t*); | |||
106 | #define READDIR(a) (_wreaddir)(a) | 106 | #define READDIR(a) (_wreaddir)(a) |
107 | #define CLOSEDIR(a) (_wclosedir)(a) | 107 | #define CLOSEDIR(a) (_wclosedir)(a) |
108 | #define STAT(a,b) (_wstat)(UTF8_TO_OS(a),b) | 108 | #define STAT(a,b) (_wstat)(UTF8_TO_OS(a),b) |
109 | #define OPEN(a,b,c) (_wopen)(UTF8_TO_OS(a),b,c) | 109 | /* empty variable parameter list doesn't work for variadic macros, |
110 | * so pretend the second parameter is variable too */ | ||
111 | #define OPEN(a,...) (_wopen)(UTF8_TO_OS(a), __VA_ARGS__) | ||
110 | #define CLOSE(a) (close)(a) | 112 | #define CLOSE(a) (close)(a) |
111 | #define REMOVE(a) (_wremove)(UTF8_TO_OS(a)) | 113 | #define REMOVE(a) (_wremove)(UTF8_TO_OS(a)) |
112 | #define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,convbuf2)) | 114 | #define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,convbuf2)) |
@@ -124,7 +126,9 @@ extern int _wrmdir(const wchar_t*); | |||
124 | #define READDIR(a) (readdir)(a) | 126 | #define READDIR(a) (readdir)(a) |
125 | #define CLOSEDIR(a) (closedir)(a) | 127 | #define CLOSEDIR(a) (closedir)(a) |
126 | #define STAT(a,b) (stat)(a,b) | 128 | #define STAT(a,b) (stat)(a,b) |
127 | #define OPEN(a,b,c) (open)(a,b,c) | 129 | /* empty variable parameter list doesn't work for variadic macros, |
130 | * so pretend the second parameter is variable too */ | ||
131 | #define OPEN(a, ...) (open)(a, __VA_ARGS__) | ||
128 | #define CLOSE(x) (close)(x) | 132 | #define CLOSE(x) (close)(x) |
129 | #define REMOVE(a) (remove)(a) | 133 | #define REMOVE(a) (remove)(a) |
130 | #define RENAME(a,b) (rename)(a,b) | 134 | #define RENAME(a,b) (rename)(a,b) |
@@ -329,15 +333,23 @@ void sim_closedir(MYDIR *dir) | |||
329 | free(dir); | 333 | free(dir); |
330 | } | 334 | } |
331 | 335 | ||
332 | int sim_open(const char *name, int o) | 336 | int sim_open(const char *name, int o, ...) |
333 | { | 337 | { |
334 | int opts = rockbox2sim(o); | 338 | int opts = rockbox2sim(o); |
335 | int ret; | 339 | int ret; |
336 | |||
337 | if (num_openfiles >= MAX_OPEN_FILES) | 340 | if (num_openfiles >= MAX_OPEN_FILES) |
338 | return -2; | 341 | return -2; |
339 | 342 | ||
340 | ret = OPEN(get_sim_pathname(name), opts, 0666); | 343 | if (o & O_CREAT) |
344 | { | ||
345 | va_list ap; | ||
346 | va_start(ap, o); | ||
347 | ret = OPEN(get_sim_pathname(name), opts, va_arg(ap, mode_t)); | ||
348 | va_end(ap); | ||
349 | } | ||
350 | else | ||
351 | ret = OPEN(get_sim_pathname(name), opts); | ||
352 | |||
341 | if (ret >= 0) | 353 | if (ret >= 0) |
342 | num_openfiles++; | 354 | num_openfiles++; |
343 | return ret; | 355 | return ret; |