usr/src/lib/libc/port/gen/readdir_r.c
author Jon Tibble <meths@btinternet.com>
Thu, 09 Dec 2010 22:32:39 +0100
changeset 13255 4afa820d78b9
parent 6812 febeba71273d
permissions -rw-r--r--
298 SPARC build fails in smt_pause.o 478 Build needs fixing for pkgdepend flag day Reviewed by: [email protected] Reviewed by: [email protected] Reviewed by: [email protected] Approved by: [email protected]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
     5
 * Common Development and Distribution License (the "License").
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    21
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    22
/*
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 3453
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    24
 * Use is subject to license terms.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    25
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    26
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
/*	Copyright (c) 1988 AT&T	*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
/*	  All Rights Reserved  	*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 3453
diff changeset
    30
#pragma ident	"%Z%%M%	%I%	%E% SMI"
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 3453
diff changeset
    31
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    33
 * readdir_r -- C library extension routine
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    34
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    35
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
#include	<sys/feature_tests.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
#if !defined(_LP64)
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 3453
diff changeset
    39
#pragma weak _readdir64_r = readdir64_r
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    40
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    41
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 3453
diff changeset
    42
#include "lint.h"
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    43
#include "libc.h"
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    44
#include <mtlib.h>
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    45
#include <unistd.h>
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    46
#include <dirent.h>
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    47
#include <string.h>
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    48
#include <limits.h>
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    49
#include <errno.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    51
#ifdef _LP64
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    52
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    53
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    54
 * POSIX.1c standard version of the thread function readdir_r.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    55
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    56
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    57
int
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    58
readdir_r(DIR *dirp, dirent_t *entry, dirent_t **result)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    59
{
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    60
	private_DIR *pdirp = (private_DIR *)dirp;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    61
	dirent_t *dp;		/* -> directory data */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    62
	int saveloc = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    63
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    64
	lmutex_lock(&pdirp->dd_lock);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    65
	if (dirp->dd_size != 0) {
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    66
		dp = (dirent_t *)(uintptr_t)&dirp->dd_buf[dirp->dd_loc];
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    67
		saveloc = dirp->dd_loc;		/* save for possible EOF */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    68
		dirp->dd_loc += (int)dp->d_reclen;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    69
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    70
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    71
	if (dirp->dd_loc >= dirp->dd_size)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    72
		dirp->dd_loc = dirp->dd_size = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    73
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    74
	if (dirp->dd_size == 0 &&	/* refill buffer */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    75
	    (dirp->dd_size = getdents(dirp->dd_fd,
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    76
	    (dirent_t *)(uintptr_t)dirp->dd_buf, DIRBUF)) <= 0) {
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    77
		if (dirp->dd_size == 0) {	/* This means EOF */
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    78
			dirp->dd_loc = saveloc;	/* so save for telldir */
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    79
			lmutex_unlock(&pdirp->dd_lock);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    80
			*result = NULL;
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    81
			return (0);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    82
		}
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    83
		lmutex_unlock(&pdirp->dd_lock);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    84
		*result = NULL;
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    85
		return (errno);		/* error */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    86
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    87
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    88
	dp = (dirent_t *)(uintptr_t)&dirp->dd_buf[dirp->dd_loc];
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    89
	(void) memcpy(entry, dp, (size_t)dp->d_reclen);
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
    90
	lmutex_unlock(&pdirp->dd_lock);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    91
	*result = entry;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    92
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    93
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    94
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    95
#else	/* _LP64 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    96
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    97
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    98
 * POSIX.1c standard version of the thr function readdir_r.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    99
 * Large file version.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   100
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   101
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   102
int
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   103
readdir64_r(DIR *dirp, dirent64_t *entry, dirent64_t **result)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   104
{
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   105
	private_DIR *pdirp = (private_DIR *)(uintptr_t)dirp;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   106
	dirent64_t *dp64;	/* -> directory data */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   107
	int saveloc = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   108
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   109
	lmutex_lock(&pdirp->dd_lock);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   110
	if (dirp->dd_size != 0) {
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   111
		dp64 = (dirent64_t *)(uintptr_t)&dirp->dd_buf[dirp->dd_loc];
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   112
		/* was converted by readdir and needs to be reversed */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   113
		if (dp64->d_ino == (ino64_t)-1) {
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   114
			dirent_t *dp32;	/* -> 32 bit directory data */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   115
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   116
			dp32 = (dirent_t *)(&dp64->d_off);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   117
			dp64->d_ino = (ino64_t)dp32->d_ino;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   118
			dp64->d_off = (off64_t)dp32->d_off;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   119
			dp64->d_reclen = (unsigned short)(dp32->d_reclen +
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   120
			    ((char *)&dp64->d_off - (char *)dp64));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   121
		}
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   122
		saveloc = dirp->dd_loc;		/* save for possible EOF */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   123
		dirp->dd_loc += (int)dp64->d_reclen;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   124
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   125
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   126
	if (dirp->dd_loc >= dirp->dd_size)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   127
		dirp->dd_loc = dirp->dd_size = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   128
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   129
	if (dirp->dd_size == 0 &&	/* refill buffer */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   130
	    (dirp->dd_size = getdents64(dirp->dd_fd,
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   131
	    (dirent64_t *)(uintptr_t)dirp->dd_buf, DIRBUF)) <= 0) {
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   132
		if (dirp->dd_size == 0) {	/* This means EOF */
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   133
			dirp->dd_loc = saveloc;	/* so save for telldir */
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   134
			lmutex_unlock(&pdirp->dd_lock);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   135
			*result = NULL;
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   136
			return (0);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   137
		}
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   138
		lmutex_unlock(&pdirp->dd_lock);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   139
		*result = NULL;
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   140
		return (errno);		/* error */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   141
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   142
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   143
	dp64 = (dirent64_t *)(uintptr_t)&dirp->dd_buf[dirp->dd_loc];
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   144
	(void) memcpy(entry, dp64, (size_t)dp64->d_reclen);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   145
	*result = entry;
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   146
	lmutex_unlock(&pdirp->dd_lock);
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   147
	return (0);
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   148
}
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   149
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   150
/*
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   151
 * POSIX.1c standard version of the function readdir_r.
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   152
 * User gets it via static readdir_r from header file.
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   153
 */
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   154
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   155
int
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   156
__posix_readdir_r(DIR *dirp, dirent_t *entry, dirent_t **result)
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   157
{
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   158
	int error;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   159
	dirent64_t *dp64;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   160
	struct {
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   161
		dirent64_t dirent64;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   162
		char chars[MAXNAMLEN];
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   163
	} buf;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   164
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   165
	error = readdir64_r(dirp, (dirent64_t *)&buf, &dp64);
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   166
	if (error != 0 || dp64 == NULL) {
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   167
		*result = NULL;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   168
		return (error);
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   169
	}
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   170
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   171
	if (dp64->d_ino > SIZE_MAX ||
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   172
	    (uint64_t)dp64->d_off > (uint64_t)UINT32_MAX) {
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   173
		*result = NULL;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   174
		return (EOVERFLOW);
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   175
	}
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   176
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   177
	entry->d_ino = (ino_t)dp64->d_ino;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   178
	entry->d_off = (off_t)dp64->d_off;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   179
	entry->d_reclen = (unsigned short)((((char *)entry->d_name -
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   180
	    (char *)entry) + strlen(dp64->d_name) + 1 + 3) & ~3);
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   181
	(void) strcpy(entry->d_name, dp64->d_name);
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   182
	*result = entry;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   183
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   184
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   185
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   186
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   187
 * POSIX.1c Draft-6 version of the function readdir_r.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   188
 * It was implemented by Solaris 2.3.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   189
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   190
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   191
dirent_t *
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   192
readdir_r(DIR *dirp, dirent_t *entry)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   193
{
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   194
	int error;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   195
	dirent_t *result;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   196
3453
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   197
	if ((error = __posix_readdir_r(dirp, entry, &result)) != 0)
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   198
		errno = error;
bc3a776612a0 6513772 readdir_r() and associates should use per-DIR locking
raf
parents: 0
diff changeset
   199
	return (result);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   200
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   201
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   202
#endif	/* _LP64 */