* Read next directory entry. The directory entry is returned in dirent * structure in the d_name field. Individual directory entries returned by * this function include regular files, sub-directories, pseudo-directories * "." and ".." as well as volume labels, hidden files and system files. */
| 346 | * "." and ".." as well as volume labels, hidden files and system files. |
| 347 | */ |
| 348 | static struct _wdirent* |
| 349 | _wreaddir( |
| 350 | _WDIR *dirp) |
| 351 | { |
| 352 | WIN32_FIND_DATAW *datap; |
| 353 | struct _wdirent *entp; |
| 354 | |
| 355 | /* Read next directory entry */ |
| 356 | datap = dirent_next (dirp); |
| 357 | if (datap) { |
| 358 | size_t n; |
| 359 | DWORD attr; |
| 360 | |
| 361 | /* Pointer to directory entry to return */ |
| 362 | entp = &dirp->ent; |
| 363 | |
| 364 | /* |
| 365 | * Copy file name as wide-character string. If the file name is too |
| 366 | * long to fit in to the destination buffer, then truncate file name |
| 367 | * to PATH_MAX characters and zero-terminate the buffer. |
| 368 | */ |
| 369 | n = 0; |
| 370 | while (n + 1 < PATH_MAX && datap->cFileName[n] != 0) { |
| 371 | entp->d_name[n] = datap->cFileName[n]; |
| 372 | n++; |
| 373 | } |
| 374 | dirp->ent.d_name[n] = 0; |
| 375 | |
| 376 | /* Length of file name excluding zero terminator */ |
| 377 | entp->d_namlen = n; |
| 378 | |
| 379 | /* File type */ |
| 380 | attr = datap->dwFileAttributes; |
| 381 | if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { |
| 382 | entp->d_type = DT_CHR; |
| 383 | } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
| 384 | entp->d_type = DT_DIR; |
| 385 | } else { |
| 386 | entp->d_type = DT_REG; |
| 387 | } |
| 388 | |
| 389 | /* Reset dummy fields */ |
| 390 | entp->d_ino = 0; |
| 391 | entp->d_reclen = sizeof (struct _wdirent); |
| 392 | |
| 393 | } else { |
| 394 | |
| 395 | /* Last directory entry read */ |
| 396 | entp = NULL; |
| 397 | |
| 398 | } |
| 399 | |
| 400 | return entp; |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * Close directory stream opened by opendir() function. This invalidates the |
nothing calls this directly
no test coverage detected