** Implementation of the POSIX opendir() function using the MSVCRT. */
| 1376 | ** Implementation of the POSIX opendir() function using the MSVCRT. |
| 1377 | */ |
| 1378 | LPDIR opendir( |
| 1379 | const char *dirname |
| 1380 | ){ |
| 1381 | struct _finddata_t data; |
| 1382 | LPDIR dirp = (LPDIR)sqlite3_malloc(sizeof(DIR)); |
| 1383 | SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]); |
| 1384 | |
| 1385 | if( dirp==NULL ) return NULL; |
| 1386 | memset(dirp, 0, sizeof(DIR)); |
| 1387 | |
| 1388 | /* TODO: Remove this if Unix-style root paths are not used. */ |
| 1389 | if( sqlite3_stricmp(dirname, "/")==0 ){ |
| 1390 | dirname = windirent_getenv("SystemDrive"); |
| 1391 | } |
| 1392 | |
| 1393 | memset(&data, 0, sizeof(struct _finddata_t)); |
| 1394 | _snprintf(data.name, namesize, "%s\\*", dirname); |
| 1395 | dirp->d_handle = _findfirst(data.name, &data); |
| 1396 | |
| 1397 | if( dirp->d_handle==BAD_INTPTR_T ){ |
| 1398 | closedir(dirp); |
| 1399 | return NULL; |
| 1400 | } |
| 1401 | |
| 1402 | /* TODO: Remove this block to allow hidden and/or system files. */ |
| 1403 | if( is_filtered(data) ){ |
| 1404 | next: |
| 1405 | |
| 1406 | memset(&data, 0, sizeof(struct _finddata_t)); |
| 1407 | if( _findnext(dirp->d_handle, &data)==-1 ){ |
| 1408 | closedir(dirp); |
| 1409 | return NULL; |
| 1410 | } |
| 1411 | |
| 1412 | /* TODO: Remove this block to allow hidden and/or system files. */ |
| 1413 | if( is_filtered(data) ) goto next; |
| 1414 | } |
| 1415 | |
| 1416 | dirp->d_first.d_attributes = data.attrib; |
| 1417 | strncpy(dirp->d_first.d_name, data.name, NAME_MAX); |
| 1418 | dirp->d_first.d_name[NAME_MAX] = '\0'; |
| 1419 | |
| 1420 | return dirp; |
| 1421 | } |
| 1422 | |
| 1423 | /* |
| 1424 | ** Implementation of the POSIX readdir() function using the MSVCRT. |
no test coverage detected