From 5cdd920d1267a7548ab492864c4a20a20c3d93ff Mon Sep 17 00:00:00 2001 From: Teruaki Kawashima Date: Sun, 6 Dec 2009 13:52:28 +0000 Subject: Correct checking return value of open in plugins. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23874 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/brickmania.c | 2 ++ apps/plugins/chessbox/chessbox_pgn.c | 4 ++-- apps/plugins/chip8.c | 4 ++-- apps/plugins/jewels.c | 2 ++ apps/plugins/midi/guspat.c | 2 +- apps/plugins/midi/midifile.c | 2 +- apps/plugins/random_folder_advance_config.c | 4 ++-- apps/plugins/rockboy/menu.c | 2 +- apps/plugins/search.c | 8 +++++--- apps/plugins/superdom.c | 2 +- apps/plugins/viewer.c | 2 +- 11 files changed, 20 insertions(+), 14 deletions(-) diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c index 6ae8cb31ed..a372eb0813 100644 --- a/apps/plugins/brickmania.c +++ b/apps/plugins/brickmania.c @@ -1046,6 +1046,8 @@ static void brickmania_savegame(void) /* write out the game state to the save file */ fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT); + if(fd < 0) return; + rb->write(fd, &pad_pos_x, sizeof(pad_pos_x)); rb->write(fd, &life, sizeof(life)); rb->write(fd, &game_state, sizeof(game_state)); diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c index 512fb0ca15..a165e3ee8c 100644 --- a/apps/plugins/chessbox/chessbox_pgn.c +++ b/apps/plugins/chessbox/chessbox_pgn.c @@ -564,7 +564,7 @@ struct pgn_game_node* pgn_list_games(const char* filename){ int line_count = 0; bool header_start = true, game_start = false; - if ( (fhandler = rb->open(filename, O_RDONLY)) == 0 ) return NULL; + if ( (fhandler = rb->open(filename, O_RDONLY)) < 0 ) return NULL; if (bufptr == NULL){ pl_malloc_init(); @@ -572,7 +572,7 @@ struct pgn_game_node* pgn_list_games(const char* filename){ while (rb->read_line(fhandler, line_buffer, sizeof line_buffer) > 0){ line_count++; /* looking for a game header */ - if (header_start) { + if (header_start) { /* a new game header is found */ if (line_buffer[0] == '['){ temp_node = (struct pgn_game_node *)pl_malloc(sizeof size_node); diff --git a/apps/plugins/chip8.c b/apps/plugins/chip8.c index 3bdf95093a..7435518855 100644 --- a/apps/plugins/chip8.c +++ b/apps/plugins/chip8.c @@ -1329,7 +1329,7 @@ static bool chip8_init(const char* file) int i; fd = rb->open(file, O_RDONLY); - if (fd==-1) { + if (fd < 0) { rb->lcd_puts(0, 6, "File Error."); return false; } @@ -1351,7 +1351,7 @@ static bool chip8_init(const char* file) c8kname[len-2] = '8'; c8kname[len-1] = 'k'; fd = rb->open(c8kname, O_RDONLY); - if (fd!=-1) { + if (fd >= 0) { rb->lcd_puts(0, 6, "File&Keymap OK."); numread = rb->read(fd, chip8_keymap, 16); rb->close(fd); diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c index 51ad642c48..586caabfa5 100644 --- a/apps/plugins/jewels.c +++ b/apps/plugins/jewels.c @@ -480,6 +480,8 @@ 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); + if(fd < 0) return; + rb->write(fd, &bj->tmp_type, sizeof(bj->tmp_type)); rb->write(fd, &bj->type, sizeof(bj->type)); rb->write(fd, &bj->score, sizeof(bj->score)); diff --git a/apps/plugins/midi/guspat.c b/apps/plugins/midi/guspat.c index 124f779671..5f6ba35110 100644 --- a/apps/plugins/midi/guspat.c +++ b/apps/plugins/midi/guspat.c @@ -160,7 +160,7 @@ struct GPatch * gusload(char * filename) int file = rb->open(filename, O_RDONLY); - if(file == -1) + if(file < 0) { char message[50]; rb->snprintf(message, 50, "Error opening %s", filename); diff --git a/apps/plugins/midi/midifile.c b/apps/plugins/midi/midifile.c index 84e8b567bc..b5d9c5b6d1 100644 --- a/apps/plugins/midi/midifile.c +++ b/apps/plugins/midi/midifile.c @@ -31,7 +31,7 @@ struct MIDIfile * loadFile(const char * filename) struct MIDIfile * mfload; int file = rb->open (filename, O_RDONLY); - if(file==-1) + if(file < 0) { printf("Could not open file"); return NULL; diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c index ba3f0d3f7e..36b9ebfcbf 100644 --- a/apps/plugins/random_folder_advance_config.c +++ b/apps/plugins/random_folder_advance_config.c @@ -133,7 +133,7 @@ bool custom_dir(void) int i, errors = 0; /* populate removed dirs array */ - if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) > 0) + if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) >= 0) { while ((rb->read_line(fd2, line, MAX_PATH - 1)) > 0) { @@ -148,7 +148,7 @@ bool custom_dir(void) rb->close(fd2); } - if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) > 0) + if((fd2 = rb->open(RFADIR_FILE,O_RDONLY)) >= 0) { while ((rb->read_line(fd2, line, MAX_PATH - 1)) > 0) { diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c index bd4088300c..710a47646a 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)) < 0) return false; /* load/save state */ diff --git a/apps/plugins/search.c b/apps/plugins/search.c index e9732d219b..d732c0282b 100644 --- a/apps/plugins/search.c +++ b/apps/plugins/search.c @@ -121,7 +121,7 @@ static bool search_init(const char* file){ clear_display(); rb->splash(0, "Searching..."); fd = rb->open(file, O_RDONLY); - if (fd==-1) + if (fd < 0) return false; fdw = rb->creat(resultfile); @@ -132,6 +132,7 @@ static bool search_init(const char* file){ #else rb->splash(HZ, "File creation failed"); #endif + rb->close(fd); return false; } @@ -153,8 +154,9 @@ enum plugin_status plugin_start(const void* parameter) DEBUGF("%s - %s\n", (char *)parameter, &filename[rb->strlen(filename)-4]); /* Check the extension. We only allow .m3u files. */ - if(rb->strcasecmp(&filename[rb->strlen(filename)-4], ".m3u") && - rb->strcasecmp(&filename[rb->strlen(filename)-5], ".m3u8")) { + if (!(p = rb->strrchr(filename, '.')) || + (rb->strcasecmp(p, ".m3u") && rb->strcasecmp(p, ".m3u8"))) + { rb->splash(HZ, "Not a .m3u or .m3u8 file"); return PLUGIN_ERROR; } diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index 3fac0d0434..69dc607090 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c @@ -1935,7 +1935,7 @@ static int load_game(const char* file) { int fd; fd = rb->open(file, O_RDONLY); - if(fd == 0) { + if(fd < 0) { DEBUGF("Couldn't open savegame\n"); return -1; } diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index 5b84c08694..046c76523a 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -1193,7 +1193,7 @@ static bool viewer_init(void) #endif fd = rb->open(file_name, O_RDONLY); - if (fd==-1) + if (fd < 0) return false; file_size = rb->filesize(fd); -- cgit v1.2.3