Fix FS#12824 : Malfunctioning FFT plugin in Sansa Clip Zip
[maemo-rb.git] / firmware / common / filefuncs.c
blob6c0275709c8768237055f7617fd312a59d8638fb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
22 #include "dir.h"
23 #include "stdlib.h"
24 #include "string.h"
25 #include "debug.h"
26 #include "file.h"
27 #include "filefuncs.h"
28 #include "string-extra.h"
30 #ifndef __PCTOOL__
31 #ifdef HAVE_MULTIVOLUME
33 /* returns on which volume this is, and copies the reduced name
34 (sortof a preprocessor for volume-decorated pathnames) */
35 int strip_volume(const char* name, char* namecopy)
37 int volume = 0;
38 const char *temp = name;
40 while (*temp == '/') /* skip all leading slashes */
41 ++temp;
43 if (*temp && !strncmp(temp, VOL_NAMES, VOL_ENUM_POS))
45 temp += VOL_ENUM_POS; /* behind special name */
46 volume = atoi(temp); /* number is following */
47 temp = strchr(temp, '/'); /* search for slash behind */
48 if (temp != NULL)
49 name = temp; /* use the part behind the volume */
50 else
51 name = "/"; /* else this must be the root dir */
54 strlcpy(namecopy, name, MAX_PATH);
56 return volume;
58 #endif /* #ifdef HAVE_MULTIVOLUME */
60 #endif /* __PCTOOL__ */
61 /* Test file existence, using dircache of possible */
62 bool file_exists(const char *file)
64 int fd;
66 #ifdef DEBUG
67 if (!file || !*file)
69 DEBUGF("%s(%p): Invalid parameter!\n", __func__, file);
70 return false;
72 #endif
74 #ifdef HAVE_DIRCACHE
75 if (dircache_is_enabled())
76 return (dircache_get_entry_id(file) >= 0);
77 #endif
79 fd = open(file, O_RDONLY);
80 if (fd < 0)
81 return false;
82 close(fd);
83 return true;
86 bool dir_exists(const char *path)
88 DIR* d = opendir(path);
89 if (!d)
90 return false;
91 closedir(d);
92 return true;
96 #if (CONFIG_PLATFORM & (PLATFORM_NATIVE|PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
97 struct dirinfo dir_get_info(DIR* parent, struct dirent *entry)
99 (void)parent;
100 return entry->info;
102 #endif