MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_win32_open

Function dfs_win32_open

bsp/simulator/drivers/dfs_win32.c:147–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147static int dfs_win32_open(struct dfs_file *file)
148{
149 int fd;
150 uint32_t oflag, mode;
151 char *file_path;
152 int res;
153
154 oflag = file->flags;
155 if (oflag & O_DIRECTORY) /* operations about dir */
156 {
157 WINDIR *wdirp;
158 HANDLE handle;
159 int len;
160
161 file_path = winpath_dirdup(WIN32_DIRDISK_ROOT, file->vnode->path);
162
163 if (oflag & O_CREAT) /* create a dir*/
164 {
165 res = CreateDirectory(file_path, NULL);
166 if (res == 0)
167 {
168 rt_free(file_path);
169 return win32_result_to_dfs(GetLastError());
170 }
171 }
172
173 len = strlen(file_path);
174 if (file_path[len - 1] != '\\')
175 {
176 file_path[len] = '\\';
177 file_path[len + 1] = 0;
178 }
179
180 strcat(file_path, "*.*");
181 /* _findfirst will get '.' */
182 /* save this pointer,will used by dfs_win32_getdents*/
183 wdirp = rt_malloc(sizeof(WINDIR));
184 RT_ASSERT(wdirp != NULL);
185 if ((handle = _findfirst(file_path, &wdirp->finddata)) == -1)
186 {
187 rt_free(wdirp);
188 rt_free(file_path);
189 goto __err;
190 }
191 len = strlen(wdirp->finddata.name) + 1;
192 wdirp->handle = handle;
193 //wdirp->nfiles = 1;
194 wdirp->start = (char *)malloc(len); //not rt_malloc!
195 wdirp->end = wdirp->curr = wdirp->start;
196 wdirp->end += len;
197 rt_strncpy(wdirp->curr, wdirp->finddata.name, len);
198
199 file->vnode->data = (void *)wdirp;
200 rt_free(file_path);
201 return 0;
202 }
203 /* regular file operations */
204 mode = O_BINARY;

Callers

nothing calls this directly

Calls 8

winpath_dirdupFunction · 0.85
rt_freeFunction · 0.85
win32_result_to_dfsFunction · 0.85
rt_mallocFunction · 0.85
rt_strncpyFunction · 0.85
mallocFunction · 0.50
_openFunction · 0.50
_lseekFunction · 0.50

Tested by

no test coverage detected