rewinddir.c revision 271263
1230557Sjimharris/*-
2230557Sjimharris * Copyright (c) 1990, 1993
3230557Sjimharris *	The Regents of the University of California.  All rights reserved.
4230557Sjimharris *
5230557Sjimharris * Redistribution and use in source and binary forms, with or without
6230557Sjimharris * modification, are permitted provided that the following conditions
7230557Sjimharris * are met:
8230557Sjimharris * 1. Redistributions of source code must retain the above copyright
9230557Sjimharris *    notice, this list of conditions and the following disclaimer.
10230557Sjimharris * 2. Redistributions in binary form must reproduce the above copyright
11230557Sjimharris *    notice, this list of conditions and the following disclaimer in the
12230557Sjimharris *    documentation and/or other materials provided with the distribution.
13230557Sjimharris * 4. Neither the name of the University nor the names of its contributors
14230557Sjimharris *    may be used to endorse or promote products derived from this software
15230557Sjimharris *    without specific prior written permission.
16230557Sjimharris *
17230557Sjimharris * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18230557Sjimharris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19230557Sjimharris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20230557Sjimharris * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21230557Sjimharris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22230557Sjimharris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23230557Sjimharris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24230557Sjimharris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25230557Sjimharris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26230557Sjimharris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27230557Sjimharris * SUCH DAMAGE.
28230557Sjimharris */
29230557Sjimharris
30230557Sjimharris#if defined(LIBC_SCCS) && !defined(lint)
31230557Sjimharrisstatic char sccsid[] = "@(#)rewinddir.c	8.1 (Berkeley) 6/8/93";
32230557Sjimharris#endif /* LIBC_SCCS and not lint */
33230557Sjimharris#include <sys/cdefs.h>
34230557Sjimharris__FBSDID("$FreeBSD: stable/10/lib/libc/gen/rewinddir.c 271263 2014-09-08 14:45:58Z jhb $");
35230557Sjimharris
36230557Sjimharris#include "namespace.h"
37230557Sjimharris#include <sys/types.h>
38230557Sjimharris#include <dirent.h>
39230557Sjimharris#include <pthread.h>
40230557Sjimharris#include <unistd.h>
41230557Sjimharris#include "un-namespace.h"
42230557Sjimharris
43230557Sjimharris#include "libc_private.h"
44230557Sjimharris#include "gen-private.h"
45230557Sjimharris#include "telldir.h"
46230557Sjimharris
47230557Sjimharrisvoid
48230557Sjimharrisrewinddir(dirp)
49230557Sjimharris	DIR *dirp;
50230557Sjimharris{
51230557Sjimharris
52230557Sjimharris	if (__isthreaded)
53230557Sjimharris		_pthread_mutex_lock(&dirp->dd_lock);
54230557Sjimharris	if (dirp->dd_flags & __DTF_READALL)
55230557Sjimharris		_filldir(dirp, false);
56230557Sjimharris	else {
57230557Sjimharris		(void) lseek(dirp->dd_fd, 0, SEEK_SET);
58230557Sjimharris		dirp->dd_seek = 0;
59230557Sjimharris	}
60230557Sjimharris	dirp->dd_loc = 0;
61230557Sjimharris	_reclaim_telldir(dirp);
62230557Sjimharris	if (__isthreaded)
63230557Sjimharris		_pthread_mutex_unlock(&dirp->dd_lock);
64230557Sjimharris}
65230557Sjimharris