2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 1988, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * seekdir -- C library extension routine
2N/A */
2N/A
2N/A#include <sys/feature_tests.h>
2N/A
2N/A#if !defined(_LP64)
2N/A#pragma weak _seekdir64 = seekdir64
2N/A#endif
2N/A#pragma weak _seekdir = seekdir
2N/A
2N/A#include "lint.h"
2N/A#include "libc.h"
2N/A#include <mtlib.h>
2N/A#include <dirent.h>
2N/A#include <fcntl.h>
2N/A#include <unistd.h>
2N/A
2N/A#ifdef _LP64
2N/A
2N/Avoid
2N/Aseekdir(DIR *dirp, long loc)
2N/A{
2N/A private_DIR *pdirp = (private_DIR *)dirp;
2N/A dirent_t *dp;
2N/A off_t off = 0;
2N/A
2N/A lmutex_lock(&pdirp->d_lock);
2N/A if (lseek(dirp->d_fd, 0, SEEK_CUR) != 0) {
2N/A dp = (dirent_t *)(uintptr_t)&dirp->d_buf[dirp->d_loc];
2N/A off = dp->d_off;
2N/A }
2N/A if (off != loc) {
2N/A dirp->d_loc = 0;
2N/A (void) lseek(dirp->d_fd, loc, SEEK_SET);
2N/A dirp->d_size = 0;
2N/A
2N/A /*
2N/A * Save seek offset in d_off field, in case telldir
2N/A * follows seekdir with no intervening call to readdir
2N/A */
2N/A ((dirent_t *)(uintptr_t)&dirp->d_buf[0])->d_off = loc;
2N/A }
2N/A lmutex_unlock(&pdirp->d_lock);
2N/A}
2N/A
2N/A#else /* _LP64 */
2N/A
2N/A/*
2N/A * Note: Instead of making this function static, we reduce it to local
2N/A * scope in the mapfile. That allows the linker to prevent it from
2N/A * appearing in the .SUNW_dynsymsort section.
2N/A */
2N/Avoid
2N/Aseekdir64(DIR *dirp, off64_t loc)
2N/A{
2N/A private_DIR *pdirp = (private_DIR *)(uintptr_t)dirp;
2N/A dirent64_t *dp64;
2N/A off64_t off = 0;
2N/A
2N/A lmutex_lock(&pdirp->d_lock);
2N/A if (lseek64(dirp->d_fd, 0, SEEK_CUR) != 0) {
2N/A dp64 = (dirent64_t *)(uintptr_t)&dirp->d_buf[dirp->d_loc];
2N/A /* was converted by readdir and needs to be reversed */
2N/A if (dp64->d_ino == (ino64_t)-1) {
2N/A dirent_t *dp32;
2N/A
2N/A dp32 = (dirent_t *)((uintptr_t)dp64 + sizeof (ino64_t));
2N/A dp64->d_ino = (ino64_t)dp32->d_ino;
2N/A dp64->d_off = (off64_t)dp32->d_off;
2N/A dp64->d_reclen = (unsigned short)(dp32->d_reclen +
2N/A ((char *)&dp64->d_off - (char *)dp64));
2N/A }
2N/A off = dp64->d_off;
2N/A }
2N/A if (off != loc) {
2N/A dirp->d_loc = 0;
2N/A (void) lseek64(dirp->d_fd, loc, SEEK_SET);
2N/A dirp->d_size = 0;
2N/A
2N/A /*
2N/A * Save seek offset in d_off field, in case telldir
2N/A * follows seekdir with no intervening call to readdir
2N/A */
2N/A ((dirent64_t *)(uintptr_t)&dirp->d_buf[0])->d_off = loc;
2N/A }
2N/A lmutex_unlock(&pdirp->d_lock);
2N/A}
2N/A
2N/Avoid
2N/Aseekdir(DIR *dirp, long loc)
2N/A{
2N/A seekdir64(dirp, (off64_t)(uint32_t)loc);
2N/A}
2N/A
2N/A#endif /* _LP64 */