From f68e13c5b44797a2144ccd0be6d13d2d1b2926e5 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Mon, 19 Jul 2004 21:08:44 +0000 Subject: 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 --- firmware/common/file.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/firmware/common/file.c b/firmware/common/file.c index 18e66c044f..e875d43f2e 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); -- cgit v1.2.3