1*1424dfb3Schristos /* Restart reading the entries of a directory from the beginning.
2*1424dfb3Schristos    Copyright (C) 2011-2020 Free Software Foundation, Inc.
3*1424dfb3Schristos 
4*1424dfb3Schristos    This program is free software: you can redistribute it and/or modify
5*1424dfb3Schristos    it under the terms of the GNU General Public License as published by
6*1424dfb3Schristos    the Free Software Foundation; either version 3 of the License, or
7*1424dfb3Schristos    (at your option) any later version.
8*1424dfb3Schristos 
9*1424dfb3Schristos    This program is distributed in the hope that it will be useful,
10*1424dfb3Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
11*1424dfb3Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*1424dfb3Schristos    GNU General Public License for more details.
13*1424dfb3Schristos 
14*1424dfb3Schristos    You should have received a copy of the GNU General Public License
15*1424dfb3Schristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16*1424dfb3Schristos 
17*1424dfb3Schristos #include <config.h>
18*1424dfb3Schristos 
19*1424dfb3Schristos /* Specification.  */
20*1424dfb3Schristos #include <dirent.h>
21*1424dfb3Schristos 
22*1424dfb3Schristos #include <errno.h>
23*1424dfb3Schristos 
24*1424dfb3Schristos #include "dirent-private.h"
25*1424dfb3Schristos 
26*1424dfb3Schristos /* Don't assume that UNICODE is not defined.  */
27*1424dfb3Schristos #undef FindFirstFile
28*1424dfb3Schristos #define FindFirstFile FindFirstFileA
29*1424dfb3Schristos 
30*1424dfb3Schristos void
rewinddir(DIR * dirp)31*1424dfb3Schristos rewinddir (DIR *dirp)
32*1424dfb3Schristos {
33*1424dfb3Schristos   /* Like in closedir().  */
34*1424dfb3Schristos   if (dirp->current != INVALID_HANDLE_VALUE)
35*1424dfb3Schristos     FindClose (dirp->current);
36*1424dfb3Schristos 
37*1424dfb3Schristos   /* Like in opendir().  */
38*1424dfb3Schristos   dirp->status = -1;
39*1424dfb3Schristos   dirp->current = FindFirstFile (dirp->dir_name_mask, &dirp->entry);
40*1424dfb3Schristos   if (dirp->current == INVALID_HANDLE_VALUE)
41*1424dfb3Schristos     {
42*1424dfb3Schristos       switch (GetLastError ())
43*1424dfb3Schristos         {
44*1424dfb3Schristos         case ERROR_FILE_NOT_FOUND:
45*1424dfb3Schristos           dirp->status = -2;
46*1424dfb3Schristos           break;
47*1424dfb3Schristos         default:
48*1424dfb3Schristos           /* Save the error code for the next readdir() call.  */
49*1424dfb3Schristos           dirp->status = ENOENT;
50*1424dfb3Schristos           break;
51*1424dfb3Schristos         }
52*1424dfb3Schristos     }
53*1424dfb3Schristos }
54