socsvn commit: r223371 - in soc2011/gk/ino64-head/lib/libc: gen include sys

gk at FreeBSD.org gk at FreeBSD.org
Fri Jun 17 22:30:15 UTC 2011


Author: gk
Date: Fri Jun 17 22:30:13 2011
New Revision: 223371
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223371

Log:
  libc: readdir, getdirentries

Added:
  soc2011/gk/ino64-head/lib/libc/gen/dirent-compat.h
     - copied, changed from r223370, soc2011/gk/ino64-head/lib/libc/include/compat.h
  soc2011/gk/ino64-head/lib/libc/gen/readdir-compat8.c   (contents, props changed)
  soc2011/gk/ino64-head/lib/libc/gen/scandir-compat8.c   (contents, props changed)
Modified:
  soc2011/gk/ino64-head/lib/libc/gen/Makefile.inc
  soc2011/gk/ino64-head/lib/libc/gen/Symbol.map
  soc2011/gk/ino64-head/lib/libc/include/compat.h
  soc2011/gk/ino64-head/lib/libc/sys/Symbol.map

Modified: soc2011/gk/ino64-head/lib/libc/gen/Makefile.inc
==============================================================================
--- soc2011/gk/ino64-head/lib/libc/gen/Makefile.inc	Fri Jun 17 22:29:57 2011	(r223370)
+++ soc2011/gk/ino64-head/lib/libc/gen/Makefile.inc	Fri Jun 17 22:30:13 2011	(r223371)
@@ -24,8 +24,8 @@
 	nlist.c nrand48.c opendir.c \
 	pause.c pmadvise.c popen.c posix_spawn.c \
 	psignal.c pututxline.c pw_scan.c pwcache.c \
-	raise.c readdir.c readpassphrase.c rewinddir.c \
-	scandir.c seed48.c seekdir.c semctl.c \
+	raise.c readdir.c readdir-compat8.c readpassphrase.c rewinddir.c \
+	scandir.c scandir-compat8.c seed48.c seekdir.c semctl.c \
 	setdomainname.c sethostname.c setjmperr.c setmode.c \
 	setproctitle.c setprogname.c siginterrupt.c siglist.c signal.c \
 	sigsetops.c sleep.c srand48.c statvfs.c stringlist.c strtofflags.c \

Modified: soc2011/gk/ino64-head/lib/libc/gen/Symbol.map
==============================================================================
--- soc2011/gk/ino64-head/lib/libc/gen/Symbol.map	Fri Jun 17 22:29:57 2011	(r223370)
+++ soc2011/gk/ino64-head/lib/libc/gen/Symbol.map	Fri Jun 17 22:30:13 2011	(r223371)
@@ -225,13 +225,9 @@
 	pclose;
 	psignal;
 	raise;
-	readdir;
-	readdir_r;
 	readpassphrase;
 	getpass;
 	rewinddir;
-	scandir;
-	alphasort;
 	seed48;
 	seekdir;
 	user_from_uid;
@@ -357,6 +353,7 @@
 };
 
 FBSD_1.2 {
+	alphasort;
 	basename_r;
 	cfmakesane;
 	dirfd;
@@ -367,6 +364,9 @@
 	getutxline;
 	getutxuser;
 	pututxline;
+	readdir;
+	readdir_r;
+	scandir;
 	sem_close;
 	sem_destroy;
 	sem_getvalue;

Copied and modified: soc2011/gk/ino64-head/lib/libc/gen/dirent-compat.h (from r223370, soc2011/gk/ino64-head/lib/libc/include/compat.h)
==============================================================================
--- soc2011/gk/ino64-head/lib/libc/include/compat.h	Fri Jun 17 22:29:57 2011	(r223370, copy source)
+++ soc2011/gk/ino64-head/lib/libc/gen/dirent-compat.h	Fri Jun 17 22:30:13 2011	(r223371)
@@ -1,7 +1,6 @@
-/*-
- * Copyright (c) 2009 Advanced Computing Technologies LLC
- * Written by: John H. Baldwin <jhb at FreeBSD.org>
- * All rights reserved.
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -11,11 +10,14 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -23,36 +25,22 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-/*
- * This file defines compatiblity symbol versions for old system calls.  It
- * is included in all generated system call files.
  */
 
-#ifndef __LIBC_COMPAT_H__
-#define	__LIBC_COMPAT_H__
-
-#define	__sym_compat(sym,impl,verid)	\
-	.symver impl, sym at verid
-
-__sym_compat(__semctl, freebsd7___semctl, FBSD_1.0);
-__sym_compat(msgctl, freebsd7_msgctl, FBSD_1.0);
-__sym_compat(shmctl, freebsd7_shmctl, FBSD_1.0);
-
-__sym_compat(nfstat, freebsd8_nfstat, FBSD_1.0);
-__sym_compat(nlstat, freebsd8_nlstat, FBSD_1.0);
-__sym_compat(nstat, freebsd8_nstat, FBSD_1.0);
-
-__sym_compat(fhstat, freebsd8_fhstat, FBSD_1.0);
-__sym_compat(fstat, freebsd8_fstat, FBSD_1.0);
-__sym_compat(fstatat, freebsd8_fstatat, FBSD_1.1);
-__sym_compat(lstat, freebsd8_lstat, FBSD_1.0);
-__sym_compat(stat, freebsd8_stat, FBSD_1.0);
-
-#undef __sym_compat
+#ifndef	_DIRENT_COMPAT_H_
+#define	_DIRENT_COMPAT_H_
 
-#endif	/* __LIBC_COMPAT_H__ */
+#define FREEBSD8_DIRSIZ(dp)						\
+	(sizeof(struct freebsd8_dirent) - sizeof((dp)->d_name) +	\
+	    (((dp)->d_namlen + 1 + 3) &~ 3))
+
+struct freebsd8_stat;
+
+struct freebsd8_dirent *freebsd8_readdir(DIR *);
+int	freebsd8_readdir_r(DIR *, struct freebsd8_dirent *,
+	    struct freebsd8_dirent **);
+int	freebsd8_stat(const char *, struct freebsd8_stat *);
+int	freebsd8_lstat(const char *, struct freebsd8_stat *);
+int	freebsd8_fstat(int, struct freebsd8_stat *);
 
+#endif /* _DIRENT_COMPAT_H_ */

Added: soc2011/gk/ino64-head/lib/libc/gen/readdir-compat8.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2011/gk/ino64-head/lib/libc/gen/readdir-compat8.c	Fri Jun 17 22:30:13 2011	(r223371)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <dirent.h>
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include "un-namespace.h"
+
+#include "libc_private.h"
+#include "dirent-compat.h"
+#include "dirent-private.h"
+#include "telldir.h"
+
+static int
+freebsd8_cvtdirent(struct freebsd8_dirent *dstdp, struct dirent *srcdp)
+{
+	if (srcdp->d_namlen > sizeof(dstdp->d_name) - 1)
+		return (ENAMETOOLONG);
+	dstdp->d_type = srcdp->d_type;
+	dstdp->d_namlen = srcdp->d_namlen;
+	dstdp->d_fileno = srcdp->d_fileno;		/* truncate */
+	dstdp->d_reclen = FREEBSD8_DIRSIZ(dstdp);
+	bcopy(srcdp->d_name, dstdp->d_name, dstdp->d_namlen);
+	bzero(dstdp->d_name + dstdp->d_namlen,
+	    dstdp->d_reclen - offsetof(struct freebsd8_dirent, d_name) -
+	    dstdp->d_namlen);
+	return (0);
+}
+
+struct freebsd8_dirent *
+freebsd8_readdir(DIR *dirp)
+{
+	static struct freebsd8_dirent *compatbuf;
+	struct freebsd8_dirent *dstdp;
+	struct dirent *dp;
+
+	if (__isthreaded)
+		_pthread_mutex_lock(&dirp->dd_lock);
+again:
+	dp = _readdir_unlocked(dirp, 1);
+	if (dp != NULL) {
+		if (compatbuf == NULL)
+			compatbuf = malloc(sizeof(struct freebsd8_dirent));
+		if (freebsd8_cvtdirent(compatbuf, dp) != 0)
+			goto again;
+		dstdp = compatbuf;
+	} else
+		dstdp = NULL;
+	if (__isthreaded)
+		_pthread_mutex_unlock(&dirp->dd_lock);
+
+	return (dstdp);
+}
+
+int
+freebsd8_readdir_r(DIR *dirp, struct freebsd8_dirent *entry,
+    struct freebsd8_dirent **result)
+{
+	struct dirent xentry;
+	struct dirent *xresult;
+	int error;
+
+again:
+	error = readdir_r(dirp, &xentry, &xresult);
+
+	if (error != 0)
+		return (error);
+	if (xresult != NULL) {
+		if (freebsd8_cvtdirent(entry, &xentry) != 0)
+			goto again;
+	} else
+		*result = NULL;
+	return (0);
+}
+
+__sym_compat(readdir, freebsd8_readdir, FBSD_1.0);
+__sym_compat(readdir_r, freebsd8_readdir_r, FBSD_1.0);

Added: soc2011/gk/ino64-head/lib/libc/gen/scandir-compat8.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2011/gk/ino64-head/lib/libc/gen/scandir-compat8.c	Fri Jun 17 22:30:13 2011	(r223371)
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+#include "un-namespace.h"
+
+#include "dirent-compat.h"
+
+static int alphasort_thunk(void *thunk, const void *p1, const void *p2);
+
+static int
+alphasort_thunk(void *thunk, const void *p1, const void *p2)
+{
+	int (*dc)(const struct dirent **, const struct dirent **);
+
+	dc = *(int (**)(const struct dirent **, const struct dirent **))thunk;
+	return (dc((const struct dirent **)p1, (const struct dirent **)p2));
+}
+
+int
+freebsd8_alphasort(const struct freebsd8_dirent **d1,
+    const struct freebsd8_dirent **d2)
+{
+
+	return (strcoll((*d1)->d_name, (*d2)->d_name));
+}
+
+int
+freebsd8_scandir(const char *dirname, struct freebsd8_dirent ***namelist,
+    int (*select)(const struct freebsd8_dirent *),
+    int (*dcomp)(const struct freebsd8_dirent **,
+	const struct freebsd8_dirent **))
+{
+	struct freebsd8_dirent *d, *p, **names = NULL;
+	size_t nitems = 0;
+	long arraysz;
+	DIR *dirp;
+
+	if ((dirp = opendir(dirname)) == NULL)
+		return(-1);
+
+	arraysz = 32;	/* initial estimate of the array size */
+	names = (struct freebsd8_dirent **)malloc(
+	    arraysz * sizeof(struct freebsd8_dirent *));
+	if (names == NULL)
+		goto fail;
+
+	while ((d = freebsd8_readdir(dirp)) != NULL) {
+		if (select != NULL && !(*select)(d))
+			continue;	/* just selected names */
+		/*
+		 * Make a minimum size copy of the data
+		 */
+		p = (struct freebsd8_dirent *)malloc(FREEBSD8_DIRSIZ(d));
+		if (p == NULL)
+			goto fail;
+		p->d_fileno = d->d_fileno;
+		p->d_type = d->d_type;
+		p->d_reclen = d->d_reclen;
+		p->d_namlen = d->d_namlen;
+		bcopy(d->d_name, p->d_name, p->d_namlen + 1);
+		/*
+		 * Check to make sure the array has space left and
+		 * realloc the maximum size.
+		 */
+		if (nitems >= arraysz) {
+			struct freebsd8_dirent **names2;
+
+			names2 = (struct freebsd8_dirent **)realloc(
+			    (char *)names,
+			    (arraysz * 2) * sizeof(struct freebsd8_dirent *));
+			if (names2 == NULL) {
+				free(p);
+				goto fail;
+			}
+			names = names2;
+			arraysz *= 2;
+		}
+		names[nitems++] = p;
+	}
+	closedir(dirp);
+	if (nitems && dcomp != NULL)
+		qsort_r(names, nitems, sizeof(struct freebsd8_dirent *),
+		    &dcomp, alphasort_thunk);
+	*namelist = names;
+	return (nitems);
+
+fail:
+	while (nitems > 0)
+		free(names[--nitems]);
+	free(names);
+	closedir(dirp);
+	return (-1);
+}
+
+__sym_compat(alphasort, freebsd8_alphasort, FBSD_1.0);
+__sym_compat(scandir, freebsd8_scandir, FBSD_1.0);

Modified: soc2011/gk/ino64-head/lib/libc/include/compat.h
==============================================================================
--- soc2011/gk/ino64-head/lib/libc/include/compat.h	Fri Jun 17 22:29:57 2011	(r223370)
+++ soc2011/gk/ino64-head/lib/libc/include/compat.h	Fri Jun 17 22:30:13 2011	(r223371)
@@ -52,6 +52,9 @@
 __sym_compat(lstat, freebsd8_lstat, FBSD_1.0);
 __sym_compat(stat, freebsd8_stat, FBSD_1.0);
 
+__sym_compat(getdents, freebsd8_getdents, FBSD_1.0);
+__sym_compat(getdirentries, freebsd8_getdirentries, FBSD_1.0);
+
 #undef __sym_compat
 
 #endif	/* __LIBC_COMPAT_H__ */

Modified: soc2011/gk/ino64-head/lib/libc/sys/Symbol.map
==============================================================================
--- soc2011/gk/ino64-head/lib/libc/sys/Symbol.map	Fri Jun 17 22:29:57 2011	(r223370)
+++ soc2011/gk/ino64-head/lib/libc/sys/Symbol.map	Fri Jun 17 22:30:13 2011	(r223371)
@@ -99,8 +99,6 @@
 	getaudit_addr;
 	getauid;
 	getcontext;
-	getdents;
-	getdirentries;
 	getdtablesize;
 	getegid;
 	geteuid;
@@ -358,6 +356,8 @@
 	fhstat;
 	fstat;
 	fstatat;
+	getdents;
+	getdirentries;
 	getloginclass;
 	lstat;
 	posix_fallocate;


More information about the svn-soc-all mailing list