summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2008-04-16 19:51:43 +0000
committerNils Wallménius <nils@rockbox.org>2008-04-16 19:51:43 +0000
commita01996436d09eca8ae114e67005d2cac73cae7b3 (patch)
tree013d6787d3c03265049536677e817572c4285119 /apps
parentd65930f9720b0d51313b0e76251e56d2ffa144dd (diff)
downloadrockbox-a01996436d09eca8ae114e67005d2cac73cae7b3.tar.gz
rockbox-a01996436d09eca8ae114e67005d2cac73cae7b3.tar.bz2
rockbox-a01996436d09eca8ae114e67005d2cac73cae7b3.zip
Use file_exists and dir_exists functions where appropriate, fix one wrong file descriptor check and one possible dir descriptor leak
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17147 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/bookmark.c15
-rw-r--r--apps/cuesheet.c8
-rw-r--r--apps/language.c2
-rw-r--r--apps/main.c5
-rw-r--r--apps/onplay.c14
-rw-r--r--apps/playlist_catalog.c6
-rw-r--r--apps/recorder/radio.c6
-rw-r--r--apps/tree.c14
8 files changed, 18 insertions, 52 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c
index 363660306c..30102bb954 100644
--- a/apps/bookmark.c
+++ b/apps/bookmark.c
@@ -380,8 +380,6 @@ static bool check_bookmark(const char* bookmark)
/* ------------------------------------------------------------------------*/
bool bookmark_autoload(const char* file)
{
- int fd;
-
if(global_settings.autoloadbookmark == BOOKMARK_NO)
return false;
@@ -390,10 +388,10 @@ bool bookmark_autoload(const char* file)
{
return false;
}
- fd = open(global_bookmark_file_name, O_RDONLY);
- if(fd<0)
+
+ if(!file_exists(global_bookmark_file_name))
return false;
- close(fd);
+
if(global_settings.autoloadbookmark == BOOKMARK_YES)
{
return bookmark_load(global_bookmark_file_name, true);
@@ -1040,12 +1038,7 @@ bool bookmark_exist(void)
sizeof(global_temp_buffer));
if (generate_bookmark_file_name(name))
{
- int fd=open(global_bookmark_file_name, O_RDONLY);
- if (fd >=0)
- {
- close(fd);
- exist=true;
- }
+ exist = file_exists(global_bookmark_file_name);
}
}
diff --git a/apps/cuesheet.c b/apps/cuesheet.c
index ba6bc9659d..dcdba9f4c6 100644
--- a/apps/cuesheet.c
+++ b/apps/cuesheet.c
@@ -91,22 +91,20 @@ bool look_for_cuesheet_file(const char *trackpath, char *found_cue_path)
dot = strrchr(cuepath, '.');
strcpy(dot, ".cue");
- int fd = open(cuepath,O_RDONLY);
- if (fd < 0)
+ if (!file_exists(cuepath))
{
strcpy(cuepath, CUE_DIR);
strcat(cuepath, slash);
char *dot = strrchr(cuepath, '.');
strcpy(dot, ".cue");
- fd = open(cuepath,O_RDONLY);
- if (fd < 0)
+ if (!file_exists(cuepath))
{
if (found_cue_path)
found_cue_path = NULL;
return false;
}
}
- close(fd);
+
if (found_cue_path)
strncpy(found_cue_path, cuepath, MAX_PATH);
return true;
diff --git a/apps/language.c b/apps/language.c
index 3a4d0b354e..fb4f7da232 100644
--- a/apps/language.c
+++ b/apps/language.c
@@ -46,7 +46,7 @@ int lang_load(const char *filename)
int fd = open(filename, O_RDONLY);
int retcode=0;
unsigned char lang_header[3];
- if(fd == -1)
+ if(fd < 0)
return 1;
fsize = filesize(fd) - 2;
if(fsize <= MAX_LANGUAGE_SIZE) {
diff --git a/apps/main.c b/apps/main.c
index 7309d95df2..543f476f08 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -574,13 +574,10 @@ static void init(void)
#ifdef AUTOROCK
{
- int fd;
static const char filename[] = PLUGIN_APPS_DIR "/autostart.rock";
- fd = open(filename, O_RDONLY);
- if(fd >= 0) /* no complaint if it doesn't exist */
+ if(file_exists(filename)) /* no complaint if it doesn't exist */
{
- close(fd);
plugin_load((char*)filename, NULL); /* start if it does */
}
}
diff --git a/apps/onplay.c b/apps/onplay.c
index 47b962bd44..6822d4238f 100644
--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -783,14 +783,9 @@ static bool clipboard_pastedirectory(char *src, int srclen, char *target,
DIR *srcdir;
int srcdirlen = strlen(src);
int targetdirlen = strlen(target);
- int fd;
bool result = true;
- /* Check if the target exists */
- fd = open(target, O_RDONLY);
- close(fd);
-
- if (fd < 0) {
+ if (!file_exists(target)) {
if (!copy) {
/* Just move the directory */
result = rename(src, target) == 0;
@@ -871,7 +866,6 @@ static bool clipboard_paste(void)
char target[MAX_PATH];
char *cwd, *nameptr;
bool success;
- int target_fd;
unsigned char *lines[]={ID2P(LANG_REALLY_OVERWRITE)};
struct text_message message={(char **)lines, 1};
@@ -885,12 +879,8 @@ static bool clipboard_paste(void)
/* Final target is current directory plus name of selection */
snprintf(target, sizeof(target), "%s%s", cwd[1] ? cwd : "", nameptr);
- /* Check if we're going to overwrite */
- target_fd = open(target, O_RDONLY);
- close(target_fd);
-
/* If the target existed but they choose not to overwite, exit */
- if (target_fd >= 0 &&
+ if (file_exists(target) &&
(gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO)) {
return false;
}
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c
index 3eb884483c..9ac9e32e00 100644
--- a/apps/playlist_catalog.c
+++ b/apps/playlist_catalog.c
@@ -64,10 +64,8 @@ static int initialize_catalog(void)
if (!initialized)
{
- DIR* dir;
bool default_dir = true;
-
/* directory config is of the format: "dir: /path/to/dir" */
if (global_settings.playlist_catalog_dir[0])
{
@@ -82,11 +80,9 @@ static int initialize_catalog(void)
playlist_dir_length = strlen(playlist_dir);
- dir = opendir(playlist_dir);
- if (dir)
+ if (dir_exists(playlist_dir))
{
playlist_dir_exists = true;
- closedir(dir);
memset(most_recent_playlist, 0, sizeof(most_recent_playlist));
initialized = true;
}
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index 8d9b77cdc7..e103c6bc82 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -1211,9 +1211,9 @@ static int save_preset_list(void)
{
bool bad_file_name = true;
- if(!opendir(FMPRESET_PATH)) /* Check if there is preset folder */
- mkdir(FMPRESET_PATH);
-
+ if(!dir_exists(FMPRESET_PATH)) /* Check if there is preset folder */
+ mkdir(FMPRESET_PATH);
+
create_numbered_filename(filepreset, FMPRESET_PATH, "preset",
".fmr", 2 IF_CNFN_NUM_(, NULL));
diff --git a/apps/tree.c b/apps/tree.c
index c6e0c48d1c..275eb6ad2d 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -269,8 +269,7 @@ static int tree_voice_cb(int selected_item, void * data)
bool check_rockboxdir(void)
{
- DIR *dir = opendir(ROCKBOX_DIR);
- if(!dir)
+ if(!dir_exists(ROCKBOX_DIR))
{ /* No need to localise this message.
If .rockbox is missing, it wouldn't work anyway */
int i;
@@ -282,7 +281,6 @@ bool check_rockboxdir(void)
gui_syncsplash(HZ*2, "Installation incomplete");
return false;
}
- closedir(dir);
return true;
}
@@ -1086,10 +1084,8 @@ bool bookmark_play(char *resume_file, int index, int offset, int seed,
/* Playlist playback */
char* slash;
/* check that the file exists */
- int fd = open(resume_file, O_RDONLY);
- if(fd<0)
+ if(!file_exists(resume_file))
return false;
- close(fd);
slash = strrchr(resume_file,'/');
if (slash)
@@ -1171,7 +1167,6 @@ static void say_filetype(int attr)
static int ft_play_dirname(char* name)
{
- int fd;
char dirname_mp3_filename[MAX_PATH+1];
#if CONFIG_CODEC != SWCODEC
@@ -1185,15 +1180,12 @@ static int ft_play_dirname(char* name)
DEBUGF("Checking for %s\n", dirname_mp3_filename);
- fd = open(dirname_mp3_filename, O_RDONLY);
- if (fd < 0)
+ if (!file_exists(dirname_mp3_filename))
{
DEBUGF("Failed to find: %s\n", dirname_mp3_filename);
return -1;
}
- close(fd);
-
DEBUGF("Found: %s\n", dirname_mp3_filename);
talk_file(dirname_mp3_filename, false);