summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2004-07-19 21:08:44 +0000
committerJens Arnold <amiconn@rockbox.org>2004-07-19 21:08:44 +0000
commitf68e13c5b44797a2144ccd0be6d13d2d1b2926e5 (patch)
tree0b7a90e0d1ba5f5cba524ae8e222f49d890a26ad
parent97d1d15bd82d1e40cc41e839610fa79c2ba05384 (diff)
downloadrockbox-f68e13c5b44797a2144ccd0be6d13d2d1b2926e5.zip
rockbox-f68e13c5b44797a2144ccd0be6d13d2d1b2926e5.tar.gz
rockbox-f68e13c5b44797a2144ccd0be6d13d2d1b2926e5.tar.bz2
rockbox-f68e13c5b44797a2144ccd0be6d13d2d1b2926e5.tar.xz
The pathname argument for open() is declared const, so copy it has to be copied
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4894 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/file.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 18e66c0..e875d43 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -63,6 +63,7 @@ int open(const char* pathname, int flags)
DIR* dir;
struct dirent* entry;
int fd;
+ char pathnamecopy[MAX_PATH];
char* name;
struct filedesc* file = NULL;
int rc;
@@ -92,23 +93,26 @@ int open(const char* pathname, int flags)
if (flags & (O_RDWR | O_WRONLY)) {
file->write = true;
-
+
if (flags & O_TRUNC)
file->trunc = true;
}
file->busy = true;
+ strncpy(pathnamecopy,pathname,sizeof(pathnamecopy));
+ pathnamecopy[sizeof(pathnamecopy)-1] = 0;
+
/* locate filename */
- name=strrchr(pathname+1,'/');
+ name=strrchr(pathnamecopy+1,'/');
if ( name ) {
- *name = 0;
- dir = opendir((char*)pathname);
+ *name = 0;
+ dir = opendir(pathnamecopy);
*name = '/';
name++;
}
else {
dir = opendir("/");
- name = (char*)pathname+1;
+ name = pathnamecopy+1;
}
if (!dir) {
DEBUGF("Failed opening dir\n");
@@ -144,7 +148,7 @@ int open(const char* pathname, int flags)
&(file->fatfile),
&(dir->fatdir));
if (rc < 0) {
- DEBUGF("Couldn't create %s in %s\n",name,pathname);
+ DEBUGF("Couldn't create %s in %s\n",name,pathnamecopy);
errno = EIO;
file->busy = false;
closedir(dir);
@@ -154,7 +158,7 @@ int open(const char* pathname, int flags)
file->attr = 0;
}
else {
- DEBUGF("Couldn't find %s in %s\n",name,pathname);
+ DEBUGF("Couldn't find %s in %s\n",name,pathnamecopy);
errno = ENOENT;
file->busy = false;
closedir(dir);