diff options
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r-- | firmware/common/file.c | 18 |
1 files 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) | |||
63 | DIR* dir; | 63 | DIR* dir; |
64 | struct dirent* entry; | 64 | struct dirent* entry; |
65 | int fd; | 65 | int fd; |
66 | char pathnamecopy[MAX_PATH]; | ||
66 | char* name; | 67 | char* name; |
67 | struct filedesc* file = NULL; | 68 | struct filedesc* file = NULL; |
68 | int rc; | 69 | int rc; |
@@ -92,23 +93,26 @@ int open(const char* pathname, int flags) | |||
92 | 93 | ||
93 | if (flags & (O_RDWR | O_WRONLY)) { | 94 | if (flags & (O_RDWR | O_WRONLY)) { |
94 | file->write = true; | 95 | file->write = true; |
95 | 96 | ||
96 | if (flags & O_TRUNC) | 97 | if (flags & O_TRUNC) |
97 | file->trunc = true; | 98 | file->trunc = true; |
98 | } | 99 | } |
99 | file->busy = true; | 100 | file->busy = true; |
100 | 101 | ||
102 | strncpy(pathnamecopy,pathname,sizeof(pathnamecopy)); | ||
103 | pathnamecopy[sizeof(pathnamecopy)-1] = 0; | ||
104 | |||
101 | /* locate filename */ | 105 | /* locate filename */ |
102 | name=strrchr(pathname+1,'/'); | 106 | name=strrchr(pathnamecopy+1,'/'); |
103 | if ( name ) { | 107 | if ( name ) { |
104 | *name = 0; | 108 | *name = 0; |
105 | dir = opendir((char*)pathname); | 109 | dir = opendir(pathnamecopy); |
106 | *name = '/'; | 110 | *name = '/'; |
107 | name++; | 111 | name++; |
108 | } | 112 | } |
109 | else { | 113 | else { |
110 | dir = opendir("/"); | 114 | dir = opendir("/"); |
111 | name = (char*)pathname+1; | 115 | name = pathnamecopy+1; |
112 | } | 116 | } |
113 | if (!dir) { | 117 | if (!dir) { |
114 | DEBUGF("Failed opening dir\n"); | 118 | DEBUGF("Failed opening dir\n"); |
@@ -144,7 +148,7 @@ int open(const char* pathname, int flags) | |||
144 | &(file->fatfile), | 148 | &(file->fatfile), |
145 | &(dir->fatdir)); | 149 | &(dir->fatdir)); |
146 | if (rc < 0) { | 150 | if (rc < 0) { |
147 | DEBUGF("Couldn't create %s in %s\n",name,pathname); | 151 | DEBUGF("Couldn't create %s in %s\n",name,pathnamecopy); |
148 | errno = EIO; | 152 | errno = EIO; |
149 | file->busy = false; | 153 | file->busy = false; |
150 | closedir(dir); | 154 | closedir(dir); |
@@ -154,7 +158,7 @@ int open(const char* pathname, int flags) | |||
154 | file->attr = 0; | 158 | file->attr = 0; |
155 | } | 159 | } |
156 | else { | 160 | else { |
157 | DEBUGF("Couldn't find %s in %s\n",name,pathname); | 161 | DEBUGF("Couldn't find %s in %s\n",name,pathnamecopy); |
158 | errno = ENOENT; | 162 | errno = ENOENT; |
159 | file->busy = false; | 163 | file->busy = false; |
160 | closedir(dir); | 164 | closedir(dir); |