summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-05-06 17:35:13 +0000
committerThomas Martitz <kugel@rockbox.org>2010-05-06 17:35:13 +0000
commit0a1d7c28b7e9da555d26d489cde2da26e2cc9ca0 (patch)
treea21521e6e4b8fe0131c4d9e8bae6d8cc78125fe9
parentc61e89c0eda126c2c1a4a3983520c35fe30db156 (diff)
downloadrockbox-0a1d7c28b7e9da555d26d489cde2da26e2cc9ca0.tar.gz
rockbox-0a1d7c28b7e9da555d26d489cde2da26e2cc9ca0.tar.bz2
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
-rw-r--r--apps/bookmark.c4
-rw-r--r--apps/codecs.c20
-rw-r--r--apps/codecs.h2
-rw-r--r--apps/codecs/aiff_enc.c2
-rw-r--r--apps/codecs/libcook/main.c2
-rw-r--r--apps/codecs/libffmpegFLAC/main.c2
-rw-r--r--apps/codecs/libspc/spc_profiler.c2
-rw-r--r--apps/codecs/mp3_enc.c2
-rw-r--r--apps/codecs/nsf.c2
-rw-r--r--apps/codecs/wav_enc.c2
-rw-r--r--apps/codecs/wavpack_enc.c2
-rw-r--r--apps/logfdisp.c2
-rw-r--r--apps/mpeg.c2
-rw-r--r--apps/playlist.c6
-rw-r--r--apps/playlist_catalog.c2
-rw-r--r--apps/plugin.c34
-rw-r--r--apps/plugin.h2
-rw-r--r--apps/plugins/battery_bench.c6
-rw-r--r--apps/plugins/blackjack.c2
-rw-r--r--apps/plugins/brickmania.c2
-rw-r--r--apps/plugins/bubbles.c4
-rw-r--r--apps/plugins/calendar.c2
-rw-r--r--apps/plugins/chessbox/chessbox.c2
-rw-r--r--apps/plugins/chessbox/chessbox_pgn.c4
-rw-r--r--apps/plugins/crypt_firmware.c4
-rw-r--r--apps/plugins/doom/rockdoom.c13
-rw-r--r--apps/plugins/doom/rockmacros.h6
-rw-r--r--apps/plugins/frotz/fastmem.c4
-rw-r--r--apps/plugins/frotz/files.c4
-rw-r--r--apps/plugins/jewels.c2
-rw-r--r--apps/plugins/keybox.c2
-rw-r--r--apps/plugins/lib/highscore.c2
-rw-r--r--apps/plugins/lua/liolib.c2
-rw-r--r--apps/plugins/md5sum.c2
-rw-r--r--apps/plugins/mp3_encoder.c2
-rw-r--r--apps/plugins/pdbox/PDa/intern/sfwrite~.c4
-rw-r--r--apps/plugins/pdbox/PDa/src/g_array.c4
-rw-r--r--apps/plugins/random_folder_advance_config.c2
-rw-r--r--apps/plugins/rockblox.c2
-rw-r--r--apps/plugins/rockboy/cpu.c2
-rw-r--r--apps/plugins/rockboy/dynarec.c4
-rw-r--r--apps/plugins/rockboy/loader.c4
-rw-r--r--apps/plugins/rockboy/menu.c2
-rw-r--r--apps/plugins/rockboy/rockboy.c2
-rw-r--r--apps/plugins/rockboy/rockmacros.h4
-rw-r--r--apps/plugins/search.c2
-rw-r--r--apps/plugins/searchengine/searchengine.c2
-rw-r--r--apps/plugins/settings_dumper.c2
-rw-r--r--apps/plugins/sokoban.c2
-rw-r--r--apps/plugins/solitaire.c2
-rw-r--r--apps/plugins/sort.c2
-rw-r--r--apps/plugins/splitedit.c4
-rw-r--r--apps/plugins/stopwatch.c2
-rw-r--r--apps/plugins/sudoku/sudoku.c2
-rw-r--r--apps/plugins/superdom.c2
-rw-r--r--apps/plugins/test_codec.c2
-rw-r--r--apps/plugins/test_disk.c2
-rw-r--r--apps/plugins/test_gfx.c2
-rw-r--r--apps/plugins/test_grey.c2
-rw-r--r--apps/plugins/text_editor.c2
-rw-r--r--apps/plugins/theme_remove.c2
-rw-r--r--apps/plugins/viewer.c6
-rw-r--r--apps/plugins/wavrecord.c2
-rw-r--r--apps/plugins/zxbox/spsound.c4
-rw-r--r--apps/scrobbler.c2
-rw-r--r--apps/settings.c4
-rw-r--r--apps/tagcache.c12
-rw-r--r--bootloader/tpj1022.c6
-rw-r--r--firmware/common/dircache.c2
-rw-r--r--firmware/common/file.c4
-rw-r--r--firmware/font.c2
-rw-r--r--firmware/include/file.h10
-rw-r--r--firmware/profile.c2
-rw-r--r--firmware/target/sh/archos/recorder/powermgmt-recorder.c2
-rw-r--r--firmware/test/fat/main.c2
-rw-r--r--uisimulator/common/io.c22
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,
snprintf(global_temp_buffer, sizeof(global_temp_buffer),
"%s.tmp", bookmark_file_name);
temp_bookmark_file = open(global_temp_buffer,
- O_WRONLY | O_CREAT | O_TRUNC);
+ O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (temp_bookmark_file < 0)
return false; /* can't open the temp file */
@@ -814,7 +814,7 @@ static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id)
snprintf(global_temp_buffer, sizeof(global_temp_buffer),
"%s.tmp", bookmark_file_name);
temp_bookmark_file = open(global_temp_buffer,
- O_WRONLY | O_CREAT | O_TRUNC);
+ O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (temp_bookmark_file < 0)
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;
extern void* plugin_get_audio_buffer(size_t *buffer_size);
+#undef open
+static int open(const char* pathname, int flags, ...)
+{
+#ifdef SIMULATOR
+ int fd;
+ if (flags & O_CREAT)
+ {
+ va_list ap;
+ va_start(ap, flags);
+ fd = sim_open(pathname, flags, va_arg(ap, mode_t));
+ va_end(ap);
+ }
+ else
+ fd = sim_open(pathname, flags);
+
+ return fd;
+#else
+ return file_open(pathname, flags);
+#endif
+}
struct codec_api ci = {
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 {
size_t (*enc_unget_pcm_data)(size_t size);
/* file */
- int (*open)(const char* pathname, int flags);
+ int (*open)(const char* pathname, int flags, ...);
int (*close)(int fd);
ssize_t (*read)(int fd, void* buf, size_t count);
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)
if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0')
return false;
- data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC);
+ data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (data->rec_file < 0)
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[])
/* output raw audio frames that are sent to the decoder into separate files */
#ifdef DUMP_RAW_FRAMES
snprintf(filename,sizeof(filename),"dump%d.raw",++x);
- fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND);
+ fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND, 0666);
write(fd_out,pkt.frames[i],sps);
close(fd_out);
#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]={
int open_wav(char* filename) {
int fd;
- fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR);
+ fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd >= 0) {
if (write(fd,wav_header,sizeof(wav_header)) < sizeof(wav_header)) {
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)
void print_timers(char * path)
{
- int logfd = ci->open("/spclog.txt",O_WRONLY|O_CREAT|O_APPEND);
+ int logfd = ci->open("/spclog.txt",O_WRONLY|O_CREAT|O_APPEND, 0666);
ci->fdprintf(logfd,"%s:\t",path);
ci->fdprintf(logfd,"%10ld total\t",READ_TIMER(total));
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)
if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0')
return false;
- data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC);
+ data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (data->rec_file < 0)
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) {
int logfd=-1;
void print_timers(char * path, int track) {
- logfd = ci->open("/nsflog.txt",O_WRONLY|O_CREAT|O_APPEND);
+ logfd = ci->open("/nsflog.txt",O_WRONLY|O_CREAT|O_APPEND, 0666);
ci->fdprintf(logfd,"%s[%d]:\t",path,track);
ci->fdprintf(logfd,"%10ld total\t",READ_TIMER(total));
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)
if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0')
return false;
- data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC);
+ data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (data->rec_file < 0)
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)
if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0')
return false;
- data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC);
+ data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (data->rec_file < 0)
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)
/* nothing is logged just yet */
return false;
- fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC);
+ fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC, 0666);
if(-1 != fd) {
int i;
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)
if (mpeg_file < 0) /* delayed file open */
{
- mpeg_file = open(delayed_filename, O_WRONLY|O_CREAT);
+ mpeg_file = open(delayed_filename, O_WRONLY|O_CREAT, 0666);
if (mpeg_file < 0)
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,
static void create_control(struct playlist_info* playlist)
{
playlist->control_fd = open(playlist->control_filename,
- O_CREAT|O_RDWR|O_TRUNC);
+ O_CREAT|O_RDWR|O_TRUNC, 0666);
if (playlist->control_fd < 0)
{
if (check_rockboxdir())
@@ -414,7 +414,7 @@ static int recreate_control(struct playlist_info* playlist)
return -1;
playlist->control_fd = open(playlist->control_filename,
- O_CREAT|O_RDWR|O_TRUNC);
+ O_CREAT|O_RDWR|O_TRUNC, 0666);
if (playlist->control_fd < 0)
return -1;
@@ -3375,7 +3375,7 @@ int playlist_save(struct playlist_info* playlist, char *filename)
else
{
/* some applications require a BOM to read the file properly */
- fd = open(path, O_CREAT|O_WRONLY|O_TRUNC);
+ fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, 0666);
}
if (fd < 0)
{
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,
if (new_playlist)
fd = open_utf8(playlist, O_CREAT|O_WRONLY|O_TRUNC);
else
- fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND);
+ fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND, 0666);
if(fd < 0)
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];
char *plugin_get_current_filename(void);
-#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
/* Some wrappers used to monitor open and close and detect leaks*/
-static int open_wrapper(const char* pathname, int flags);
+static int open_wrapper(const char* pathname, int flags, ...);
+#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
static int close_wrapper(int fd);
static int creat_wrapper(const char *pathname, mode_t mode);
#endif
@@ -299,13 +299,12 @@ static const struct plugin_api rockbox_api = {
/* file */
open_utf8,
-#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
(open_func)open_wrapper,
+#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
close_wrapper,
#else
- (open_func)PREFIX(open),
PREFIX(close),
- #endif
+#endif
(read_func)PREFIX(read),
PREFIX(lseek),
#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
@@ -979,17 +978,34 @@ char *plugin_get_current_filename(void)
return current_plugin;
}
-#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
-static int open_wrapper(const char* pathname, int flags)
+static int open_wrapper(const char* pathname, int flags, ...)
{
- int fd = PREFIX(open)(pathname,flags);
+/* we don't have an 'open' function. it's a define. and we need
+ * the real file_open, hence PREFIX() doesn't work here */
+ int fd;
+#ifdef SIMULATOR
+ if (flags & O_CREAT)
+ {
+ va_list ap;
+ va_start(ap, flags);
+ int fd;
+ fd = sim_open(pathname, flags, va_arg(ap, mode_t));
+ va_end(ap);
+ }
+ else
+ fd = sim_open(pathname, flags);
+#else
+ fd = file_open(pathname,flags);
+#endif
+#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
if(fd >= 0)
open_files |= 1<<fd;
-
+#endif
return fd;
}
+#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
static int close_wrapper(int fd)
{
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 {
/* file */
int (*open_utf8)(const char* pathname, int flags);
- int (*open)(const char* pathname, int flags);
+ int (*open)(const char* pathname, int flags, ...);
int (*close)(int fd);
ssize_t (*read)(int fd, void* buf, size_t count);
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)
if (in_usb_mode || (buf_idx == 0))
return;
- fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND);
+ fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND, 0666);
if (fd < 0)
return;
@@ -446,7 +446,7 @@ void thread(void)
rb->unregister_storage_idle_func(flush_buffer, true);
/* log end of bench and exit reason */
- fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND);
+ fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND, 0666);
if (fd >= 0)
{
rb->fdprintf(fd, "--Battery bench ended, reason: %s--\n", exit_reason);
@@ -525,7 +525,7 @@ int main(void)
fd = rb->open(BATTERY_LOG, O_RDONLY);
if (fd < 0)
{
- fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT);
+ fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT, 0666);
if (fd >= 0)
{
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) {
if(!resume)
return;
/* write out the game state to the save file */
- fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
+ fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666);
if(fd < 0)
return;
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)
int fd;
/* write out the game state to the save file */
- fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
+ fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666);
if(fd < 0) return;
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) {
if (last_highlevel >= highlevel) /* no need to save */
return;
- fd = rb->open(DATA_FILE, O_WRONLY|O_CREAT);
+ fd = rb->open(DATA_FILE, O_WRONLY|O_CREAT, 0666);
if (fd < 0) return;
rb->write(fd, &highlevel, sizeof(highlevel));
@@ -2252,7 +2252,7 @@ static void bubbles_savegame(struct game_context* bb) {
if (!resume) /* nothing to save */
return;
/* write out the game state to the save file */
- fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
+ fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666);
if (fd < 0)
{
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)
{
int fp, fq;
/* use O_RDWR|O_CREAT so that file is created if it doesn't exist. */
- fp = rb->open(MEMO_FILE, O_RDWR|O_CREAT);
+ fp = rb->open(MEMO_FILE, O_RDWR|O_CREAT, 0666);
fq = rb->creat(TEMP_FILE, 0666);
if ( (fq > -1) && (fp > -1) )
{
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 ) {
rb->splash ( 0 , "Saving position" );
- fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
+ fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666);
computer++; rb->write(fd, &(computer), sizeof(computer)); computer--;
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,
rb->read_line(fhandler, line_buffer, sizeof line_buffer);
}
- loghandler = rb->open(LOG_FILE, O_WRONLY | O_CREAT);
+ loghandler = rb->open(LOG_FILE, O_WRONLY | O_CREAT, 0666);
GNUChess_Initialize();
@@ -829,7 +829,7 @@ void pgn_store_game(struct pgn_game_node* game){
ply_count++;
}
- fhandler = rb->open(PGN_FILE, O_WRONLY|O_CREAT|O_APPEND);
+ fhandler = rb->open(PGN_FILE, O_WRONLY|O_CREAT|O_APPEND, 0666);
/* 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)
memcpy(buf + 1, "nn2x", 4);
/* 4 - Write to disk */
- fd = rb->open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC);
+ fd = rb->open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fd < 0) {
rb->splash(HZ*2, "Could not open output file");
@@ -307,7 +307,7 @@ enum plugin_status plugin_start(const void* parameter)
memcpy(buf + 1, "nn2g", 4);
/* 4 - Write to disk */
- fd = rb->open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC);
+ fd = rb->open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fd < 0) {
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)
}
#ifndef SIMULATOR
-int my_open(const char *file, int flags)
+int my_open(const char *file, int flags, ...)
{
if(fpoint==8)
return -1;
#undef open
- filearray[fpoint]=rb->open(file, flags);
-
+ if (flags & O_CREAT)
+ {
+ va_list ap;
+ va_start(ap, flags);
+ filearray[fpoint]=rb->open(file, flags, va_arg(ap, mode_t));
+ va_end(ap);
+ }
+ else
+ filearray[fpoint]=rb->open(file, flags);
if(filearray[fpoint]<0)
return filearray[fpoint];
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 );
#define read_line(a,b,c) rb->read_line((a),(b),(c))
#ifdef SIMULATOR
-#define open(a,b) rb->open((a),(b))
+#define open(a, ...) rb->open((a), __VA_ARGS__)
#define close(a) rb->close((a))
#else
-int my_open(const char *file, int flags);
+int my_open(const char *file, int flags, ...);
int my_close(int id);
-#define open(a,b) my_open((a),(b))
+#define open(a, ...) my_open((a), __VA_ARGS__)
#define close(a) my_close((a))
#endif
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)
/* Open auxilary file */
- if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC)) < 0)
+ if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
goto finished;
/* Write auxilary file */
@@ -859,7 +859,7 @@ void z_save (void)
/* Open game file */
- if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC)) < 0)
+ if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
goto finished;
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)
/* Opening in "at" mode doesn't work for script_erase_input... */
- if ((sfp = rb->open (script_name, O_RDWR|O_CREAT)) != -1) {
+ if ((sfp = rb->open (script_name, O_RDWR|O_CREAT, 0666)) != -1) {
fseek (sfp, 0, SEEK_END);
@@ -290,7 +290,7 @@ void record_open (void)
strcpy (command_name, new_name);
- if ((rfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC)) != -1)
+ if ((rfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) != -1)
ostream_record = TRUE;
else
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)
{
int fd;
/* write out the game state to the save file */
- fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
+ fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666);
if(fd < 0) return;
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)
if (data_changed)
{
- fd = rb->open(KEYBOX_FILE, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = rb->open(KEYBOX_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
return FILE_OPEN_ERROR;
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)
if(!highscore_updated)
return 1;
- fd = rb->open(filename, O_WRONLY|O_CREAT);
+ fd = rb->open(filename, O_WRONLY|O_CREAT, 0666);
if(fd < 0)
return -1;
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) {
}
if((*mode == 'w' || *mode == 'a') && !rb->file_exists(filename))
flags |= O_CREAT;
- *pf = rb->open(filename, flags);
+ *pf = rb->open(filename, flags, 0666);
return (*pf < 0) ? pushresult(L, 0, filename) : 1;
}
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)
done = 0;
action( out, arg );
- out = rb->open( filename, O_WRONLY|O_CREAT|O_TRUNC );
+ out = rb->open( filename, O_WRONLY|O_CREAT|O_TRUNC , 0666);
if( out < 0 ) return PLUGIN_ERROR;
action( out, arg );
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)
{
init_mp3_encoder_engine(true, brate[srat], cfg.samplerate);
get_mp3_filename(wav_filename);
- mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC);
+ mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC, 0666);
frames = 0;
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)
sfwrite_close(x);
-#ifdef ROCKBOX
- if ((x->x_file = open(fname, O_RDWR | O_CREAT)) < 0)
-#else
if ((x->x_file = open(fname,O_RDWR | O_CREAT,0664)) < 0)
-#endif
{
error("can't create %s",fname);
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)
buf, MAXPDSTRING);
sys_bashfilename(buf, buf);
#ifdef ROCKBOX
- if(!(fd = open(buf, O_WRONLY|O_CREAT|O_TRUNC)))
+ if(!(fd = open(buf, O_WRONLY|O_CREAT|O_TRUNC, 0666)))
#else
if (!(fd = fopen(buf, "w")))
#endif
@@ -1388,7 +1388,7 @@ static void garray_write16(t_garray *x, t_symbol *filename, t_symbol *format)
buf2, MAXPDSTRING);
sys_bashfilename(buf2, buf2);
#ifdef ROCKBOX
- if(!(fd = open(buf2, O_WRONLY|O_CREAT|O_TRUNC)))
+ if(!(fd = open(buf2, O_WRONLY|O_CREAT|O_TRUNC, 0666)))
#else
if (!(fd = fopen(buf2, BINWRITEMODE)))
#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)
{
dirs_count = 0;
abort = false;
- fd = rb->open(RFA_FILE,O_CREAT|O_WRONLY);
+ fd = rb->open(RFA_FILE,O_CREAT|O_WRONLY, 0666);
rb->write(fd,&dirs_count,sizeof(int));
if (fd < 0)
{
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)
{
int fd;
- fd = rb->open(RESUME_FILE, O_WRONLY|O_CREAT);
+ fd = rb->open(RESUME_FILE, O_WRONLY|O_CREAT, 0666);
if (fd < 0)
goto fail;
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:
int fd;
blockcount++;
snprintf(meow,499,"/dyna_0x%x_run.rb",PC);
- fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC);
+ fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC, 0666);
if(fd>=0)
{
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)
newblock->block=dynapointer;
#ifdef DYNA_DEBUG
snprintf(meow,499,"/dyna_0x%x_asm.rb",PC);
- fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC);
+ fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC, 0666);
if(fd<0)
{
die("couldn't open dyna debug file");
@@ -1907,7 +1907,7 @@ void dynamic_recompile (struct dynarec_block *newblock)
newblock->length=dynapointer-newblock->block;
IF_COP(rb->cpucache_invalidate());
snprintf(meow,499,"/dyna_0x%x_code.rb",PC);
- fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC);
+ fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC, 0666);
if(fd>=0)
{
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)
/* If we crash before we ever loaded sram, DO NOT SAVE! */
if (!mbc.batt || !ram.loaded || !mbc.ramsize)
return -1;
- fd = open(sramfile, O_WRONLY|O_CREAT|O_TRUNC);
+ fd = open(sramfile, O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fd<0) return -1;
snprintf(meow,499,"Saving savedata to %s",sramfile);
rb->splash(HZ*2, meow);
@@ -263,7 +263,7 @@ static void rtc_save(void)
{
int fd;
if (!rtc.batt) return;
- if ((fd = open(rtcfile, O_WRONLY|O_CREAT|O_TRUNC))<0) return;
+ if ((fd = open(rtcfile, O_WRONLY|O_CREAT|O_TRUNC, 0666))<0) return;
rtc_save_internal(fd);
close(fd);
}
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) {
file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT);
/* attempt to open file descriptor here */
- if ((fd = open(path, file_mode)) < 0)
+ if ((fd = open(path, file_mode, 0666)) < 0)
return false;
/* 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)
{
options.dirty=0;
snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname);
- fd = open(optionsave, O_WRONLY|O_CREAT|O_TRUNC);
+ fd = open(optionsave, O_WRONLY|O_CREAT|O_TRUNC, 0666);
write(fd,&options, sizeof(options));
close(fd);
}
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);
#define isalpha(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && ((c) <= 'Z')))
#define isalnum(c) (isdigit(c) || (isalpha(c)))
-#define open(a,b) rb->open((a),(b))
+/* only 1 fixed argument for open, since variadic macros don't except empty
+ * variable parameters */
+#define open(a, ...) rb->open((a), __VA_ARGS__)
#define lseek(a,b,c) rb->lseek((a),(b),(c))
#define close(a) rb->close((a))
#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){
if (bomsize)
fdw = rb->open_utf8(resultfile, O_WRONLY|O_CREAT|O_TRUNC);
else
- fdw = rb->open(resultfile, O_WRONLY|O_CREAT|O_TRUNC);
+ fdw = rb->open(resultfile, O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fdw < 0) {
#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)
rb->close(parsefd);
hits=0;
if(result!=0) {
- int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC);
+ int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC, 0666);
int i;
for(i=0;i<rb->tagdbheader->filecount;i++)
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(
int fd;
(void)parameter;
- fd = rb->open(FILENAME, O_CREAT|O_TRUNC|O_WRONLY);
+ fd = rb->open(FILENAME, O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd < 0)
return PLUGIN_ERROR;
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)
}
if (filename[0] == '\0' ||
- (fd = rb->open(filename, O_WRONLY|O_CREAT|O_TRUNC)) < 0) {
+ (fd = rb->open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
rb->splashf(HZ*2, "Unable to open %s", filename);
return false;
}
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 )
{
char buf[MAX_PATH];
get_save_filename( buf );
- return rb->open( buf, flags );
+ return rb->open( buf, flags, 0666);
}
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)
if (bomsize)
fd = rb->open_utf8(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC);
else
- fd = rb->open(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC);
+ fd = rb->open(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
if(fd < 0)
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(
/* write the file 1 */
if (file_name1 != NULL)
{
- file1 = rb->open (file_name1, O_WRONLY | O_CREAT);
+ file1 = rb->open (file_name1, O_WRONLY | O_CREAT, 0666);
if (file1 >= 0)
{
int rc = copy_file(file1, src_file, end, y*2 + 1, y -1);
@@ -727,7 +727,7 @@ static int save(
if (file_name2 != NULL)
{
/* write file 2 */
- file2 = rb->open (file_name2, O_WRONLY | O_CREAT);
+ file2 = rb->open (file_name2, O_WRONLY | O_CREAT, 0666);
if (file2 >= 0)
{
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)
{
int fd;
- fd = rb->open(STOPWATCH_FILE, O_CREAT|O_WRONLY|O_TRUNC);
+ fd = rb->open(STOPWATCH_FILE, O_CREAT|O_WRONLY|O_TRUNC, 0666);
if (fd < 0)
{
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)
return false;
}
- fd=rb->open(state->filename, O_WRONLY|O_CREAT);
+ fd=rb->open(state->filename, O_WRONLY|O_CREAT, 0666);
if (fd >= 0) {
for (r=0;r<9;r++) {
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) {
return -1;
}
- fd = rb->open(savepath, O_WRONLY|O_CREAT);
+ fd = rb->open(savepath, O_WRONLY|O_CREAT, 0666);
DEBUGF("savepath: %s\n", savepath);
if(fd < 0) {
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)
if (use_logfile) {
rb->create_numbered_filename(logfilename, "/", "test_codec_log_", ".txt",
2 IF_CNFN_NUM_(, NULL));
- log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC);
+ log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666);
return log_fd >= 0;
}
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)
rb->create_numbered_filename(logfilename, "/", "test_disk_log_", ".txt",
2 IF_CNFN_NUM_(, NULL));
- log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC);
+ log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666);
return log_fd >= 0;
}
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)
rb->create_numbered_filename(logfilename, "/", "test_gfx_log_", ".txt",
2 IF_CNFN_NUM_(, NULL));
- fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC);
+ fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666);
return fd;
}
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)
case GREY_OK:
rb->create_numbered_filename(filename, "/", "test_grey_",
".txt", 2 IF_CNFN_NUM_(, NULL));
- fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC);
+ fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (fd >= 0)
{
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)
}
}
- fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC);
+ fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fd < 0)
{
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)
case 0:
if(create_log)
{
- log_fd = rb->open(LOG_FILENAME, O_WRONLY|O_CREAT|O_APPEND);
+ log_fd = rb->open(LOG_FILENAME, O_WRONLY|O_CREAT|O_APPEND, 0666);
if(log_fd >= 0)
rb->fdprintf(log_fd, "---- %s ----\n", title);
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)
static bool viewer_save_global_settings(void)
{
- int sfd = rb->open(GLOBAL_SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC);
+ int sfd = rb->open(GLOBAL_SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666);
unsigned char buf[GLOBAL_SETTINGS_H_SIZE];
if (sfd < 0)
@@ -2219,7 +2219,7 @@ static bool viewer_convert_settings_file(void)
if ((sfd = rb->open(SETTINGS_FILE, O_RDONLY)) < 0)
return false;
- if ((tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC)) < 0)
+ if ((tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
{
rb->close(sfd);
return false;
@@ -2441,7 +2441,7 @@ static bool viewer_save_settings(void)
bookmarks[bookmark_count-1].flag = BOOKMARK_LAST;
}
- tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC);
+ tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (tfd < 0)
return false;
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)
{8, 32000}, {9, 44100}, {10, 48000}
};
- fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC);
+ fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (fd < 0)
{
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){
#if 0
/* can use to save and later analyze what we produce */
- i = rb->open ( "/sound.raw" , O_WRONLY | O_APPEND | O_CREAT );
+ i = rb->open ( "/sound.raw" , O_WRONLY | O_APPEND | O_CREAT, 0666);
rb->write ( i , sp_sound_buf , TMNUM );
rb->close (i);
- i = rb->open ( "/sound2.raw" , O_WRONLY | O_APPEND |O_CREAT);
+ i = rb->open ( "/sound2.raw" , O_WRONLY | O_APPEND |O_CREAT, 0666);
rb->write ( i , (unsigned char *)my_buf , TMNUM*4*3 );
rb->close (i);
#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)
Check at each write since file may be deleted at any time */
if(!file_exists(SCROBBLER_FILE))
{
- fd = open(SCROBBLER_FILE, O_RDWR | O_CREAT);
+ fd = open(SCROBBLER_FILE, O_RDWR | O_CREAT, 0666);
if(fd >= 0)
{
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)
max_len-NVRAM_DATA_START-1,0xffffffff);
memcpy(&buf[4],&crc32,4);
#ifndef HAVE_RTC_RAM
- fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY);
+ fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd >= 0)
{
int len = write(fd,buf,max_len);
@@ -532,7 +532,7 @@ static bool settings_write_config(const char* filename, int options)
int i;
int fd;
char value[MAX_PATH];
- fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY);
+ fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd < 0)
return false;
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,
#ifdef SIMULATOR
/* Crude logging for the sim - to aid in debugging */
int logfd = open(ROCKBOX_DIR "/database.log",
- O_WRONLY | O_APPEND | O_CREAT);
+ O_WRONLY | O_APPEND | O_CREAT, 0666);
if (logfd >= 0) {
write(logfd, path, strlen(path));
write(logfd, "\n", 1);
@@ -2494,7 +2494,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
* anything whether the index type is sorted or not.
*/
snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type);
- fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
{
logf("%s open fail", buf);
@@ -2521,7 +2521,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
if (masterfd < 0)
{
logf("Creating new DB");
- masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC);
+ masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (masterfd < 0)
{
@@ -3447,7 +3447,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
return false;
/* Initialize the changelog */
- clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC);
+ clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (clfd < 0)
{
logf("failure to open changelog");
@@ -3820,7 +3820,7 @@ static bool tagcache_dumpsave(void)
if (!tc_stat.ramcache)
return false;
- fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
{
logf("failed to create a statedump");
@@ -4252,7 +4252,7 @@ void tagcache_build(const char *path)
return ;
}
- cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC);
+ cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (cachefd < 0)
{
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)
#if 0
/* Dump the flash */
- fd=open("/flash.bin",O_CREAT|O_RDWR);
+ fd=open("/flash.bin",O_CREAT|O_RDWR, 0666);
write(fd,(char*)0,1024*1024);
close(fd);
#endif
#if 1
/* Dump what may be the framebuffer */
- fd=open("/framebuffer.bin",O_CREAT|O_RDWR|O_TRUNC);
+ fd=open("/framebuffer.bin",O_CREAT|O_RDWR|O_TRUNC, 0666);
write(fd,framebuffer,220*176*4);
close(fd);
#endif
- fd=open("/gpio.txt",O_CREAT|O_RDWR|O_TRUNC);
+ fd=open("/gpio.txt",O_CREAT|O_RDWR|O_TRUNC, 0666);
unsigned int gpio_a = GPIOA_INPUT_VAL;
unsigned int gpio_b = GPIOB_INPUT_VAL;
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)
return -1;
logf("Saving directory cache");
- fd = open(DIRCACHE_FILE, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(DIRCACHE_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0666);
maindata.magic = DIRCACHE_MAGIC;
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);
int file_creat(const char *pathname)
{
- return open(pathname, O_WRONLY|O_CREAT|O_TRUNC);
+ return open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
}
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)
return fd;
}
-int open(const char* pathname, int flags)
+int file_open(const char* pathname, int flags)
{
/* By default, use the dircache if available. */
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)
if (pf->fd >= 0 && pf == &font_ui)
{
#ifdef WPSEDITOR
- cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC);
+ cache_fd = open(GLYPH_CACHE_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666);
#else
cache_fd = creat(GLYPH_CACHE_FILE, 0666);
#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 @@
#endif
#if defined(SIMULATOR) && !defined(PLUGIN) && !defined(CODEC)
-#define open(x,y) sim_open(x,y)
+#define open(x, ...) sim_open(x, __VA_ARGS__)
#define creat(x,m) sim_creat(x,m)
#define remove(x) sim_remove(x)
#define rename(x,y) sim_rename(x,y)
@@ -61,16 +61,17 @@
#define write(x,y,z) sim_write(x,y,z)
#define close(x) sim_close(x)
extern int sim_creat(const char *pathname, mode_t mode);
+extern int sim_open(const char *pathname, int flags, ...);
#endif
-typedef int (*open_func)(const char* pathname, int flags);
+typedef int (*open_func)(const char* pathname, int flags, ...);
typedef ssize_t (*read_func)(int fd, void *buf, size_t count);
typedef int (*creat_func)(const char *pathname, mode_t mode);
typedef ssize_t (*write_func)(int fd, const void *buf, size_t count);
typedef void (*qsort_func)(void *base, size_t nmemb, size_t size,
int(*_compar)(const void *, const void *));
-extern int open(const char* pathname, int flags);
+extern int file_open(const char* pathname, int flags);
extern int close(int fd);
extern int fsync(int fd);
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)
(void)mode;
return file_creat(pathname);
}
+#if !defined(CODEC) && !defined(PLUGIN)
+#define open(x, y, ...) file_open(x,y)
+#endif
#endif
extern ssize_t write(int fd, const void *buf, size_t count);
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() {
unsigned short current_index;
timer_unregister();
profiling = PROF_OFF;
- fd = open("/profile.out", O_WRONLY|O_CREAT|O_TRUNC);
+ fd = open("/profile.out", O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (profiling_exit == PROF_ERROR) {
fdprintf(fd,"Profiling exited with an error.\n");
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)
debug_file_close();
}
else if (fd < 0) {
- fd = open(DEBUG_FILE_NAME, O_WRONLY | O_APPEND | O_CREAT);
+ fd = open(DEBUG_FILE_NAME, O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd >= 0) {
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)
for (j=0; j<5; j++) {
int num = 40960;
- fd = open(name,O_WRONLY|O_CREAT|O_APPEND);
+ fd = open(name,O_WRONLY|O_CREAT|O_APPEND, 0666);
if (fd<0) {
DEBUGF("Failed opening file\n");
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*);
#define READDIR(a) (_wreaddir)(a)
#define CLOSEDIR(a) (_wclosedir)(a)
#define STAT(a,b) (_wstat)(UTF8_TO_OS(a),b)
-#define OPEN(a,b,c) (_wopen)(UTF8_TO_OS(a),b,c)
+/* empty variable parameter list doesn't work for variadic macros,
+ * so pretend the second parameter is variable too */
+#define OPEN(a,...) (_wopen)(UTF8_TO_OS(a), __VA_ARGS__)
#define CLOSE(a) (close)(a)
#define REMOVE(a) (_wremove)(UTF8_TO_OS(a))
#define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,convbuf2))
@@ -124,7 +126,9 @@ extern int _wrmdir(const wchar_t*);
#define READDIR(a) (readdir)(a)
#define CLOSEDIR(a) (closedir)(a)
#define STAT(a,b) (stat)(a,b)
-#define OPEN(a,b,c) (open)(a,b,c)
+/* empty variable parameter list doesn't work for variadic macros,
+ * so pretend the second parameter is variable too */
+#define OPEN(a, ...) (open)(a, __VA_ARGS__)
#define CLOSE(x) (close)(x)
#define REMOVE(a) (remove)(a)
#define RENAME(a,b) (rename)(a,b)
@@ -329,15 +333,23 @@ void sim_closedir(MYDIR *dir)
free(dir);
}
-int sim_open(const char *name, int o)
+int sim_open(const char *name, int o, ...)
{
int opts = rockbox2sim(o);
int ret;
-
if (num_openfiles >= MAX_OPEN_FILES)
return -2;
- ret = OPEN(get_sim_pathname(name), opts, 0666);
+ if (o & O_CREAT)
+ {
+ va_list ap;
+ va_start(ap, o);
+ ret = OPEN(get_sim_pathname(name), opts, va_arg(ap, mode_t));
+ va_end(ap);
+ }
+ else
+ ret = OPEN(get_sim_pathname(name), opts);
+
if (ret >= 0)
num_openfiles++;
return ret;