changeset 871:f917b2ed7d21

6346636 expunge readdir_r uses from Solaris 6346809 S_IFxxx is not a bitmask but our programmers don't know
author casper
date Wed, 09 Nov 2005 11:19:56 -0800
parents 31f4460227a3
children 3a2ac11314a8
files usr/src/cmd/audio/mixerctl/mixerctl.c usr/src/cmd/auditreduce/option.c usr/src/cmd/cat/cat.c usr/src/cmd/cdrw/device.c usr/src/cmd/cmd-crypto/decrypt/decrypt.c usr/src/cmd/cmd-crypto/digest/digest.c usr/src/cmd/cmd-inet/usr.sbin/in.ftpd/ftpd.c usr/src/cmd/cmd-inet/usr.sbin/in.rarpd.c usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.c usr/src/cmd/cmd-inet/usr.sbin/ipsecconf.c usr/src/cmd/consadm/consadm.c usr/src/cmd/cpio/cpio.c usr/src/cmd/cron/cron.c usr/src/cmd/devctl/devctl.c usr/src/cmd/devfsadm/devfsadm.c usr/src/cmd/devfsadm/devfsadm_impl.h usr/src/cmd/fm/fmd/common/fmd_asru.c usr/src/cmd/fm/fmd/common/fmd_module.c usr/src/cmd/fm/modules/sun4v/etm/etm_xport_api_dd.c usr/src/cmd/fs.d/nfs/share/issubdir.c usr/src/cmd/fs.d/nfs/statd/sm_statd.c usr/src/cmd/fs.d/nfs/statd/sm_svc.c usr/src/cmd/fs.d/ufs/volcopy/volcopy.c usr/src/cmd/init/init.c usr/src/cmd/ldap/common/fileurl.c usr/src/cmd/lp/cmd/lpadmin/chkopts.c usr/src/cmd/lp/cmd/lpsched/lpfsck.c usr/src/cmd/lp/cmd/lpsched/ports.c usr/src/cmd/lp/lib/forms/putform.c usr/src/cmd/lp/lib/printers/printwheels.c usr/src/cmd/lp/lib/printers/putprinter.c usr/src/cmd/pack/pack.c usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c usr/src/cmd/rcm_daemon/common/rcm_subr.c usr/src/cmd/rmformat/rmf_misc.c usr/src/cmd/sgs/libld/common/map.c usr/src/cmd/ssh/sftp/sftp-client.c usr/src/cmd/ssh/sftp/sftp-int.c usr/src/cmd/sulogin/sulogin.c usr/src/cmd/swap/swap.c usr/src/cmd/syseventd/daemons/syseventd/syseventd.c usr/src/cmd/syseventd/modules/sysevent_conf_mod/sysevent_conf_mod.c usr/src/cmd/tar/tar.c usr/src/cmd/utmp_update/utmp_update.c usr/src/cmd/volmgt/vold/vold_config.c usr/src/cmd/volmgt/vold/vold_main.c usr/src/cmd/xntpd/xntpd/ntp_filegen.c usr/src/cmd/ypcmd/shared/ancil.c usr/src/cmd/zoneadmd/zoneadmd.c usr/src/common/openssl/apps/ca.c usr/src/common/openssl/crypto/rand/randfile.c usr/src/lib/fm/libfmd_log/common/fmd_log.c usr/src/lib/libdevinfo/devinfo_devlink.c usr/src/lib/libdevinfo/devinfo_devperm.c usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c usr/src/lib/libdiskmgt/common/drive.c usr/src/lib/libdiskmgt/common/inuse_fs.c usr/src/lib/libdiskmgt/common/partition.c usr/src/lib/libdiskmgt/common/slice.c usr/src/lib/libdtrace/common/dt_cc.c usr/src/lib/libdtrace/common/dt_module.c usr/src/lib/libresolv2/common/bsd/writev.c usr/src/lib/libresolv2/common/isc/logging.c usr/src/lib/libsmedia/library/common/l_misc.c usr/src/lib/libsysevent/libsysevent.c usr/src/lib/lvm/libmeta/common/meta_name.c usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c usr/src/tools/cscope-fast/dir.c
diffstat 70 files changed, 341 insertions(+), 661 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/audio/mixerctl/mixerctl.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/audio/mixerctl/mixerctl.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,8 +20,8 @@
  * CDDL HEADER END
  */
 /*
- * Copyright (c) 1991-2001 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
  */
 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
@@ -321,7 +321,7 @@
 		(void) close(fd);
 		return (1);
 	}
-	if (!(buf.st_mode & S_IFCHR)) {
+	if (!S_ISCHR(buf.st_mode)) {
 		(void) fprintf(stderr,
 		    gettext("%s: %s is not a character special device\n"),
 		    info->pgm, dev);
--- a/usr/src/cmd/auditreduce/option.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/auditreduce/option.c	Wed Nov 09 11:19:56 2005 -0800
@@ -887,7 +887,7 @@
 	if (stat(fname, &stat_buf)) {
 		return (0);
 	}
-	if ((stat_buf.st_mode & S_IFREG) == 0)
+	if (!S_ISREG(stat_buf.st_mode))
 		return (0);
 	/*
 	 * Allocate a new fcb to hold fcb and full filename.
--- a/usr/src/cmd/cat/cat.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cat/cat.c	Wed Nov 09 11:19:56 2005 -0800
@@ -24,7 +24,7 @@
 
 
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -428,8 +428,7 @@
 		(void) lseek(fi_desc, (off_t)mapoffset, SEEK_SET);
 		(void) munmap(bufferp, (size_t)munmapsize);
 	} else {
-		if (((statp->st_mode & S_IFREG) == S_IFREG) &&
-		    ((outp->st_mode & S_IFREG) == S_IFREG)) {
+		if (S_ISREG(statp->st_mode) && S_ISREG(outp->st_mode)) {
 			bufferp = (char *)buf;
 			buffsize = SMALLFILESIZE;
 		} else {
--- a/usr/src/cmd/cdrw/device.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cdrw/device.c	Wed Nov 09 11:19:56 2005 -0800
@@ -324,7 +324,7 @@
 		free(p1);
 		return (0);
 	}
-	if (statbuf.st_mode & S_IFDIR) {
+	if (S_ISDIR(statbuf.st_mode)) {
 		for (i = 0; i < 16; i++) {
 			(void) snprintf(found, PATH_MAX, "%s/s%d", p1, i);
 			if (access(found, F_OK) >= 0)
@@ -383,7 +383,7 @@
 	char tmpstr[PATH_MAX];
 
 	/* If everything is fine and proper, no need to analyze */
-	if ((stat(supplied, &statbuf) == 0) && (statbuf.st_mode & S_IFCHR) &&
+	if ((stat(supplied, &statbuf) == 0) && S_ISCHR(statbuf.st_mode) &&
 	    ((fd = open(supplied, O_RDONLY|O_NDELAY)) >= 0)) {
 		(void) close(fd);
 		(void) strlcpy(found, supplied, PATH_MAX);
--- a/usr/src/cmd/cmd-crypto/decrypt/decrypt.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cmd-crypto/decrypt/decrypt.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1161,7 +1161,7 @@
 		return (-1);
 	}
 
-	if (!(statbuf.st_mode & S_IFREG)) {
+	if (!S_ISREG(statbuf.st_mode)) {
 		cryptoerror(LOG_STDERR, gettext(
 			"%s not a regular file"), filename);
 		(void) close(fd);
--- a/usr/src/cmd/cmd-crypto/digest/digest.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cmd-crypto/digest/digest.c	Wed Nov 09 11:19:56 2005 -0800
@@ -893,7 +893,7 @@
 			return (-1);
 		}
 
-		if (!(statbuf.st_mode & S_IFREG)) {
+		if (!S_ISREG(statbuf.st_mode)) {
 			cryptoerror(LOG_STDERR, gettext(
 				"%s not a regular file\n"), filename);
 			(void) close(fd);
--- a/usr/src/cmd/cmd-inet/usr.sbin/in.ftpd/ftpd.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cmd-inet/usr.sbin/in.ftpd/ftpd.c	Wed Nov 09 11:19:56 2005 -0800
@@ -3668,7 +3668,7 @@
     }
 
 #ifdef HAVE_LSTAT
-    if ((s.st_mode & S_IFLNK) == S_IFLNK) {
+    if (S_ISLNK(s.st_mode)) {
 	link = (char *) malloc(MAXPATHLEN);
 	memset(link, 0, MAXPATHLEN);
 	if (readlink(file, link, MAXPATHLEN) == -1) {
--- a/usr/src/cmd/cmd-inet/usr.sbin/in.rarpd.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cmd-inet/usr.sbin/in.rarpd.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
@@ -128,7 +128,6 @@
 static int	dflag = 0;		/* enable diagnostics */
 static int	aflag = 0;		/* start rarpd on all interfaces */
 static char	*alarmmsg;		/* alarm() error message */
-static long	pc_name_max;		/* pathconf maximum path name */
 
 static void	getintf(void);
 static struct rarpdev *find_device(ifspec_t *);
@@ -219,16 +218,6 @@
 	if (setrlimit(RLIMIT_NOFILE, &rl) == -1)
 		syserr("setrlimit");
 
-	/*
-	 * Look up the maximum name length of the BOOTDIR, it may not
-	 * exist so use /, if that fails use a reasonable sized buffer.
-	 */
-	if ((pc_name_max = pathconf(BOOTDIR, _PC_NAME_MAX)) == -1) {
-		if ((pc_name_max = pathconf("/", _PC_NAME_MAX)) == -1) {
-			pc_name_max = 255;
-		}
-	}
-
 	(void) openlog(cmdname, LOG_PID, LOG_DAEMON);
 
 	if (aflag) {
@@ -1162,7 +1151,6 @@
 	char path[MAXPATHL];
 	DIR *dirp;
 	struct dirent *dp;
-	struct dirent *dentry;
 
 	(void) snprintf(path, sizeof (path), "%s/%08X", BOOTDIR, ipa);
 
@@ -1181,18 +1169,7 @@
 	if (!(dirp = opendir(BOOTDIR)))
 		return (0);
 
-	dentry = (struct dirent *)malloc(sizeof (struct dirent) +
-							pc_name_max + 1);
-	if (dentry == NULL) {
-		error("out of memory");
-	}
-#ifdef _POSIX_PTHREAD_SEMANTICS
-	while ((readdir_r(dirp, dentry, &dp)) != 0) {
-		if (dp == NULL)
-			break;
-#else
-	while ((dp = readdir_r(dirp, dentry)) != NULL) {
-#endif
+	while ((dp = readdir(dirp)) != NULL) {
 		if (strncmp(dp->d_name, path, 8) != 0)
 			continue;
 		if ((strlen(dp->d_name) != 8) && (dp->d_name[8] != '.'))
@@ -1201,7 +1178,6 @@
 	}
 
 	(void) closedir(dirp);
-	(void) free(dentry);
 
 	return (dp? 1: 0);
 }
--- a/usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -9753,7 +9753,7 @@
 		 * link. Its link count should be 1. The owner should be
 		 * root and the file should be empty.
 		 */
-		if (((sbuf1.st_mode & (S_IFREG|S_IFLNK)) != S_IFREG) ||
+		if (!S_ISREG(sbuf1.st_mode) ||
 		    sbuf1.st_nlink != 1 ||
 		    sbuf1.st_uid != 0 ||
 		    sbuf1.st_size != 0) {
--- a/usr/src/cmd/cmd-inet/usr.sbin/ipsecconf.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ipsecconf.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1460,7 +1460,7 @@
 		 * link. Its link count should be 1. The owner should be
 		 * root and the file should be empty.
 		 */
-		if (((sbuf1.st_mode & (S_IFREG|S_IFLNK)) != S_IFREG) ||
+		if (!S_ISREG(sbuf1.st_mode) ||
 		    sbuf1.st_nlink != 1 ||
 		    sbuf1.st_uid != 0 ||
 		    sbuf1.st_size != 0) {
--- a/usr/src/cmd/consadm/consadm.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/consadm/consadm.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -487,10 +487,10 @@
 	if (strcmp(adev, bdev) == 0)
 		return (0);
 
-	if (stat(adev, &st1) || (st1.st_mode & S_IFCHR) == 0)
+	if (stat(adev, &st1) != 0 || !S_ISCHR(st1.st_mode))
 		die(gettext("invalid device %s\n"), adev);
 
-	if (stat(bdev, &st2) || (st2.st_mode & S_IFCHR) == 0)
+	if (stat(bdev, &st2) != 0 || !S_ISCHR(st2.st_mode))
 		die(gettext("invalid device %s\n"), bdev);
 
 	if (st1.st_rdev == st2.st_rdev)
--- a/usr/src/cmd/cpio/cpio.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cpio/cpio.c	Wed Nov 09 11:19:56 2005 -0800
@@ -6474,8 +6474,8 @@
 	bufsize = -1;
 	if (fstat(*fdes, &st_buf) == -1)
 		return (-1);
-	if (!(st_buf.st_mode & S_IFCHR) || !(st_buf.st_mode & S_IFBLK)) {
-		if (st_buf.st_mode & S_IFIFO) {
+	if (!S_ISCHR(st_buf.st_mode) && !S_ISBLK(st_buf.st_mode)) {
+		if (S_ISFIFO(st_buf.st_mode)) {
 			bufsize = 512;
 		} else {
 			/* find block size for this file system */
--- a/usr/src/cmd/cron/cron.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/cron/cron.c	Wed Nov 09 11:19:56 2005 -0800
@@ -2376,8 +2376,8 @@
 	else
 		--p->cruncnt;
 
-	if (!lstat(pr->outfile, &buf)) {
-		if ((buf.st_mode != S_IFLNK) &&
+	if (lstat(pr->outfile, &buf) == 0) {
+		if (!S_ISLNK(buf.st_mode) &&
 		    (buf.st_size > 0 || pr->mailwhendone)) {
 			/* mail user stdout and stderr */
 			for (;;) {
--- a/usr/src/cmd/devctl/devctl.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/devctl/devctl.c	Wed Nov 09 11:19:56 2005 -0800
@@ -251,7 +251,7 @@
 	 * if the device is a logical name, get the physical name
 	 */
 	if (lstat(orig_path, &stat_buf) == 0) {
-		if ((stat_buf.st_mode & S_IFLNK) == S_IFLNK) {
+		if (S_ISLNK(stat_buf.st_mode)) {
 			if ((pathlen = readlink(orig_path, devctl_device,
 			    MAXPATHLEN)) == -1)  {
 				(void) fprintf(stderr,
--- a/usr/src/cmd/devfsadm/devfsadm.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/devfsadm/devfsadm.c	Wed Nov 09 11:19:56 2005 -0800
@@ -2237,8 +2237,7 @@
 load_modules(void)
 {
 	DIR *mod_dir;
-	struct dirent *entp = NULL;
-	struct dirent *retp;
+	struct dirent *entp;
 	char cdir[PATH_MAX + 1];
 	char *last;
 	char *mdir = module_dirs;
@@ -2270,13 +2269,7 @@
 			continue;
 		}
 
-		entp = s_malloc(PATH_MAX + 1 + sizeof (struct  dirent));
-
-		while (readdir_r(mod_dir, entp, &retp) == 0) {
-
-			if (retp == NULL) {
-				break;
-			}
+		while ((entp = readdir(mod_dir)) != NULL) {
 
 			if ((strcmp(entp->d_name, ".") == 0) ||
 			    (strcmp(entp->d_name, "..") == 0)) {
@@ -2286,7 +2279,6 @@
 			load_module(entp->d_name, cdir);
 		}
 		s_closedir(mod_dir);
-		free(entp);
 	}
 }
 
@@ -3385,7 +3377,7 @@
 	devfsadm_rm_work(file, TRUE, TYPE_LINK);
 }
 
-static void
+static int
 s_rmdir(char *path)
 {
 	int	i;
@@ -3406,12 +3398,13 @@
 			if (strcmp(rpath, dir) == 0) {
 				vprint(REMOVE_MID, "%s: skipping packaged dir: "
 				    "%s\n", fcn, path);
-				return;
+				errno = EEXIST;
+				return (-1);
 			}
 		}
 	}
 
-	(void) rmdir(path);
+	return (rmdir(path));
 }
 
 /*
@@ -3424,17 +3417,11 @@
 {
 	char *ptr, path[PATH_MAX + 1];
 	char *fcn = "rm_parent_dir_if_empty: ";
-	struct dirent *entp;
-	struct dirent *retp;
-	DIR *dp;
 
 	vprint(REMOVE_MID, "%schecking %s if empty\n", fcn, pathname);
 
 	(void) strcpy(path, pathname);
 
-	entp = (struct dirent *)s_malloc(PATH_MAX + 1 +
-					    sizeof (struct dirent));
-
 	/*
 	 * ascend up the dir tree, deleting all empty dirs.
 	 * Return immediately if a dir is not empty.
@@ -3447,34 +3434,18 @@
 
 		*ptr = '\0';
 
-		if ((dp = opendir(path)) == NULL) {
-			err_print(OPENDIR_FAILED, path, strerror(errno));
-			free(entp);
+		if (s_rmdir(path) == 0) {
+			vprint(REMOVE_MID, "%sremoving empty dir %s\n",
+			    fcn, path);
+			continue;
+		}
+		if (errno == EEXIST) {
+			vprint(REMOVE_MID, "%sdir not empty: %s\n", fcn, path);
 			return;
 		}
-
-		while (readdir_r(dp, entp, &retp) == 0) {
-
-			if (retp == NULL) {
-				vprint(REMOVE_MID, "%sremoving empty dir %s\n",
-						fcn, path);
-				s_rmdir(path);
-				break;
-			}
-
-			if (strcmp(entp->d_name, ".") == 0 ||
-			    strcmp(entp->d_name, "..") == 0) {
-				continue;
-			}
-
-			/* some other file is here, so return */
-			vprint(REMOVE_MID, "%sdir not empty: %s\n", fcn, path);
-			free(entp);
-			s_closedir(dp);
-			return;
-
-		}
-		s_closedir(dp);
+		vprint(REMOVE_MID, "%s can't remove %s: %s\n", fcn, path,
+		    strerror(errno));
+		return;
 	}
 }
 
@@ -4501,7 +4472,6 @@
 	char new_path[PATH_MAX + 1];
 	char *anchored_path_re;
 	struct dirent *entp;
-	struct dirent *retp;
 	DIR *dp;
 	size_t len;
 
@@ -4517,8 +4487,6 @@
 		len = (slash - path_re);
 	}
 
-	entp = s_malloc(PATH_MAX + 1 + sizeof (struct  dirent));
-
 	anchored_path_re = s_malloc(len + 3);
 	(void) sprintf(anchored_path_re, "^%.*s$", len, path_re);
 
@@ -4529,12 +4497,7 @@
 
 	free(anchored_path_re);
 
-	while (readdir_r(dp, entp, &retp) == 0) {
-
-		/* See 4062296 to understand readdir_r semantics */
-		if (retp == NULL) {
-			break;
-		}
+	while ((entp = readdir(dp)) != NULL) {
 
 		if (strcmp(entp->d_name, ".") == 0 ||
 		    strcmp(entp->d_name, "..") == 0) {
@@ -4564,7 +4527,6 @@
 	regfree(&re1);
 
 out:
-	free(entp);
 	s_closedir(dp);
 }
 
@@ -5286,7 +5248,6 @@
 get_stat_info(char *namebuf, struct stat *sb)
 {
 	struct dirent *entp;
-	struct dirent *retp;
 	DIR *dp;
 	char *cp;
 
@@ -5309,16 +5270,11 @@
 			return (DEVFSADM_FAILURE);
 		}
 
-		entp = s_malloc(PATH_MAX + 1 + sizeof (struct  dirent));
-
 		/*
 		 *  Search each dir entry looking for a symlink.  Return
 		 *  the first symlink found in namebuf.  Recurse dirs.
 		 */
-		while (readdir_r(dp,  entp, &retp) == 0) {
-			if (retp == NULL) {
-				break;
-			}
+		while ((entp = readdir(dp)) != NULL) {
 			if (strcmp(entp->d_name, ".") == 0 ||
 			    strcmp(entp->d_name, "..") == 0) {
 				continue;
@@ -5328,13 +5284,11 @@
 			(void) strcat(namebuf, "/");
 			(void) strcat(namebuf, entp->d_name);
 			if (get_stat_info(namebuf, sb) == DEVFSADM_SUCCESS) {
-				free(entp);
 				s_closedir(dp);
 				return (DEVFSADM_SUCCESS);
 			}
 			*cp = '\0';
 		}
-		free(entp);
 		s_closedir(dp);
 	}
 
@@ -5461,7 +5415,6 @@
 	char *new_path;
 	char *numeral_id;
 	struct dirent *entp;
-	struct dirent *retp;
 	DIR *dp;
 
 	if ((dp = opendir(current_dir)) == NULL) {
@@ -5477,13 +5430,7 @@
 		*slash = '\0';
 	}
 
-	entp = s_malloc(PATH_MAX + 1 + sizeof (struct  dirent));
-
-	while (readdir_r(dp, entp, &retp) == 0) {
-
-		if (retp == NULL) {
-			break;
-		}
+	while ((entp = readdir(dp)) != NULL) {
 
 		if (strcmp(entp->d_name, ".") == 0 ||
 		    strcmp(entp->d_name, "..") == 0) {
@@ -5524,7 +5471,6 @@
 	if (slash != NULL) {
 		*slash = '/';
 	}
-	free(entp);
 	s_closedir(dp);
 }
 
--- a/usr/src/cmd/devfsadm/devfsadm_impl.h	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/devfsadm/devfsadm_impl.h	Wed Nov 09 11:19:56 2005 -0800
@@ -404,7 +404,7 @@
 static linkhead_t *get_cached_links(char *dir_re);
 static void build_devlink_list(char *check_link, void *data);
 static void instance_flush_thread(void);
-static void s_rmdir(char *path);
+static int s_rmdir(char *path);
 static void rm_parent_dir_if_empty(char *path);
 static void free_link_list(link_list_t *head);
 static void free_selector_list(selector_list_t *head);
--- a/usr/src/cmd/fm/fmd/common/fmd_asru.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/fm/fmd/common/fmd_asru.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -328,7 +328,7 @@
 void
 fmd_asru_hash_refresh(fmd_asru_hash_t *ahp)
 {
-	struct dirent *dp, *ep;
+	struct dirent *dp;
 	DIR *dirp;
 	int zero;
 
@@ -339,12 +339,10 @@
 	}
 
 	(void) fmd_conf_getprop(fmd.d_conf, "rsrc.zero", &zero);
-	ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
-	bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
 
 	(void) pthread_rwlock_wrlock(&ahp->ah_lock);
 
-	while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) {
+	while ((dp = readdir(dirp)) != NULL) {
 		if (dp->d_name[0] == '.')
 			continue; /* skip "." and ".." */
 
--- a/usr/src/cmd/fm/fmd/common/fmd_module.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/fm/fmd/common/fmd_module.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1006,17 +1006,14 @@
     const fmd_modops_t *ops)
 {
 	char path[PATH_MAX];
-	struct dirent *dp, *ep;
+	struct dirent *dp;
 	const char *p;
 	DIR *dirp;
 
 	if ((dirp = opendir(dir)) == NULL)
 		return; /* failed to open directory; just skip it */
 
-	ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
-	bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
-
-	while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) {
+	while ((dp = readdir(dirp)) != NULL) {
 		if (dp->d_name[0] == '.')
 			continue; /* skip "." and ".." */
 
--- a/usr/src/cmd/fm/modules/sun4v/etm/etm_xport_api_dd.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/fm/modules/sun4v/etm/etm_xport_api_dd.c	Wed Nov 09 11:19:56 2005 -0800
@@ -720,7 +720,7 @@
 		rv = (-errno);
 		goto func_ret;
 	}
-	if ((stat_buf.st_mode & S_IFCHR) == 0) {
+	if (!S_ISCHR(stat_buf.st_mode)) {
 		etm_xport_should_fake_dd = 1;	/* not a char driver */
 	}
 	fmd_hdl_debug(hdl, "info: etm_xport_should_fake_dd %d\n",
--- a/usr/src/cmd/fs.d/nfs/share/issubdir.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/fs.d/nfs/share/issubdir.c	Wed Nov 09 11:19:56 2005 -0800
@@ -110,7 +110,7 @@
 				break;
 			}
 			child_ino[index++] = st.st_ino;
-			if (st.st_mode & S_IFDIR) {
+			if (S_ISDIR(st.st_mode)) {
 				p = strcpy(p, "/..") + 3;
 			} else {
 				p = strrchr(childdir, '/');
--- a/usr/src/cmd/fs.d/nfs/statd/sm_statd.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/fs.d/nfs/statd/sm_statd.c	Wed Nov 09 11:19:56 2005 -0800
@@ -100,7 +100,7 @@
 void
 statd_init()
 {
-	struct dirent *dirp, *entp;
+	struct dirent *dirp;
 	DIR 	*dp;
 	FILE *fp, *fp_tmp;
 	int i, tmp_state;
@@ -222,12 +222,7 @@
 		exit(1);
 	}
 
-	entp = (struct dirent *)xmalloc(MAXDIRENT);
-	if (entp == NULL) {
-		exit(1);
-	}
-
-	while ((dirp = readdir_r(dp, entp)) != (struct dirent *)NULL) {
+	while ((dirp = readdir(dp)) != NULL) {
 		if (strcmp(dirp->d_name, ".") != 0 &&
 			strcmp(dirp->d_name, "..") != 0) {
 		/* rename all entries from CURRENT to BACKUP */
@@ -235,7 +230,6 @@
 		}
 	}
 
-	free(entp);
 	(void) closedir(dp);
 
 	/* Contact hosts' statd */
@@ -252,7 +246,7 @@
 void *
 thr_statd_init()
 {
-	struct dirent *dirp, *entp;
+	struct dirent *dirp;
 	DIR 	*dp;
 	int num_threads;
 	int num_join;
@@ -266,11 +260,6 @@
 		exit(1);
 	}
 
-	entp = (struct dirent *)xmalloc(MAXDIRENT);
-	if (entp == NULL) {
-		exit(1);
-	}
-
 	/*
 	 * Create "UNDETACHED" threads for each symlink and (unlinked)
 	 * regular file in backup directory to initiate statd_call_statd.
@@ -278,7 +267,7 @@
 	 * program and thus, the thread id is not needed to join the threads.
 	 */
 	num_threads = 0;
-	while ((dirp = readdir_r(dp, entp)) != (struct dirent *)NULL) {
+	while ((dirp = readdir(dp)) != NULL) {
 		/*
 		 * If host file is not a symlink, don't bother to
 		 * spawn a thread for it.  If any link(s) refer to
@@ -335,9 +324,6 @@
 		thr_join(0, 0, 0);
 	}
 
-	/* Reuse the buffer for readdir_r use */
-	(void) memset(entp, 0, MAXDIRENT);
-
 	/*
 	 * The second pass checks for `legacies':  regular files which
 	 * never had symlinks pointing to them at all, just like in the
@@ -347,7 +333,7 @@
 	 */
 	rewinddir(dp);
 	num_threads = 0;
-	while ((dirp = readdir_r(dp, entp)) != (struct dirent *)NULL) {
+	while ((dirp = readdir(dp)) != NULL) {
 		if (strcmp(dirp->d_name, ".") == 0 ||
 			strcmp(dirp->d_name, "..") == 0) {
 			continue;
@@ -404,7 +390,6 @@
 		num_threads++;
 	}
 
-	free(entp);
 	(void) closedir(dp);
 
 	/*
@@ -1132,7 +1117,7 @@
 	int cnt = 0;
 	int n;
 	DIR *dp;
-	struct dirent *dirp, *entp;
+	struct dirent *dirp;
 	char lpath[MAXPATHLEN];
 	char rname[MAXNAMELEN + 1]; /* +1 for term NULL */
 
@@ -1142,13 +1127,7 @@
 		return (-1);
 	}
 
-	entp = (struct dirent *)xmalloc(MAXDIRENT);
-	if (entp == NULL) {
-		(void) closedir(dp);
-		return (-1);
-	}
-
-	while ((dirp = readdir_r(dp, entp)) != (struct dirent *)NULL) {
+	while ((dirp = readdir(dp)) != NULL) {
 		if (strcmp(dirp->d_name, ".") == 0 ||
 			strcmp(dirp->d_name, "..") == 0) {
 			continue;
@@ -1181,7 +1160,6 @@
 		}
 	}
 
-	free(entp);
 	(void) closedir(dp);
 
 	if (debug) {
--- a/usr/src/cmd/fs.d/nfs/statd/sm_svc.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/fs.d/nfs/statd/sm_svc.c	Wed Nov 09 11:19:56 2005 -0800
@@ -297,7 +297,7 @@
 char *path_dir;
 {
 	DIR	*dp;
-	struct dirent   *dirp, *entp;
+	struct dirent   *dirp;
 	char tmp_path[MAXPATHLEN];
 
 	if ((dp = opendir(path_dir)) == (DIR *)NULL) {
@@ -307,13 +307,7 @@
 		return (1);
 	}
 
-	entp = (struct dirent *)xmalloc(MAXDIRENT);
-	if (entp == NULL) {
-		(void) closedir(dp);
-		return (1);
-	}
-
-	while ((dirp = readdir_r(dp, entp)) != (struct dirent *)NULL) {
+	while ((dirp = readdir(dp)) != NULL) {
 		if (strcmp(dirp->d_name, ".") != 0 &&
 			strcmp(dirp->d_name, "..") != 0) {
 			if (strlen(path_dir) + strlen(dirp->d_name) +2 >
@@ -332,7 +326,6 @@
 		}
 	}
 
-	free(entp);
 	(void) closedir(dp);
 	return (0);
 }
@@ -348,7 +341,7 @@
 {
 	int	n;
 	DIR	*dp;
-	struct dirent   *dirp, *entp;
+	struct dirent   *dirp;
 	char rname[MAXNAMELEN + 1];
 	char path[MAXPATHLEN+MAXNAMELEN+2];
 
@@ -359,13 +352,7 @@
 		return;
 	}
 
-	entp = (struct dirent *)xmalloc(MAXDIRENT);
-	if (entp == NULL) {
-		(void) closedir(dp);
-		return;
-	}
-
-	while ((dirp = readdir_r(dp, entp)) != (struct dirent *)NULL) {
+	while ((dirp = readdir(dp)) != NULL) {
 		if (strcmp(dirp->d_name, ".") == 0 ||
 			strcmp(dirp->d_name, "..") == 0) {
 			continue;
@@ -403,7 +390,6 @@
 		}
 	}
 
-	free(entp);
 	(void) closedir(dp);
 }
 
--- a/usr/src/cmd/fs.d/ufs/volcopy/volcopy.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/fs.d/ufs/volcopy/volcopy.c	Wed Nov 09 11:19:56 2005 -0800
@@ -191,8 +191,8 @@
 	*devtype = G_NO_DEV;
 	if (fstat64(*fdes, &st_buf) == -1)
 		return (-1);
-	if (!(st_buf.st_mode & S_IFCHR) && !(st_buf.st_mode & S_IFBLK)) {
-		if (st_buf.st_mode & S_IFIFO)
+	if (!S_ISCHR(st_buf.st_mode) && !S_ISBLK(st_buf.st_mode)) {
+		if (S_ISFIFO(st_buf.st_mode))
 			bufsize = 512;
 		else {
 			/* find block size for this file system */
--- a/usr/src/cmd/init/init.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/init/init.c	Wed Nov 09 11:19:56 2005 -0800
@@ -2832,8 +2832,8 @@
 
 	if (stat(SYSCON, &sconbuf) != -1 &&
 	    stat(CONSOLE, &conbuf) != -1 &&
-	    sconbuf.st_mode & S_IFCHR &&
-	    conbuf.st_mode & S_IFCHR &&
+	    S_ISCHR(sconbuf.st_mode) &&
+	    S_ISCHR(conbuf.st_mode) &&
 	    sconbuf.st_rdev == conbuf.st_rdev) {
 		return (1);
 	} else {
--- a/usr/src/cmd/ldap/common/fileurl.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/ldap/common/fileurl.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -289,7 +289,7 @@
 	case LDAPTOOL_FILEURL_SUCCESS:
 	    if ( stat( path, &fstats ) != 0 ) {
 		if ( reporterrs ) perror( path );
-	    } else if ( fstats.st_mode & S_IFDIR ) {	
+	    } else if (S_ISDIR(fstats.st_mode)) {	
 		if ( reporterrs ) fprintf( stderr,
 					   gettext("%s: %s is a directory, not a file\n"),
 					   ldaptool_progname, path );
@@ -306,7 +306,7 @@
 				       " -- unknown error\n"), ldaptool_progname, url );
 	}
     } else if ( always_try_file && (stat( value, &fstats ) == 0) &&
-		!(fstats.st_mode & S_IFDIR)) {	/* get value from file */
+		!S_ISDIR(fstats.st_mode)) {	/* get value from file */
 	rc = berval_from_file( value, bvp, reporterrs );
     } else {
 	bvp->bv_len = vlen;
--- a/usr/src/cmd/lp/cmd/lpadmin/chkopts.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/lp/cmd/lpadmin/chkopts.c	Wed Nov 09 11:19:56 2005 -0800
@@ -746,8 +746,7 @@
 	 * If the device is a symlink (and it is not a root owned symlink),
 	 * verify that the owner matches the destination owner.
 	 */
-	if (((statbuf.st_mode & S_IFLNK) == S_IFLNK) &&
-	    (statbuf.st_uid != 0)) {
+	if (S_ISLNK(statbuf.st_mode) && statbuf.st_uid != 0) {
 		uid_t uid = statbuf.st_uid;
 
 		if (Stat(path, &statbuf) == -1) {
--- a/usr/src/cmd/lp/cmd/lpsched/lpfsck.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/lp/cmd/lpsched/lpfsck.c	Wed Nov 09 11:19:56 2005 -0800
@@ -279,25 +279,27 @@
 		return;
 
 	case D:
-		if (exist && (stbuf.st_mode & S_IFDIR) == 0)
+		if (exist && !S_ISDIR(stbuf.st_mode)) {
 			if (!rm_ok)
 				fail ("%s is not a directory!\n", path);
 			else {
 				Unlink (path);
 				exist = 0;
 			}
+		}
 		if (!exist)
 			Mkdir (path, 0);
 		break;
 
 	case F:
-		if (exist && (stbuf.st_mode & S_IFREG) == 0)
+		if (exist && !S_ISREG(stbuf.st_mode)) {
 			if (!rm_ok)
 				fail ("%s is not a file!\n", path);
 			else {
 				Unlink (path);
 				exist = 0;
 			}
+		}
 		if (!exist)
 			Close(Creat(path, 0));
 		break;
@@ -306,13 +308,15 @@
 		/*
 		 * Either a pipe or a file.
 		 */
-		if (exist && (stbuf.st_mode & (S_IFREG|S_IFIFO)) == 0)
+		if (exist &&
+		    !S_ISREG(stbuf.st_mode) && !S_ISFIFO(stbuf.st_mode)) {
 			if (!rm_ok)
 				fail ("%s is not a file or pipe!\n", path);
 			else {
 				Unlink (path);
 				exist = 0;
 			}
+		}
 		if (!exist)
 			Close(Creat(path, 0));
 		break;
--- a/usr/src/cmd/lp/cmd/lpsched/ports.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/lp/cmd/lpsched/ports.c	Wed Nov 09 11:19:56 2005 -0800
@@ -286,7 +286,7 @@
 	 * If we have a stream and a list of modules to use, then pop the old
 	 * modules and push the new ones.
 	 */
-	if ((modules != NULL) && !(buf.st_mode & S_IFIFO) && isastream(1)) {
+	if ((modules != NULL) && !S_ISFIFO(buf.st_mode) && isastream(1)) {
 		/*
 		 * First, pop all current modules off, unless
 		 * instructed not to.
--- a/usr/src/cmd/lp/lib/forms/putform.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/lp/lib/forms/putform.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -72,7 +72,7 @@
 	if (!(path = getformfile(name, (char *)0)))
 		return (-1);
 	if (Stat(path, &statbuf) == 0) {
-		if (!(statbuf.st_mode & S_IFDIR)) {
+		if (!S_ISDIR(statbuf.st_mode)) {
 			Free (path);
 			errno = ENOTDIR;
 			return (-1);
--- a/usr/src/cmd/lp/lib/printers/printwheels.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/lp/lib/printers/printwheels.c	Wed Nov 09 11:19:56 2005 -0800
@@ -19,11 +19,15 @@
  *
  * CDDL HEADER END
  */
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
 
-#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.13	*/
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
 
 #include "string.h"
@@ -131,7 +135,7 @@
 	if (!(path = makepath(Lp_A_PrintWheels, name, (char *)0)))
 		return (-1);
 	if (Stat(path, &statbuf) == 0) {
-		if (!(statbuf.st_mode & S_IFDIR)) {
+		if (!S_ISDIR(statbuf.st_mode)) {
 			Free (path);
 			errno = ENOTDIR;
 			return (-1);
--- a/usr/src/cmd/lp/lib/printers/putprinter.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/lp/lib/printers/putprinter.c	Wed Nov 09 11:19:56 2005 -0800
@@ -138,7 +138,7 @@
 	if (!(path = getprinterfile(name, (char *)0)))
 		return (-1);
 	if (Stat(path, &statbuf1) == 0) {
-		if (!(statbuf1.st_mode & S_IFDIR)) {
+		if (!S_ISDIR(statbuf1.st_mode)) {
 			Free (path);
 			errno = ENOTDIR;
 			return (-1);
--- a/usr/src/cmd/pack/pack.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/pack/pack.c	Wed Nov 09 11:19:56 2005 -0800
@@ -428,7 +428,7 @@
 			continue;
 		}
 		fstat(infile, &status);
-		if (status.st_mode&S_IFDIR) {
+		if (S_ISDIR(status.st_mode)) {
 			fprintf(stderr, gettext(
 				"pack: %s: cannot pack a directory\n"),
 				    argv[k]);
--- a/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -704,14 +704,10 @@
 	struct mc_memconf	mcmemconf;
 	int			fd;
 	DIR			*dirp;
-	struct dirent		*entp, *retp;
+	struct dirent		*retp;
 	char			path[PATH_MAX];
 	int 			found = 0;
 
-#ifdef lint
-extern struct dirent *readdir_r(DIR *__dp, struct dirent *__ent);
-#endif
-
 	/* open the directory */
 	if ((dirp = opendir(MC_DIR)) == NULL) {
 		/*
@@ -724,14 +720,8 @@
 		return (-1);
 	}
 
-	entp = (struct dirent *)malloc(PATH_MAX +
-				    sizeof (struct dirent));
-	if (entp == NULL)
-		return (-1);
-
-
 	/* start searching this directory */
-	while ((retp = (struct dirent *)readdir_r(dirp, entp)) != NULL) {
+	while ((retp = readdir(dirp)) != NULL) {
 		/* skip . .. etc... */
 		if (strcmp(retp->d_name, ".") == 0 ||
 		    strcmp(retp->d_name, "..") == 0)
@@ -745,7 +735,6 @@
 			break;
 		}
 	}
-	free(entp);
 	(void) closedir(dirp);
 
 	if (!found) {
--- a/usr/src/cmd/rcm_daemon/common/rcm_subr.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/rcm_daemon/common/rcm_subr.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1504,15 +1504,11 @@
 {
 	char *tmp;
 	DIR *mod_dir;
-	struct dirent *retp, *entp;
+	struct dirent *entp;
 	int i;
 	char *dir_name;
 	int rcm_script;
 
-#ifdef	lint
-extern int readdir_r(DIR *, struct dirent *, struct dirent **);
-#endif
-
 	rcm_log_message(RCM_DEBUG, "rcmd_db_init(): initialize database\n");
 
 	if (script_main_init() == -1)
@@ -1520,8 +1516,6 @@
 
 	rsrc_root = rn_alloc("/", RSRC_TYPE_NORMAL);
 
-	entp = s_malloc(PATH_MAX + 1 + sizeof (struct dirent));
-
 	for (i = 0; (dir_name = rcm_dir(i, &rcm_script)) != NULL; i++) {
 
 		if ((mod_dir = opendir(dir_name)) == NULL) {
@@ -1530,13 +1524,9 @@
 
 		rcm_log_message(RCM_TRACE2, "search directory %s\n", dir_name);
 
-		while (readdir_r(mod_dir, entp, &retp) == 0) {
+		while ((entp = readdir(mod_dir)) != NULL) {
 			module_t *module;
 
-			if (retp == NULL) {
-				break;
-			}
-
 			if (strcmp(entp->d_name, ".") == 0 ||
 				strcmp(entp->d_name, "..") == 0)
 				continue;
@@ -1570,7 +1560,6 @@
 		(void) closedir(mod_dir);
 	}
 
-	free(entp);
 	rcmd_db_print();
 }
 
--- a/usr/src/cmd/rmformat/rmf_misc.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/rmformat/rmf_misc.c	Wed Nov 09 11:19:56 2005 -0800
@@ -625,7 +625,7 @@
 		PERROR("Could not stat");
 		return (-1);
 	}
-	if (stat_buf.st_mode & S_IFDIR) {
+	if (S_ISDIR(stat_buf.st_mode)) {
 
 		/*
 		 * Open the directory and look for the
@@ -1499,7 +1499,7 @@
 	    (char *)NULL);
 
 	/* If everything is fine and proper, no need to analyze */
-	if ((stat(supplied, &statbuf) == 0) && (statbuf.st_mode & S_IFCHR) &&
+	if ((stat(supplied, &statbuf) == 0) && S_ISCHR(statbuf.st_mode) &&
 	    ((fd = open(supplied, O_RDONLY|O_NDELAY)) >= 0)) {
 		(void) close(fd);
 		(void) strlcpy(found, supplied, PATH_MAX);
@@ -1640,7 +1640,7 @@
 		free(p1);
 		return (0);
 	}
-	if (statbuf.st_mode & S_IFDIR) {
+	if (S_ISDIR(statbuf.st_mode)) {
 		for (i = 0; i < 16; i++) {
 			(void) snprintf(found, PATH_MAX, "%s/s%d", p1, i);
 			if (access(found, F_OK) >= 0)
--- a/usr/src/cmd/sgs/libld/common/map.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/sgs/libld/common/map.c	Wed Nov 09 11:19:56 2005 -0800
@@ -24,7 +24,7 @@
  *	  All Rights Reserved
  *
  *
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
@@ -2015,7 +2015,7 @@
 		    strerror(err));
 		return (S_ERROR);
 	}
-	if (stat_buf.st_mode & S_IFDIR) {
+	if (S_ISDIR(stat_buf.st_mode)) {
 		DIR		*dirp;
 		struct dirent	*denp;
 
@@ -2042,7 +2042,7 @@
 		}
 		(void) closedir(dirp);
 		return (1);
-	} else if (!(stat_buf.st_mode & S_IFREG)) {
+	} else if (!S_ISREG(stat_buf.st_mode)) {
 		eprintf(ERR_FATAL, MSG_INTL(MSG_SYS_NOTREG), mapfile);
 		return (S_ERROR);
 	}
--- a/usr/src/cmd/ssh/sftp/sftp-client.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/ssh/sftp/sftp-client.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -771,7 +771,7 @@
 		mode = 0666;
 
 	if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) &&
-	    (a->perm & S_IFDIR)) {
+	    S_ISDIR(a->perm)) {
 		error("Cannot download a directory: %s", remote_path);
 		return(-1);
 	}
--- a/usr/src/cmd/ssh/sftp/sftp-int.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/ssh/sftp/sftp-int.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -380,7 +380,7 @@
 	if (stat(path, &sb) == -1)
 		return(0);
 
-	return(sb.st_mode & S_IFDIR);
+	return (S_ISDIR(sb.st_mode));
 }
 
 static int
@@ -393,7 +393,7 @@
 		return(0);
 	if (!(a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS))
 		return(0);
-	return(a->perm & S_IFDIR);
+	return (S_ISDIR(a->perm));
 }
 
 static int
--- a/usr/src/cmd/sulogin/sulogin.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/sulogin/sulogin.c	Wed Nov 09 11:19:56 2005 -0800
@@ -403,10 +403,10 @@
 	if (strcmp(adev, bdev) == 0)
 		return (0);
 
-	if (stat(adev, &st1) || (st1.st_mode & S_IFCHR) == 0)
+	if (stat(adev, &st1) || !S_ISCHR(st1.st_mode))
 		return (1);
 
-	if (stat(bdev, &st2) || (st2.st_mode & S_IFCHR) == 0)
+	if (stat(bdev, &st2) || !S_ISCHR(st2.st_mode))
 		return (1);
 
 	if (st1.st_rdev == st2.st_rdev)
--- a/usr/src/cmd/swap/swap.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/swap/swap.c	Wed Nov 09 11:19:56 2005 -0800
@@ -386,13 +386,15 @@
 				(void) printf(gettext("%-20s ?,? "),
 					fullpath);
 		else {
-			if (statbuf.st_mode & (S_IFBLK | S_IFCHR))
+			if (S_ISBLK(statbuf.st_mode) ||
+			    S_ISCHR(statbuf.st_mode)) {
 				(void) printf(gettext("%-19s %2lu,%-2lu"),
 				    fullpath,
 				    major(statbuf.st_rdev),
 				    minor(statbuf.st_rdev));
-			else
+			} else {
 				(void) printf(gettext("%-20s  -  "), fullpath);
+			}
 		}
 		{
 		int diskblks_per_page =
--- a/usr/src/cmd/syseventd/daemons/syseventd/syseventd.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/syseventd/daemons/syseventd/syseventd.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1152,7 +1152,7 @@
 	int client_id;
 	DIR *mod_dir;
 	module_t *mod;
-	struct dirent *retp, *entp;
+	struct dirent *entp;
 	struct slm_mod_ops *mod_ops;
 	struct sysevent_client *scp;
 
@@ -1168,25 +1168,13 @@
 
 	syseventd_print(3, "loading modules from %s\n", dirname);
 
-	entp = malloc(PATH_MAX + 1 + sizeof (struct dirent));
-	if (entp == NULL) {
-		syseventd_err_print(LOAD_MOD_ALLOC_ERR, "entp",
-			strerror(errno));
-		(void) closedir(mod_dir);
-		return;
-	}
-
 	/*
 	 * Go through directory, looking for files ending with .so
 	 */
-	while (readdir_r(mod_dir, entp, &retp) == 0) {
+	while ((entp = readdir(mod_dir)) != NULL) {
 		void *dlh, *f;
 		char *tmp, modpath[MAXPATHLEN];
 
-		if (retp == NULL) {
-			break;
-		}
-
 		if (((tmp = strstr(entp->d_name, MODULE_SUFFIX)) == NULL) ||
 		    (tmp[strlen(MODULE_SUFFIX)] != '\0')) {
 			continue;
@@ -1293,7 +1281,6 @@
 		syseventd_print(3, "loaded module %s\n", entp->d_name);
 	}
 
-	free(entp);
 	(void) closedir(mod_dir);
 	syseventd_print(3, "modules loaded\n");
 }
--- a/usr/src/cmd/syseventd/modules/sysevent_conf_mod/sysevent_conf_mod.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/syseventd/modules/sysevent_conf_mod/sysevent_conf_mod.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -752,40 +752,16 @@
 	conftab_t	*cfp = NULL;
 	DIR		*dir;
 	struct dirent	*result;
-	struct dirent	*entry;
-	int		err;
 	conftab_t	*new_cfp;
 	char		*str;
-	long		max_name;
-	size_t		dirent_size;
 
-	max_name = pathconf(SYSEVENT_CONFIG_DIR, _PC_NAME_MAX);
-	if ((int)max_name == -1) {
-		syslog(LOG_ERR, PATHCONF_ERR,
+	if ((dir = opendir(SYSEVENT_CONFIG_DIR)) == NULL) {
+		syslog(LOG_ERR, CANNOT_OPEN_ERR,
 			SYSEVENT_CONFIG_DIR, strerror(errno));
 		return;
 	}
 
-	dirent_size = sizeof (struct dirent) + (int)max_name + 1;
-	entry = (struct dirent *)sc_malloc(dirent_size);
-	if (entry == NULL)
-		return;
-
-	if ((dir = opendir(SYSEVENT_CONFIG_DIR)) == NULL) {
-		syslog(LOG_ERR, CANNOT_OPEN_ERR,
-			SYSEVENT_CONFIG_DIR, strerror(errno));
-		sc_free(entry, dirent_size);
-		return;
-	}
-
-	for (;;) {
-		err = readdir_r(dir, entry, &result);
-		if (err != 0) {
-			syslog(LOG_ERR, READDIR_ERR, SYSEVENT_CONFIG_DIR, err);
-			goto err;
-		}
-		if (result == NULL)
-			break;
+	while ((result = readdir(dir)) != NULL) {
 		if (result->d_name[0] == '.')
 			continue;
 
@@ -833,7 +809,6 @@
 		syslog(LOG_ERR, CLOSEDIR_ERR,
 			SYSEVENT_CONFIG_DIR, strerror(errno));
 	}
-	sc_free(entry, dirent_size);
 }
 
 
--- a/usr/src/cmd/tar/tar.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/tar/tar.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1615,7 +1615,7 @@
 	 */
 	if ((split > NAMSIZ) ||
 	    (split == NAMSIZ && strlen(shortname) < NAMSIZ) ||
-	    (split == NAMSIZ && (stbuf.st_mode & S_IFDIR) && !Pflag)) {
+	    (split == NAMSIZ && S_ISDIR(stbuf.st_mode) && !Pflag)) {
 		/*
 		 * Since path is limited to PRESIZ characters, look for the
 		 * last slash within PRESIZ + 1 characters only.
@@ -1636,7 +1636,7 @@
 		 * If the filename is greater than NAMSIZ we can't
 		 * archive the file unless we are using extended headers.
 		 */
-		if ((i > NAMSIZ) || (i == NAMSIZ && (stbuf.st_mode & S_IFDIR) &&
+		if ((i > NAMSIZ) || (i == NAMSIZ && S_ISDIR(stbuf.st_mode) &&
 		    !Pflag)) {
 			/* Determine which (filename or path) is too long. */
 			lastslash = strrchr(longname, '/');
@@ -1654,7 +1654,7 @@
 					(void) strcpy(goodbuf, xhdr_dirname);
 			} else {
 				if ((i > NAMSIZ) || (i == NAMSIZ &&
-				    (stbuf.st_mode & S_IFDIR) && !Pflag))
+				    S_ISDIR(stbuf.st_mode) && !Pflag))
 					(void) fprintf(stderr, gettext(
 					    "tar: %s: filename is greater than "
 					    "%d\n"), lastslash == NULL ?
@@ -5041,7 +5041,7 @@
 {
 	int result = 0;
 
-	if (type & S_IFCHR) {
+	if (S_ISCHR(type)) {
 		struct mtget mtg;
 
 		if (ioctl(fd, MTIOCGET, &mtg) != -1) {
--- a/usr/src/cmd/utmp_update/utmp_update.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/utmp_update/utmp_update.c	Wed Nov 09 11:19:56 2005 -0800
@@ -460,9 +460,9 @@
 
 	/*
 	 * Check that the line refers to a character
-	 * special device see bugid: 1136978
+	 * special device.
 	 */
-	if ((stat(line, &statbuf) < 0) || (statbuf.st_mode & S_IFCHR) == 0) {
+	if ((stat(line, &statbuf) < 0) || !S_ISCHR(statbuf.st_mode)) {
 		dprintf("Bad line (stat failed) (Not S_IFCHR) = %s\n", line);
 		return (1);
 	}
@@ -490,9 +490,9 @@
 
 	/*
 	 * Check that the line refers to a character
-	 * special device see bugid: 1136978
+	 * special device.
 	 */
-	if ((fstat(fd, &statbuf) < 0) || (statbuf.st_mode & S_IFCHR) == 0) {
+	if ((fstat(fd, &statbuf) < 0) || !S_ISCHR(statbuf.st_mode)) {
 		dprintf("Bad line (fstat failed) (Not S_IFCHR) = %s\n", line);
 		(void) close(fd);
 		return (1);
--- a/usr/src/cmd/volmgt/vold/vold_config.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/volmgt/vold/vold_config.c	Wed Nov 09 11:19:56 2005 -0800
@@ -506,7 +506,7 @@
 		return (FALSE);
 	}
 
-	if (!(S_IFREG & sb.st_mode)) {
+	if (!S_ISREG(sb.st_mode)) {
 		warning(gettext(
 		    "config file (%s) line %d: %s not a regular file\n"),
 		    vold_config, ln, pname);
--- a/usr/src/cmd/volmgt/vold/vold_main.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/volmgt/vold/vold_main.c	Wed Nov 09 11:19:56 2005 -0800
@@ -425,7 +425,7 @@
 				fatal("can't stat \"%s\"; %m\n", vold_root);
 				/*NOTREACHED*/
 			}
-		} else if (!(sb.st_mode & S_IFDIR)) {
+		} else if (!S_ISDIR(sb.st_mode)) {
 			/* ...and that it's a directory. */
 			fatal(gettext("\"%s\" is not a directory\n"),
 			    vold_root);
--- a/usr/src/cmd/xntpd/xntpd/ntp_filegen.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/xntpd/xntpd/ntp_filegen.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1996,1999 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
  */
 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
@@ -172,7 +172,7 @@
 		static u_long conflicts = 0;
 
 #ifndef	S_ISREG
-#define	S_ISREG(mode)	(((mode) & S_IFREG) == S_IFREG)
+#define	S_ISREG(mode)	(((mode) & S_IFMT) == S_IFREG)
 #endif
 		if (stat(basename, &stats) == 0) {
 			/* Hm, file exists... */
--- a/usr/src/cmd/ypcmd/shared/ancil.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/ypcmd/shared/ancil.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -64,7 +64,7 @@
 	strcat(path, domain);
 
 	if (stat(path, &filestat) != -1) {
-		if ((filestat.st_mode & S_IFDIR))
+		if (S_ISDIR(filestat.st_mode))
 				present = TRUE;
 		}
 	return (present);
--- a/usr/src/cmd/zoneadmd/zoneadmd.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/cmd/zoneadmd/zoneadmd.c	Wed Nov 09 11:19:56 2005 -0800
@@ -254,7 +254,7 @@
 		return (-1);
 	}
 	/* paranoia */
-	if ((stat(ZONES_TMPDIR, &st) < 0) || ((st.st_mode & S_IFDIR) == 0)) {
+	if ((stat(ZONES_TMPDIR, &st) < 0) || !S_ISDIR(st.st_mode)) {
 		zerror(zlogp, B_TRUE, "'%s' is not a directory", ZONES_TMPDIR);
 		return (-1);
 	}
--- a/usr/src/common/openssl/apps/ca.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/common/openssl/apps/ca.c	Wed Nov 09 11:19:56 2005 -0800
@@ -839,8 +839,8 @@
 			perror(outdir);
 			goto err;
 			}
-#ifdef S_IFDIR
-		if (!(sb.st_mode & S_IFDIR))
+#ifdef S_ISDIR
+		if (!S_ISDIR(sb.st_mode))
 			{
 			BIO_printf(bio_err,"%s need to be a directory\n",outdir);
 			perror(outdir);
--- a/usr/src/common/openssl/crypto/rand/randfile.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/common/openssl/crypto/rand/randfile.c	Wed Nov 09 11:19:56 2005 -0800
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 
-/* We need to define this to get macros like S_IFBLK and S_IFCHR */
+/* We need to define this to get macros like S_ISBLK and S_ISCHR */
 #ifndef	_BOOT
 #define _XOPEN_SOURCE 1
 #endif	/* _BOOT */
@@ -112,8 +112,8 @@
 
 	in=fopen(file,"rb");
 	if (in == NULL) goto err;
-#if defined(S_IFBLK) && defined(S_IFCHR)
-	if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
+#if defined(S_ISBLK) && defined(S_ISCHR)
+	if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) {
 	  /* this file is a device. we don't want read an infinite number
 	   * of bytes from a random device, nor do we want to use buffered
 	   * I/O because we will waste system entropy. 
@@ -155,8 +155,8 @@
 	
 	i=stat(file,&sb);
 	if (i != -1) { 
-#if defined(S_IFBLK) && defined(S_IFCHR)
-	  if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
+#if defined(S_ISBLK) && defined(S_ISCHR)
+	  if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) {
 	    /* this file is a device. we don't write back to it. 
 	     * we "succeed" on the assumption this is some sort 
 	     * of random device. Otherwise attempting to write to 
--- a/usr/src/lib/fm/libfmd_log/common/fmd_log.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/fm/libfmd_log/common/fmd_log.c	Wed Nov 09 11:19:56 2005 -0800
@@ -38,11 +38,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <libgen.h>
-
-#define	_POSIX_PTHREAD_SEMANTICS
 #include <dirent.h>
-#undef	_POSIX_PTHREAD_SEMANTICS
-
 #include <fmd_log_impl.h>
 #include <fmd_log.h>
 
@@ -273,7 +269,7 @@
 {
 	fmd_log_t *xlp;
 	char dirbuf[PATH_MAX], path[PATH_MAX], *dirpath;
-	struct dirent *dp, *ep;
+	struct dirent *dp;
 	DIR *dirp;
 
 	lp->log_flags |= FMD_LF_XREFS;
@@ -283,10 +279,7 @@
 	if ((dirp = opendir(dirpath)) == NULL)
 		return; /* failed to open directory; just skip it */
 
-	ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
-	bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
-
-	while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) {
+	while ((dp = readdir(dirp)) != NULL) {
 		if (dp->d_name[0] == '.')
 			continue; /* skip "." and ".." and hidden files */
 
--- a/usr/src/lib/libdevinfo/devinfo_devlink.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdevinfo/devinfo_devlink.c	Wed Nov 09 11:19:56 2005 -0800
@@ -2405,7 +2405,7 @@
 	struct stat sbuf;
 	char cur[PATH_MAX], *cp;
 	int i, rv = DI_WALK_CONTINUE;
-	struct dirent *entp, *result;
+	struct dirent *entp;
 
 
 	if ((rel = rel_path(hdp, dir)) == NULL)
@@ -2427,23 +2427,12 @@
 	if ((dp = opendir(dir)) == NULL)
 		return (DI_WALK_CONTINUE);
 
-	entp = malloc(sizeof (struct dirent) + PATH_MAX + 1);
-	if (entp == NULL) {
-		SET_DB_ERR(hdp);
-		(void) closedir(dp);
-		*retp = -1;
-		return (DI_WALK_TERMINATE);
-	}
-
 	(void) snprintf(cur, sizeof (cur), "%s/", dir);
 	len = strlen(cur);
 	cp = cur + len;
 	len = sizeof (cur) - len;
 
-	while (readdir_r(dp, entp, &result) == 0) {
-
-		if (result == NULL)
-			break;
+	while ((entp = readdir(dp)) != NULL) {
 
 		if (strcmp(entp->d_name, ".") == 0 ||
 		    strcmp(entp->d_name, "..") == 0) {
@@ -2486,7 +2475,6 @@
 			break;
 	}
 
-	free(entp);
 	(void) closedir(dp);
 
 	return (rv);
--- a/usr/src/lib/libdevinfo/devinfo_devperm.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdevinfo/devinfo_devperm.c	Wed Nov 09 11:19:56 2005 -0800
@@ -26,7 +26,7 @@
 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
 
-#define	_POSIX_PTHREAD_SEMANTICS	/* for readdir_r */
+#define	_POSIX_PTHREAD_SEMANTICS	/* for getgrnam_r */
 #ifdef lint
 #define	_REENTRANT			/* for strtok_r */
 #endif
@@ -39,7 +39,6 @@
 #include <errno.h>
 #include <grp.h>
 #include <pwd.h>
-#include <alloca.h>
 #include <nss_dbdefs.h>
 #include <stdarg.h>
 #include <syslog.h>
@@ -375,7 +374,7 @@
 	struct stat stat_buf;
 	int err = 0;
 	DIR *dirp;
-	struct dirent *direntp, *result;
+	struct dirent *direntp;
 
 	/* path must be a valid name */
 	if (stat(path, &stat_buf) == -1) {
@@ -433,11 +432,7 @@
 			}
 		}
 
-		direntp = alloca(sizeof (struct dirent) + MAXPATHLEN);
-		while (readdir_r(dirp, direntp, &result) == 0) {
-			if (result == NULL)
-				break;
-
+		while ((direntp = readdir(dirp)) != NULL) {
 			name = direntp->d_name;
 			if ((strcmp(name, ".") == 0) ||
 			    (strcmp(name, "..") == 0))
--- a/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,8 +20,8 @@
  * CDDL HEADER END
  */
 /*
- * Copyright (c) 2000 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
  */
 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
@@ -1104,8 +1104,7 @@
 list_dn(const char *location, char ***listppp, uint_t *countp)
 {
 	char		ipaddr[INET_ADDRSTRLEN];
-	uint64_t	direntbuf[(MAXPATHLEN + sizeof (struct dirent)) / 8];
-	struct dirent	*result, *dirent = (struct dirent *)&direntbuf;
+	struct dirent	*result;
 	DIR		*dirp;
 	unsigned int	i, count = 0;
 	char		*re, **new_listpp, **listpp = NULL;
@@ -1137,14 +1136,7 @@
 	if (re == NULL)
 		return (DSVC_NO_MEMORY);
 
-	for (;;) {
-		/*
-		 * readdir_r() is very broken; see 4329196 -- in the
-		 * meantime, workaround as best we can.
-		 */
-		error = readdir_r(dirp, dirent, &result);
-		if (error != 0 || result == NULL)
-			break;
+	while ((result = readdir(dirp)) != NULL) {
 
 		if (regex(re, result->d_name, conver, ipaddr) != NULL) {
 			if (atoi(conver) != DSVC_CONVER)
--- a/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,8 +20,8 @@
  * CDDL HEADER END
  */
 /*
- * Copyright (c) 2000 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
  */
 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
@@ -630,8 +630,7 @@
 list_dn(const char *location, char ***listppp, uint_t *countp)
 {
 	char		ipaddr[INET_ADDRSTRLEN];
-	uint64_t	direntbuf[(MAXPATHLEN + sizeof (struct dirent)) / 8];
-	struct dirent	*result, *dirent = (struct dirent *)&direntbuf;
+	struct dirent	*result;
 	DIR		*dirp;
 	unsigned int	i, count = 0;
 	char		*re, **new_listpp, **listpp = NULL;
@@ -663,15 +662,7 @@
 	if (re == NULL)
 		return (DSVC_NO_MEMORY);
 
-	for (;;) {
-		/*
-		 * readdir_r() is very broken; see 4329196 -- in the
-		 * meantime, workaround as best we can.
-		 */
-		error = readdir_r(dirp, dirent, &result);
-		if (error != 0 || result == NULL)
-			break;
-
+	while ((result = readdir(dirp)) != NULL) {
 		if (regex(re, result->d_name, conver, ipaddr) != NULL) {
 			if (atoi(conver) != DSVC_CONVER)
 				continue;
--- a/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c	Wed Nov 09 11:19:56 2005 -0800
@@ -20,8 +20,8 @@
  * CDDL HEADER END
  */
 /*
- * Copyright (c) 2000-2001 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
  */
 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
@@ -533,8 +533,7 @@
 list_dn(const char *location, char ***listppp, uint_t *countp)
 {
 	char		ipaddr[INET_ADDRSTRLEN];
-	uint64_t	direntbuf[(MAXPATHLEN + sizeof (struct dirent)) / 8];
-	struct dirent	*result, *dirent = (struct dirent *)&direntbuf;
+	struct dirent	*result;
 	DIR		*dirp;
 	unsigned int	i, count = 0;
 	char		*re, **new_listpp, **listpp = NULL;
@@ -563,15 +562,7 @@
 	if (re == NULL)
 		return (DSVC_NO_MEMORY);
 
-	for (;;) {
-		/*
-		 * readdir_r() is very broken; see 4329196 -- in the
-		 * meantime, workaround as best we can.
-		 */
-		error = readdir_r(dirp, dirent, &result);
-		if (error != 0 || result == NULL)
-			break;
-
+	while ((result = readdir(dirp)) != NULL) {
 		if (regex(re, result->d_name, ipaddr) != NULL) {
 			new_listpp = realloc(listpp,
 			    (sizeof (char **)) * (count + 1));
--- a/usr/src/lib/libdiskmgt/common/drive.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdiskmgt/common/drive.c	Wed Nov 09 11:19:56 2005 -0800
@@ -658,21 +658,18 @@
 		return (-1);
 	    }
 
-	    if (buf.st_mode & S_IFCHR) {
+	    if (S_ISCHR(buf.st_mode)) {
 		/* opened, is device, so done */
 		if (opath != NULL) {
 		    (void) strlcpy(opath, rmmedia_devpath, len);
 		}
 		return (fd);
 
-	    } else if (buf.st_mode & S_IFDIR) {
+	    } else if (S_ISDIR(buf.st_mode)) {
 		/* disk w/ slices so handle the directory */
 		DIR		*dirp;
 		struct dirent	*dentp;
 		int		dfd;
-#ifdef _LP64
-		struct  dirent *result;
-#endif
 
 		/* each device file in the dir represents a slice */
 
@@ -681,17 +678,7 @@
 		    return (-1);
 		}
 
-		if ((dentp = (struct dirent *)malloc(sizeof (struct dirent) +
-		    PATH_MAX + 1)) == NULL) {
-		    /* out of memory */
-		    (void) close(fd);
-		    return (-1);
-		}
-#ifdef _LP64
-		while (readdir_r(dirp, dentp, &result) != NULL) {
-#else
-		while (readdir_r(dirp, dentp) != NULL) {
-#endif
+		while ((dentp = readdir(dirp)) != NULL) {
 		    char	slice_path[MAXPATHLEN];
 
 		    if (libdiskmgt_str_eq(".", dentp->d_name) ||
@@ -706,10 +693,9 @@
 			continue;
 		    }
 
-		    if (fstat(dfd, &buf) == 0 && (buf.st_mode & S_IFCHR)) {
+		    if (fstat(dfd, &buf) == 0 && S_ISCHR(buf.st_mode)) {
 			/* opened, is device, so done */
-			free(dentp);
-			(void) close(fd);
+			(void) closedir(dirp);
 			if (opath != NULL) {
 			    (void) strlcpy(opath, slice_path, len);
 			}
@@ -721,11 +707,12 @@
 		}
 
 		/* did not find a device under the rmmedia_path */
-		free(dentp);
-		(void) close(fd);
+		(void) closedir(dirp);
+		return (-1);
 	    }
 
 	    /* didn't find a device under volume management control */
+	    (void) close(fd);
 	    return (-1);
 	}
 
--- a/usr/src/lib/libdiskmgt/common/inuse_fs.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdiskmgt/common/inuse_fs.c	Wed Nov 09 11:19:56 2005 -0800
@@ -210,7 +210,7 @@
 		(void) snprintf(path, sizeof (path), "/usr/lib/fs/%s",
 		    dp->d_name);
 
-		if (stat(path, &buf) != 0 || !(buf.st_mode & S_IFDIR)) {
+		if (stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
 		    continue;
 		}
 
@@ -226,7 +226,7 @@
 				"/usr/lib/fs/%s/fstyp", dp->d_name);
 
 			    if (stat(progpath, &buf) == 0 &&
-				buf.st_mode & S_IFREG) {
+				S_ISREG(buf.st_mode)) {
 
 				struct heuristic *hp;
 
--- a/usr/src/lib/libdiskmgt/common/partition.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdiskmgt/common/partition.c	Wed Nov 09 11:19:56 2005 -0800
@@ -626,21 +626,18 @@
 		return (-1);
 	    }
 
-	    if (buf.st_mode & S_IFCHR) {
+	    if (S_ISCHR(buf.st_mode)) {
 		/* opened, is device, so done */
 		if (opath != NULL) {
 		    (void) strlcpy(opath, rmmedia_devpath, len);
 		}
 		return (fd);
 
-	    } else if (buf.st_mode & S_IFDIR) {
+	    } else if (S_ISDIR(buf.st_mode)) {
 		/* disk w/ slices so handle the directory */
 		DIR		*dirp;
 		struct dirent	*dentp;
 		int		dfd;
-#ifdef _LP64
-		struct dirent	*result;
-#endif
 
 		/* each device file in the dir represents a slice */
 
@@ -649,17 +646,7 @@
 		    return (-1);
 		}
 
-		if ((dentp = (struct dirent *)malloc(sizeof (struct dirent) +
-		    PATH_MAX + 1)) == NULL) {
-		    /* out of memory */
-		    (void) close(fd);
-		    return (-1);
-		}
-#ifdef _LP64
-		while (readdir_r(dirp, dentp, &result) != NULL) {
-#else
-		while (readdir_r(dirp, dentp) != NULL) {
-#endif
+		while ((dentp = readdir(dirp)) != NULL) {
 		    char	slice_path[MAXPATHLEN];
 
 		    if (libdiskmgt_str_eq(".", dentp->d_name) ||
@@ -674,10 +661,9 @@
 			continue;
 		    }
 
-		    if (fstat(dfd, &buf) == 0 && (buf.st_mode & S_IFCHR)) {
+		    if (fstat(dfd, &buf) == 0 && S_ISCHR(buf.st_mode)) {
 			/* opened, is device, so done */
-			free(dentp);
-			(void) close(fd);
+			(void) closedir(dirp);
 			if (opath != NULL) {
 			    (void) strlcpy(opath, slice_path, len);
 			}
@@ -689,11 +675,12 @@
 		}
 
 		/* did not find a device under the rmmedia_path */
-		free(dentp);
-		(void) close(fd);
+		(void) closedir(dirp);
+		return (-1);
 	    }
 
 	    /* didn't find a device under volume management control */
+	    (void) close(fd);
 	    return (-1);
 	}
 
--- a/usr/src/lib/libdiskmgt/common/slice.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdiskmgt/common/slice.c	Wed Nov 09 11:19:56 2005 -0800
@@ -766,10 +766,10 @@
 
 	/* get the media name from the descriptor */
 	if (desc->type == DM_MEDIA) {
-	    media_name = desc->name;
+		media_name = desc->name;
 	} else {
-	    /* must be a DM_PARTITION */
-	    media_name = desc->secondary_name;
+		/* must be a DM_PARTITION */
+		media_name = desc->secondary_name;
 	}
 
 	/*
@@ -781,113 +781,104 @@
 
 	if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) < 0 ||
 	    fstat(fd, &buf) != 0) {
-	    *errp = ENODEV;
-	    return (NULL);
+		*errp = ENODEV;
+		return (NULL);
 	}
 
 	cnt = num_removable_slices(fd, &buf, volm_path);
 
 	/* allocate the array for the descriptors */
-	slices = (descriptor_t **)calloc(cnt + 1, sizeof (descriptor_t *));
+	slices = calloc(cnt + 1, sizeof (descriptor_t *));
 	if (slices == NULL) {
-	    *errp = ENOMEM;
-	    return (NULL);
+		*errp = ENOMEM;
+		return (NULL);
 	}
 
 	slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
 
 	pos = 0;
 	*errp = 0;
-	if (buf.st_mode & S_IFCHR) {
-	    struct dk_minfo	minfo;
+	if (S_ISCHR(buf.st_mode)) {
+		struct dk_minfo	minfo;
+
+		/* Make sure media has readable label */
+		if (media_read_info(fd, &minfo)) {
+			int		status;
+			int		data_format = FMT_UNKNOWN;
+			struct vtoc	vtoc;
+			struct dk_gpt	*efip;
+
+			if ((status = read_vtoc(fd, &vtoc)) >= 0) {
+				data_format = FMT_VTOC;
+			} else if (status == VT_ENOTSUP &&
+			    efi_alloc_and_read(fd, &efip) >= 0) {
+				data_format = FMT_EFI;
+			}
 
-	    /* Make sure media has readable label */
-	    if (media_read_info(fd, &minfo)) {
-		int		status;
-		int		data_format = FMT_UNKNOWN;
-		struct vtoc	vtoc;
-		struct dk_gpt	*efip;
+			if (data_format != FMT_UNKNOWN) {
+			    /* has a readable label */
+				slices[pos++] =
+				    cache_get_desc(DM_SLICE, desc->p.disk,
+				    devpath, media_name, errp);
+			}
+		}
+		(void) close(fd);
+	} else if (S_ISDIR(buf.st_mode)) {
+		DIR		*dirp;
+		struct dirent	*dentp;
 
-		if ((status = read_vtoc(fd, &vtoc)) >= 0) {
-		    data_format = FMT_VTOC;
-		} else if (status == VT_ENOTSUP &&
-		    efi_alloc_and_read(fd, &efip) >= 0) {
-		    data_format = FMT_EFI;
+		/* rewind, num_removable_slices already traversed */
+		(void) lseek(fd, 0, SEEK_SET);
+
+		if ((dirp = fdopendir(fd)) == NULL) {
+			*errp = errno;
+			(void) close(fd);
+			return (NULL);
 		}
 
-		if (data_format != FMT_UNKNOWN) {
-		    /* has a readable label */
-		    slices[pos++] = cache_get_desc(DM_SLICE, desc->p.disk,
-			devpath, media_name, errp);
-		}
-	    }
-
-	} else if (buf.st_mode & S_IFDIR) {
-	    DIR			*dirp;
-#ifdef _LP64
-	    struct dirent 	*result;
-#endif
-
-	    /* rewind, num_removable_slices already traversed */
-	    (void) lseek(fd, 0, SEEK_SET);
-
-	    if ((dirp = fdopendir(fd)) != NULL) {
-		struct dirent	*dentp;
-
-		dentp = (struct dirent *)malloc(sizeof (struct dirent) +
-		    PATH_MAX + 1);
-		if (dentp != NULL) {
-#ifdef _LP64
-		    while (readdir_r(dirp, dentp, &result) != NULL) {
-#else
-		    while (readdir_r(dirp, dentp) != NULL) {
-#endif
+		while ((dentp = readdir(dirp)) != NULL) {
 			int	dfd;
 			int	is_dev = 0;
 			char	slice_path[MAXPATHLEN];
 
 			if (libdiskmgt_str_eq(".", dentp->d_name) ||
 			    libdiskmgt_str_eq("..", dentp->d_name)) {
-			    continue;
+				continue;
 			}
 
 			(void) snprintf(slice_path, sizeof (slice_path),
 			    "%s/%s", devpath, dentp->d_name);
 
 			if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) {
-			    struct stat	buf;
+				struct stat	buf;
 
-			    if (fstat(dfd, &buf) == 0 &&
-				buf.st_mode & S_IFCHR) {
-				is_dev = 1;
-			    }
-			    (void) close(dfd);
+				if (fstat(dfd, &buf) == 0 &&
+				    S_ISCHR(buf.st_mode)) {
+					is_dev = 1;
+				}
+				(void) close(dfd);
 			}
 
 			if (!is_dev) {
-			    continue;
+				continue;
 			}
 
 			slices[pos++] = cache_get_desc(DM_SLICE, desc->p.disk,
 			    slice_path, media_name, errp);
 			if (*errp != 0) {
-			    break;
+				break;
 			}
-
-		    }
-		    free(dentp);
 		}
-		/* don't call closedir since it closes the fd */
-	    }
+		(void) closedir(dirp);
+	} else {
+		(void) close(fd);
 	}
 
-	(void) close(fd);
-
 	slices[pos] = NULL;
 
 	if (*errp != 0) {
-	    cache_free_descriptors(slices);
-	    return (NULL);
+		cache_free_descriptors(slices);
+		return (NULL);
 	}
 
 	return (slices);
@@ -1023,7 +1014,7 @@
 	    struct stat	buf;
 
 	    if (fstat(fd, &buf) == 0) {
-		if (buf.st_mode & S_IFCHR) {
+		if (S_ISCHR(buf.st_mode)) {
 		    int			status;
 		    int			data_format = FMT_UNKNOWN;
 		    struct dk_minfo	minfo;
@@ -1054,7 +1045,7 @@
 		    /* The media name is the volm_path in this case. */
 		    cache_load_desc(DM_SLICE, dp, devpath, volm_path, &error);
 
-		} else if (buf.st_mode & S_IFDIR) {
+		} else if (S_ISDIR(buf.st_mode)) {
 		    /* each device file in the dir represents a slice */
 		    error = make_volm_dir_descriptors(dp, fd, volm_path);
 		}
@@ -1076,56 +1067,48 @@
 	int		error;
 	DIR		*dirp;
 	struct dirent	*dentp;
-#ifdef _LP64
-	struct dirent	*result;
-#endif
 	char		devpath[MAXPATHLEN];
 
+	dirfd = dup(dirfd);
+	if (dirfd < 0)
+		return (0);
 	if ((dirp = fdopendir(dirfd)) == NULL) {
-	    return (0);
+		(void) close(dirfd);
+		return (0);
 	}
 
 	slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
 
 	error = 0;
-	dentp = (struct dirent *)malloc(sizeof (struct dirent) +
-	    PATH_MAX + 1);
-	if (dentp != NULL) {
-#ifdef _LP64
-	    while (readdir_r(dirp, dentp, &result) != NULL) {
-#else
-	    while (readdir_r(dirp, dentp) != NULL) {
-#endif
+	while ((dentp = readdir(dirp)) != NULL) {
 		int	fd;
 		char	slice_path[MAXPATHLEN];
 
 		if (libdiskmgt_str_eq(".", dentp->d_name) ||
 		    libdiskmgt_str_eq("..", dentp->d_name)) {
-		    continue;
+			continue;
 		}
 
 		(void) snprintf(slice_path, sizeof (slice_path), "%s/%s",
 		    devpath, dentp->d_name);
 
 		if ((fd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) {
-		    struct stat	buf;
+			struct stat	buf;
 
-		    if (fstat(fd, &buf) == 0 && buf.st_mode & S_IFCHR) {
 			/* The media name is the volm_path in this case. */
-			cache_load_desc(DM_SLICE, dp, slice_path, volm_path,
-			    &error);
-			if (error != 0) {
-			    (void) close(fd);
-			    break;
+			if (fstat(fd, &buf) == 0 && S_ISCHR(buf.st_mode)) {
+				cache_load_desc(DM_SLICE, dp, slice_path,
+				    volm_path, &error);
+				if (error != 0) {
+					(void) close(fd);
+					break;
+				}
 			}
-		    }
 
-		    (void) close(fd);
+			(void) close(fd);
 		}
-	    }
-	    free(dentp);
 	}
-	/* don't call closedir since it closes the fd */
+	(void) closedir(dirp);
 
 	return (error);
 }
@@ -1255,82 +1238,75 @@
 
 	*errp = 0;
 
+	if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) == -1 ||
+	    fstat(fd, &buf) != 0) {
+		return (0);
+	}
+
 	found = 0;
-	if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) >= 0 &&
-	    fstat(fd, &buf) == 0) {
 
-	    if (buf.st_mode & S_IFCHR) {
+	if (S_ISCHR(buf.st_mode)) {
 		char	devpath[MAXPATHLEN];
 
 		slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
 		if (libdiskmgt_str_eq(name, devpath)) {
-		    found = 1;
+			found = 1;
 		}
-
-	    } else if (buf.st_mode & S_IFDIR) {
+		(void) close(fd);
+		return (found);
+	} else if (S_ISDIR(buf.st_mode)) {
 		/* each device file in the dir represents a slice */
 		DIR		*dirp;
+		struct dirent	*dentp;
+		char		devpath[MAXPATHLEN];
 
-		if ((dirp = fdopendir(fd)) != NULL) {
-		    struct dirent	*dentp;
-#ifdef _LP64
-		    struct dirent	*result;
-#endif
-		    char		devpath[MAXPATHLEN];
+		if ((dirp = fdopendir(fd)) == NULL) {
+			(void) close(fd);
+			return (0);
+		}
 
-		    slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
+		slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
 
-		    dentp = (struct dirent *)malloc(sizeof (struct dirent) +
-			PATH_MAX + 1);
-		    if (dentp != NULL) {
-#ifdef _LP64
-			while (readdir_r(dirp, dentp, &result) != NULL) {
-#else
-			while (readdir_r(dirp, dentp) != NULL) {
-#endif
-			    char	slice_path[MAXPATHLEN];
+		while ((dentp = readdir(dirp)) != NULL) {
+			char	slice_path[MAXPATHLEN];
 
-			    if (libdiskmgt_str_eq(".", dentp->d_name) ||
-				libdiskmgt_str_eq("..", dentp->d_name)) {
+			if (libdiskmgt_str_eq(".", dentp->d_name) ||
+			    libdiskmgt_str_eq("..", dentp->d_name)) {
 				continue;
-			    }
+			}
 
-			    (void) snprintf(slice_path, sizeof (slice_path),
-				"%s/%s", devpath, dentp->d_name);
+			(void) snprintf(slice_path, sizeof (slice_path),
+			    "%s/%s", devpath, dentp->d_name);
 
-			    if (libdiskmgt_str_eq(name, slice_path)) {
+			if (libdiskmgt_str_eq(name, slice_path)) {
 				/* found name, check device */
 				int	dfd;
 				int	is_dev = 0;
 
-				if ((dfd = open(slice_path, O_RDONLY|O_NDELAY))
-				    >= 0) {
-				    struct stat	buf;
+				dfd = open(slice_path, O_RDONLY|O_NDELAY);
+				if (dfd >= 0) {
+					struct stat	buf;
 
-				    if (fstat(dfd, &buf) == 0 &&
-					buf.st_mode & S_IFCHR) {
-					is_dev = 1;
-				    }
-				    (void) close(dfd);
+					if (fstat(dfd, &buf) == 0 &&
+					    S_ISCHR(buf.st_mode)) {
+						is_dev = 1;
+					}
+					(void) close(dfd);
 				}
 
 				/* we found the name */
 				found = 1;
 
 				if (!is_dev) {
-				    *errp = ENODEV;
+					*errp = ENODEV;
 				}
 
 				break;
-			    }
 			}
-			free(dentp);
-		    }
-		    /* don't call closedir since it closes the fd */
 		}
-	    } /* end of dir handling */
-
-	    (void) close(fd);
+		(void) closedir(dirp);
+	} else {
+		(void) close(fd);
 	}
 
 	return (found);
@@ -1341,56 +1317,50 @@
 {
 	int cnt = 0;
 
-	if (bufp->st_mode & S_IFCHR) {
-	    cnt = 1;
+	if (S_ISCHR(bufp->st_mode))
+		return (1);
 
-	} else if (bufp->st_mode & S_IFDIR) {
-	    /* each device file in the dir represents a slice */
-	    DIR		*dirp;
+	if (S_ISDIR(bufp->st_mode)) {
+		/* each device file in the dir represents a slice */
+		DIR		*dirp;
+		struct dirent	*dentp;
+		char		devpath[MAXPATHLEN];
 
-	    if ((dirp = fdopendir(fd)) != NULL) {
-		struct dirent	*dentp;
-#ifdef _LP64
-		struct dirent	*result;
-#endif
-		char		devpath[MAXPATHLEN];
+		fd = dup(fd);
+
+		if (fd < 0)
+			return (0);
+
+		if ((dirp = fdopendir(fd)) == NULL) {
+			(void) close(fd);
+			return (0);
+		}
 
 		slice_rdsk2dsk(volm_path, devpath, sizeof (devpath));
 
-		dentp = (struct dirent *)malloc(sizeof (struct dirent) +
-		    PATH_MAX + 1);
-		if (dentp != NULL) {
-#ifdef _LP64
-		    while (readdir_r(dirp, dentp, &result) != NULL) {
-#else
-		    while (readdir_r(dirp, dentp) != NULL) {
-#endif
+		while ((dentp = readdir(dirp)) != NULL) {
 			int	dfd;
 			char	slice_path[MAXPATHLEN];
 
 			if (libdiskmgt_str_eq(".", dentp->d_name) ||
 			    libdiskmgt_str_eq("..", dentp->d_name)) {
-			    continue;
+				continue;
 			}
 
 			(void) snprintf(slice_path, sizeof (slice_path),
 			    "%s/%s", devpath, dentp->d_name);
 
 			if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) {
-			    struct stat	buf;
+				struct stat	buf;
 
-			    if (fstat(dfd, &buf) == 0 &&
-				buf.st_mode & S_IFCHR) {
-				cnt++;
-			    }
-			    (void) close(dfd);
+				if (fstat(dfd, &buf) == 0 &&
+				    S_ISCHR(buf.st_mode)) {
+					cnt++;
+				}
+				(void) close(dfd);
 			}
-		    }
-		    free(dentp);
 		}
-		/* don't call closedir since it closes the fd */
-	    }
-	} /* end of dir handling */
-
+		(void) closedir(dirp);
+	}
 	return (cnt);
 }
--- a/usr/src/lib/libdtrace/common/dt_cc.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdtrace/common/dt_cc.c	Wed Nov 09 11:19:56 2005 -0800
@@ -95,13 +95,8 @@
 #include <errno.h>
 #include <ucontext.h>
 #include <limits.h>
-#include <alloca.h>
 #include <ctype.h>
-
-#define	_POSIX_PTHREAD_SEMANTICS
 #include <dirent.h>
-#undef	_POSIX_PTHREAD_SEMANTICS
-
 #include <dt_module.h>
 #include <dt_program.h>
 #include <dt_provider.h>
@@ -1646,7 +1641,7 @@
 static int
 dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path)
 {
-	struct dirent *dp, *ep;
+	struct dirent *dp;
 	const char *p;
 	DIR *dirp;
 
@@ -1659,10 +1654,7 @@
 		return (0);
 	}
 
-	ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
-	bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
-
-	while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) {
+	while ((dp = readdir(dirp)) != NULL) {
 		if ((p = strrchr(dp->d_name, '.')) == NULL || strcmp(p, ".d"))
 			continue; /* skip any filename not ending in .d */
 
--- a/usr/src/lib/libdtrace/common/dt_module.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libdtrace/common/dt_module.c	Wed Nov 09 11:19:56 2005 -0800
@@ -42,11 +42,7 @@
 #include <limits.h>
 #include <assert.h>
 #include <errno.h>
-#include <alloca.h>
-
-#define	_POSIX_PTHREAD_SEMANTICS
 #include <dirent.h>
-#undef	_POSIX_PTHREAD_SEMANTICS
 
 #include <dt_strtab.h>
 #include <dt_module.h>
@@ -903,12 +899,9 @@
 	 */
 	if (!(dtp->dt_oflags & DTRACE_O_NOSYS) &&
 	    (dirp = opendir(OBJFS_ROOT)) != NULL) {
-		struct dirent *dp, *ep;
+		struct dirent *dp;
 
-		ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
-		bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
-
-		while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) {
+		while ((dp = readdir(dirp)) != NULL) {
 			if (dp->d_name[0] != '.')
 				dt_module_update(dtp, dp->d_name);
 		}
--- a/usr/src/lib/libresolv2/common/bsd/writev.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libresolv2/common/bsd/writev.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -36,7 +36,7 @@
 	/*
 	 * Allow for atomic writes to network.
 	 */
-	if (statbuf.st_mode & S_IFSOCK) {
+	if (S_ISSOCK(statbuf.st_mode)) {
 		struct msghdr   mesg;		
 
 		memset(&mesg, 0, sizeof(mesg));
--- a/usr/src/lib/libresolv2/common/isc/logging.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libresolv2/common/isc/logging.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -121,7 +121,7 @@
 		}
 		regular = 1;
 	} else
-		regular = (sb.st_mode & S_IFREG);
+		regular = S_ISREG(sb.st_mode);
 
 	if (chan->out.file.versions) {
 		if (!regular) {
--- a/usr/src/lib/libsmedia/library/common/l_misc.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libsmedia/library/common/l_misc.c	Wed Nov 09 11:19:56 2005 -0800
@@ -470,7 +470,7 @@
 				clnt_destroy(handle->sm_clnt);
 			return (NULL);
 		}
-		if ((stat.st_mode & S_IFDOOR) != S_IFDOOR) {
+		if (!S_ISDOOR(stat.st_mode)) {
 			DPRINTF(
 		"Descriptor returned by door_call is not of type DOOR\n");
 			(void) dlclose(handle->sm_lib_handle);
--- a/usr/src/lib/libsysevent/libsysevent.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/libsysevent/libsysevent.c	Wed Nov 09 11:19:56 2005 -0800
@@ -1756,7 +1756,7 @@
 		errno = EACCES;
 		return (NULL);
 	} else if (chan_stat.st_uid != getuid() ||
-	    !(chan_stat.st_mode & S_IFDIR)) {
+	    !S_ISDIR(chan_stat.st_mode)) {
 		dprint("sysevent_open_channel: Invalid "
 		    "permissions for channel %s\n: %d:%d:%d", channel_path,
 		    (int)chan_stat.st_uid, (int)chan_stat.st_gid,
--- a/usr/src/lib/lvm/libmeta/common/meta_name.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/lvm/libmeta/common/meta_name.c	Wed Nov 09 11:19:56 2005 -0800
@@ -95,13 +95,13 @@
 			    "line containing device %s\n"), uname);
 			exit(1);
 		}
-		if ((sbuf1.st_mode & S_IFBLK) == 0) {
+		if (!S_ISBLK(sbuf1.st_mode)) {
 			(void) printf(dgettext(TEXT_DOMAIN,
 			    "/etc/vfstab device to mount is not a "
 			    "block device for device %s\n"), uname);
 			exit(1);
 		}
-		if ((sbuf2.st_mode & S_IFCHR) == 0) {
+		if (!S_ISCHR(sbuf2.st_mode)) {
 			(void) printf(dgettext(TEXT_DOMAIN,
 			    "/etc/vfstab device to fsck is not a "
 			    "raw device for device %s\n"), p);
--- a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c	Wed Nov 09 11:19:56 2005 -0800
@@ -835,27 +835,13 @@
 
 static CK_RV
 get_all_objs_in_dir(DIR *dirp, ks_obj_handle_t *ks_handle,
-    ks_obj_t **result_obj_list, boolean_t lock_held, char *dir_name)
+    ks_obj_t **result_obj_list, boolean_t lock_held)
 {
-	struct dirent *dp = NULL, *result = NULL;
+	struct dirent *dp;
 	ks_obj_t *obj;
 	CK_RV rv;
-	long path_limit;
-
-	if ((path_limit = pathconf(dir_name, _PC_NAME_MAX)) == -1) {
-		path_limit = PATH_MAX;
-	}
-
-	dp = malloc(path_limit + 1 + sizeof (struct dirent));
-	if (dp == NULL) {
-		return (CKR_HOST_MEMORY);
-	}
-
-	while (readdir_r(dirp, dp, &result) == 0) {
-		if (result == NULL) {
-			break;
-		}
-
+
+	while ((dp = readdir(dirp)) != NULL) {
 
 		if ((strcmp(dp->d_name, ".") == 0) ||
 		    (strcmp(dp->d_name, "..") == 0)) {
@@ -865,7 +851,6 @@
 		(void) strcpy((char *)ks_handle->name, dp->d_name);
 		rv = soft_keystore_get_single_obj(ks_handle, &obj, lock_held);
 		if (rv != CKR_OK) {
-			free(dp);
 			return (rv);
 		}
 		if (obj != NULL) {
@@ -877,7 +862,6 @@
 			}
 		}
 	}
-	free(dp);
 	return (CKR_OK);
 }
 
@@ -1497,7 +1481,7 @@
 	soft_object_t *new_crypt_key = NULL, *new_hmac_key = NULL;
 	char filebuf[BUFSIZ];
 	DIR	*pri_dirp;
-	struct dirent *pri_ent = NULL, *result = NULL;
+	struct dirent *pri_ent;
 	char pri_obj_path[MAXPATHLEN], ks_desc_file[MAXPATHLEN],
 	    tmp_ks_desc_name[MAXPATHLEN];
 	typedef struct priobjs {
@@ -1741,16 +1725,7 @@
 		}
 	}
 
-	pri_ent = malloc(pathconf(pri_obj_path, _PC_NAME_MAX) + 1
-	    + sizeof (struct dirent));
-	if (pri_ent == NULL) {
-		goto cleanup2;
-	}
-
-	while (readdir_r(pri_dirp, pri_ent, &result) == 0) {
-		if (result == NULL) {
-			break;
-		}
+	while ((pri_ent = readdir(pri_dirp)) != NULL) {
 
 		if ((strcmp(pri_ent->d_name, ".") == 0) ||
 		    (strcmp(pri_ent->d_name, "..") == 0) ||
@@ -1761,7 +1736,6 @@
 
 		obj = malloc(sizeof (priobjs_t));
 		if (obj == NULL) {
-			free(pri_ent);
 			goto cleanup2;
 		}
 		(void) snprintf(obj->orig_name, MAXPATHLEN,
@@ -1771,7 +1745,6 @@
 		    (pri_ent->d_name) + strlen(OBJ_PREFIX));
 		if (reencrypt_obj(new_crypt_key, new_hmac_key,
 		    obj->orig_name, obj->tmp_name) != 0) {
-			free(pri_ent);
 			free(obj);
 			goto cleanup2;
 		}
@@ -1785,7 +1758,6 @@
 			pri_objs = obj;
 		}
 	}
-	free(pri_ent);
 
 	/* rename all the private objects */
 	tmp = pri_objs;
@@ -2007,7 +1979,7 @@
 			return (CKR_FUNCTION_FAILED);
 		}
 		rv = get_all_objs_in_dir(dirp, &ks_handle, result_obj_list,
-		    lock_held, pub_obj_path);
+		    lock_held);
 		if (rv != CKR_OK) {
 			(void) closedir(dirp);
 			goto cleanup;
@@ -2036,7 +2008,7 @@
 			return (CKR_OK);
 		}
 		rv = get_all_objs_in_dir(dirp, &ks_handle, result_obj_list,
-		    lock_held, pri_obj_path);
+		    lock_held);
 		if (rv != CKR_OK) {
 			(void) closedir(dirp);
 			goto cleanup;
--- a/usr/src/tools/cscope-fast/dir.c	Wed Nov 09 11:09:41 2005 -0800
+++ b/usr/src/tools/cscope-fast/dir.c	Wed Nov 09 11:19:56 2005 -0800
@@ -24,8 +24,8 @@
 
 
 /*
- * Copyright (c) 1999 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
  */
 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
@@ -86,7 +86,7 @@
 		 * view path node)
 		 */
 		if (stat(compath(dir), &statstruct) == 0 &&
-		    (statstruct.st_mode & S_IFDIR)) {
+		    S_ISDIR(statstruct.st_mode)) {
 			if (srcdirs == NULL) {
 				srcdirs = mymalloc(msrcdirs * sizeof (char *));
 			} else if (nsrcdirs == msrcdirs) {
@@ -120,7 +120,7 @@
 		 * view path node)
 		 */
 		if (stat(compath(dir), &statstruct) == 0 &&
-		    (statstruct.st_mode & S_IFDIR)) {
+		    S_ISDIR(statstruct.st_mode)) {
 			if (incdirs == NULL) {
 				incdirs = mymalloc(mincdirs * sizeof (char *));
 			} else if (nincdirs == mincdirs) {
@@ -253,7 +253,7 @@
 
 				/* make sure it is a directory */
 				if (stat(compath(dir), &statstruct) == 0 &&
-				    (statstruct.st_mode & S_IFDIR)) {
+				    S_ISDIR(statstruct.st_mode)) {
 					getsrcfiles(dir, s);
 				}
 			}
@@ -330,7 +330,7 @@
 				 * suffixes so make sure it is a file
 				 */
 				if (vpstat(file, &statstruct) == 0 &&
-				    (statstruct.st_mode & S_IFREG)) {
+				    S_ISREG(statstruct.st_mode)) {
 					return (YES);
 				}
 			}