summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorcasper <none@none>2005-11-09 11:19:56 -0800
committercasper <none@none>2005-11-09 11:19:56 -0800
commit4bc0a2ef2b7ba50a7a717e7ddbf31472ad28e358 (patch)
tree8076ef765d7019096fce872c8359a5345dee3160 /usr
parent205d86ae4bc9e661871ff365f59324d8c9b0108a (diff)
downloadillumos-joyent-4bc0a2ef2b7ba50a7a717e7ddbf31472ad28e358.tar.gz
6346636 expunge readdir_r uses from Solaris
6346809 S_IFxxx is not a bitmask but our programmers don't know
Diffstat (limited to 'usr')
-rw-r--r--usr/src/cmd/audio/mixerctl/mixerctl.c6
-rw-r--r--usr/src/cmd/auditreduce/option.c2
-rw-r--r--usr/src/cmd/cat/cat.c5
-rw-r--r--usr/src/cmd/cdrw/device.c4
-rw-r--r--usr/src/cmd/cmd-crypto/decrypt/decrypt.c2
-rw-r--r--usr/src/cmd/cmd-crypto/digest/digest.c2
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/in.ftpd/ftpd.c2
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/in.rarpd.c28
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.c4
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/ipsecconf.c2
-rw-r--r--usr/src/cmd/consadm/consadm.c6
-rw-r--r--usr/src/cmd/cpio/cpio.c4
-rw-r--r--usr/src/cmd/cron/cron.c4
-rw-r--r--usr/src/cmd/devctl/devctl.c2
-rw-r--r--usr/src/cmd/devfsadm/devfsadm.c88
-rw-r--r--usr/src/cmd/devfsadm/devfsadm_impl.h2
-rw-r--r--usr/src/cmd/fm/fmd/common/fmd_asru.c8
-rw-r--r--usr/src/cmd/fm/fmd/common/fmd_module.c7
-rw-r--r--usr/src/cmd/fm/modules/sun4v/etm/etm_xport_api_dd.c2
-rw-r--r--usr/src/cmd/fs.d/nfs/share/issubdir.c2
-rw-r--r--usr/src/cmd/fs.d/nfs/statd/sm_statd.c36
-rw-r--r--usr/src/cmd/fs.d/nfs/statd/sm_svc.c22
-rw-r--r--usr/src/cmd/fs.d/ufs/volcopy/volcopy.c4
-rw-r--r--usr/src/cmd/init/init.c4
-rwxr-xr-xusr/src/cmd/ldap/common/fileurl.c6
-rw-r--r--usr/src/cmd/lp/cmd/lpadmin/chkopts.c3
-rw-r--r--usr/src/cmd/lp/cmd/lpsched/lpfsck.c10
-rw-r--r--usr/src/cmd/lp/cmd/lpsched/ports.c2
-rw-r--r--usr/src/cmd/lp/lib/forms/putform.c4
-rw-r--r--usr/src/cmd/lp/lib/printers/printwheels.c8
-rw-r--r--usr/src/cmd/lp/lib/printers/putprinter.c2
-rw-r--r--usr/src/cmd/pack/pack.c2
-rw-r--r--usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c17
-rw-r--r--usr/src/cmd/rcm_daemon/common/rcm_subr.c15
-rw-r--r--usr/src/cmd/rmformat/rmf_misc.c6
-rw-r--r--usr/src/cmd/sgs/libld/common/map.c6
-rw-r--r--usr/src/cmd/ssh/sftp/sftp-client.c4
-rw-r--r--usr/src/cmd/ssh/sftp/sftp-int.c6
-rw-r--r--usr/src/cmd/sulogin/sulogin.c4
-rw-r--r--usr/src/cmd/swap/swap.c6
-rw-r--r--usr/src/cmd/syseventd/daemons/syseventd/syseventd.c17
-rw-r--r--usr/src/cmd/syseventd/modules/sysevent_conf_mod/sysevent_conf_mod.c29
-rw-r--r--usr/src/cmd/tar/tar.c8
-rw-r--r--usr/src/cmd/utmp_update/utmp_update.c8
-rw-r--r--usr/src/cmd/volmgt/vold/vold_config.c2
-rw-r--r--usr/src/cmd/volmgt/vold/vold_main.c2
-rw-r--r--usr/src/cmd/xntpd/xntpd/ntp_filegen.c6
-rw-r--r--usr/src/cmd/ypcmd/shared/ancil.c4
-rw-r--r--usr/src/cmd/zoneadmd/zoneadmd.c2
-rw-r--r--usr/src/common/openssl/apps/ca.c4
-rw-r--r--usr/src/common/openssl/crypto/rand/randfile.c10
-rw-r--r--usr/src/lib/fm/libfmd_log/common/fmd_log.c11
-rw-r--r--usr/src/lib/libdevinfo/devinfo_devlink.c16
-rw-r--r--usr/src/lib/libdevinfo/devinfo_devperm.c11
-rw-r--r--usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c16
-rw-r--r--usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c17
-rw-r--r--usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c17
-rw-r--r--usr/src/lib/libdiskmgt/common/drive.c29
-rw-r--r--usr/src/lib/libdiskmgt/common/inuse_fs.c4
-rw-r--r--usr/src/lib/libdiskmgt/common/partition.c29
-rw-r--r--usr/src/lib/libdiskmgt/common/slice.c304
-rw-r--r--usr/src/lib/libdtrace/common/dt_cc.c12
-rw-r--r--usr/src/lib/libdtrace/common/dt_module.c11
-rw-r--r--usr/src/lib/libresolv2/common/bsd/writev.c4
-rw-r--r--usr/src/lib/libresolv2/common/isc/logging.c4
-rw-r--r--usr/src/lib/libsmedia/library/common/l_misc.c2
-rw-r--r--usr/src/lib/libsysevent/libsysevent.c2
-rw-r--r--usr/src/lib/lvm/libmeta/common/meta_name.c4
-rw-r--r--usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c42
-rw-r--r--usr/src/tools/cscope-fast/dir.c12
70 files changed, 334 insertions, 654 deletions
diff --git a/usr/src/cmd/audio/mixerctl/mixerctl.c b/usr/src/cmd/audio/mixerctl/mixerctl.c
index 903c016c7f..16509a5b71 100644
--- a/usr/src/cmd/audio/mixerctl/mixerctl.c
+++ b/usr/src/cmd/audio/mixerctl/mixerctl.c
@@ -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 @@ doit(info_t *info, char *dev)
(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);
diff --git a/usr/src/cmd/auditreduce/option.c b/usr/src/cmd/auditreduce/option.c
index 450b0c5add..181a383ad4 100644
--- a/usr/src/cmd/auditreduce/option.c
+++ b/usr/src/cmd/auditreduce/option.c
@@ -887,7 +887,7 @@ proc_file(char *fname, int mode)
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.
diff --git a/usr/src/cmd/cat/cat.c b/usr/src/cmd/cat/cat.c
index 15945776c3..7436e5b53a 100644
--- a/usr/src/cmd/cat/cat.c
+++ b/usr/src/cmd/cat/cat.c
@@ -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 @@ cat(FILE *fi, struct stat *statp, struct stat *outp, char *filenm)
(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 {
diff --git a/usr/src/cmd/cdrw/device.c b/usr/src/cmd/cdrw/device.c
index 0b25702544..208170f057 100644
--- a/usr/src/cmd/cdrw/device.c
+++ b/usr/src/cmd/cdrw/device.c
@@ -324,7 +324,7 @@ vol_name_to_dev_node(char *vname, char *found)
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 @@ lookup_device(char *supplied, char *found)
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);
diff --git a/usr/src/cmd/cmd-crypto/decrypt/decrypt.c b/usr/src/cmd/cmd-crypto/decrypt/decrypt.c
index 8604a74e5a..e5c856387a 100644
--- a/usr/src/cmd/cmd-crypto/decrypt/decrypt.c
+++ b/usr/src/cmd/cmd-crypto/decrypt/decrypt.c
@@ -1161,7 +1161,7 @@ cryptoreadfile(char *filename, CK_BYTE_PTR *pdata, CK_ULONG_PTR pdatalen)
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);
diff --git a/usr/src/cmd/cmd-crypto/digest/digest.c b/usr/src/cmd/cmd-crypto/digest/digest.c
index 2b751f20cc..73b805c812 100644
--- a/usr/src/cmd/cmd-crypto/digest/digest.c
+++ b/usr/src/cmd/cmd-crypto/digest/digest.c
@@ -893,7 +893,7 @@ getkey(char *filename, CK_BYTE_PTR *pkeydata)
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);
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/in.ftpd/ftpd.c b/usr/src/cmd/cmd-inet/usr.sbin/in.ftpd/ftpd.c
index 944bf1269a..df62971088 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/in.ftpd/ftpd.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/in.ftpd/ftpd.c
@@ -3668,7 +3668,7 @@ char *ls_file(const char *file, int nameonly, char remove_path, char classify)
}
#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) {
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/in.rarpd.c b/usr/src/cmd/cmd-inet/usr.sbin/in.rarpd.c
index 2e756c342e..709aa39e03 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/in.rarpd.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/in.rarpd.c
@@ -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 char *cmdname; /* command name from argv[0] */
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 @@ main(int argc, char *argv[])
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 @@ mightboot(ipaddr_t ipa)
char path[MAXPATHL];
DIR *dirp;
struct dirent *dp;
- struct dirent *dentry;
(void) snprintf(path, sizeof (path), "%s/%08X", BOOTDIR, ipa);
@@ -1181,18 +1169,7 @@ mightboot(ipaddr_t ipa)
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 @@ mightboot(ipaddr_t ipa)
}
(void) closedir(dirp);
- (void) free(dentry);
return (dp? 1: 0);
}
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.c b/usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.c
index e85bc168a4..82e6ef8dd2 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.c
@@ -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 @@ lock()
* 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) {
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ipsecconf.c b/usr/src/cmd/cmd-inet/usr.sbin/ipsecconf.c
index 6507162b78..d0b2d12d8d 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/ipsecconf.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ipsecconf.c
@@ -1460,7 +1460,7 @@ lock()
* 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) {
diff --git a/usr/src/cmd/consadm/consadm.c b/usr/src/cmd/consadm/consadm.c
index 3ba3710d3f..d31d7f13d6 100644
--- a/usr/src/cmd/consadm/consadm.c
+++ b/usr/src/cmd/consadm/consadm.c
@@ -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 @@ pathcmp(char *adev, char *bdev)
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)
diff --git a/usr/src/cmd/cpio/cpio.c b/usr/src/cmd/cpio/cpio.c
index 4a8e442dee..4effc75dd6 100644
--- a/usr/src/cmd/cpio/cpio.c
+++ b/usr/src/cmd/cpio/cpio.c
@@ -6474,8 +6474,8 @@ g_init(int *devtype, int *fdes)
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 */
diff --git a/usr/src/cmd/cron/cron.c b/usr/src/cmd/cron/cron.c
index e87df45fef..a127f3800c 100644
--- a/usr/src/cmd/cron/cron.c
+++ b/usr/src/cmd/cron/cron.c
@@ -2376,8 +2376,8 @@ cleanup(struct runinfo *pr, int rc)
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 (;;) {
diff --git a/usr/src/cmd/devctl/devctl.c b/usr/src/cmd/devctl/devctl.c
index 7e52490ab3..5516d51f14 100644
--- a/usr/src/cmd/devctl/devctl.c
+++ b/usr/src/cmd/devctl/devctl.c
@@ -251,7 +251,7 @@ main(int argc, char *argv[])
* 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,
diff --git a/usr/src/cmd/devfsadm/devfsadm.c b/usr/src/cmd/devfsadm/devfsadm.c
index cb04fa24c0..c6d0414f6d 100644
--- a/usr/src/cmd/devfsadm/devfsadm.c
+++ b/usr/src/cmd/devfsadm/devfsadm.c
@@ -2237,8 +2237,7 @@ static void
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 @@ load_modules(void)
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_modules(void)
load_module(entp->d_name, cdir);
}
s_closedir(mod_dir);
- free(entp);
}
}
@@ -3385,7 +3377,7 @@ devfsadm_rm_all(char *file)
devfsadm_rm_work(file, TRUE, TYPE_LINK);
}
-static void
+static int
s_rmdir(char *path)
{
int i;
@@ -3406,12 +3398,13 @@ s_rmdir(char *path)
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 @@ rm_parent_dir_if_empty(char *pathname)
{
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 @@ rm_parent_dir_if_empty(char *pathname)
*ptr = '\0';
- if ((dp = opendir(path)) == NULL) {
- err_print(OPENDIR_FAILED, path, strerror(errno));
- free(entp);
- return;
+ if (s_rmdir(path) == 0) {
+ vprint(REMOVE_MID, "%sremoving empty dir %s\n",
+ fcn, path);
+ continue;
}
-
- 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 */
+ if (errno == EEXIST) {
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 @@ recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd)
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 @@ recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd)
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 @@ recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd)
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 @@ recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd)
regfree(&re1);
out:
- free(entp);
s_closedir(dp);
}
@@ -5286,7 +5248,6 @@ int
get_stat_info(char *namebuf, struct stat *sb)
{
struct dirent *entp;
- struct dirent *retp;
DIR *dp;
char *cp;
@@ -5309,16 +5270,11 @@ get_stat_info(char *namebuf, struct stat *sb)
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 @@ get_stat_info(char *namebuf, struct stat *sb)
(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 @@ enumerate_recurse(char *current_dir, char *path_left, numeral_set_t *setp,
char *new_path;
char *numeral_id;
struct dirent *entp;
- struct dirent *retp;
DIR *dp;
if ((dp = opendir(current_dir)) == NULL) {
@@ -5477,13 +5430,7 @@ enumerate_recurse(char *current_dir, char *path_left, numeral_set_t *setp,
*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 @@ enumerate_recurse(char *current_dir, char *path_left, numeral_set_t *setp,
if (slash != NULL) {
*slash = '/';
}
- free(entp);
s_closedir(dp);
}
diff --git a/usr/src/cmd/devfsadm/devfsadm_impl.h b/usr/src/cmd/devfsadm/devfsadm_impl.h
index 3ea72ca908..d0f5703cf6 100644
--- a/usr/src/cmd/devfsadm/devfsadm_impl.h
+++ b/usr/src/cmd/devfsadm/devfsadm_impl.h
@@ -404,7 +404,7 @@ static void add_link_to_cache(char *devlink, char *physpath);
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);
diff --git a/usr/src/cmd/fm/fmd/common/fmd_asru.c b/usr/src/cmd/fm/fmd/common/fmd_asru.c
index f0ea9fbb37..61992d0001 100644
--- a/usr/src/cmd/fm/fmd/common/fmd_asru.c
+++ b/usr/src/cmd/fm/fmd/common/fmd_asru.c
@@ -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 @@ fmd_asru_hash_logopen(fmd_asru_hash_t *ahp, const char *uuid)
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 @@ fmd_asru_hash_refresh(fmd_asru_hash_t *ahp)
}
(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 ".." */
diff --git a/usr/src/cmd/fm/fmd/common/fmd_module.c b/usr/src/cmd/fm/fmd/common/fmd_module.c
index 1e0177f057..c86337c124 100644
--- a/usr/src/cmd/fm/fmd/common/fmd_module.c
+++ b/usr/src/cmd/fm/fmd/common/fmd_module.c
@@ -1006,17 +1006,14 @@ fmd_modhash_loaddir(fmd_modhash_t *mhp, const char *dir,
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 ".." */
diff --git a/usr/src/cmd/fm/modules/sun4v/etm/etm_xport_api_dd.c b/usr/src/cmd/fm/modules/sun4v/etm/etm_xport_api_dd.c
index ee1de2b83a..e6285cf6d1 100644
--- a/usr/src/cmd/fm/modules/sun4v/etm/etm_xport_api_dd.c
+++ b/usr/src/cmd/fm/modules/sun4v/etm/etm_xport_api_dd.c
@@ -720,7 +720,7 @@ etm_xport_init(fmd_hdl_t *hdl)
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",
diff --git a/usr/src/cmd/fs.d/nfs/share/issubdir.c b/usr/src/cmd/fs.d/nfs/share/issubdir.c
index 41785fefbd..d24a4b89e5 100644
--- a/usr/src/cmd/fs.d/nfs/share/issubdir.c
+++ b/usr/src/cmd/fs.d/nfs/share/issubdir.c
@@ -110,7 +110,7 @@ issubdir(dir1, dir2)
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, '/');
diff --git a/usr/src/cmd/fs.d/nfs/statd/sm_statd.c b/usr/src/cmd/fs.d/nfs/statd/sm_statd.c
index d601fd4f51..b160df420e 100644
--- a/usr/src/cmd/fs.d/nfs/statd/sm_statd.c
+++ b/usr/src/cmd/fs.d/nfs/statd/sm_statd.c
@@ -100,7 +100,7 @@ static char *family2string(sa_family_t family);
void
statd_init()
{
- struct dirent *dirp, *entp;
+ struct dirent *dirp;
DIR *dp;
FILE *fp, *fp_tmp;
int i, tmp_state;
@@ -222,12 +222,7 @@ statd_init()
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 @@ statd_init()
}
}
- free(entp);
(void) closedir(dp);
/* Contact hosts' statd */
@@ -252,7 +246,7 @@ statd_init()
void *
thr_statd_init()
{
- struct dirent *dirp, *entp;
+ struct dirent *dirp;
DIR *dp;
int num_threads;
int num_join;
@@ -266,11 +260,6 @@ thr_statd_init()
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 @@ thr_statd_init()
* 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_statd_init()
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 @@ thr_statd_init()
*/
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 @@ thr_statd_init()
num_threads++;
}
- free(entp);
(void) closedir(dp);
/*
@@ -1132,7 +1117,7 @@ count_symlinks(char *dir, char *name, int *count)
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 @@ count_symlinks(char *dir, char *name, int *count)
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 @@ count_symlinks(char *dir, char *name, int *count)
}
}
- free(entp);
(void) closedir(dp);
if (debug) {
diff --git a/usr/src/cmd/fs.d/nfs/statd/sm_svc.c b/usr/src/cmd/fs.d/nfs/statd/sm_svc.c
index a4699c2d19..f90ec07960 100644
--- a/usr/src/cmd/fs.d/nfs/statd/sm_svc.c
+++ b/usr/src/cmd/fs.d/nfs/statd/sm_svc.c
@@ -297,7 +297,7 @@ remove_dir(path_dir)
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 @@ char *path_dir;
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 @@ char *path_dir;
}
}
- free(entp);
(void) closedir(dp);
return (0);
}
@@ -348,7 +341,7 @@ char *to_dir;
{
int n;
DIR *dp;
- struct dirent *dirp, *entp;
+ struct dirent *dirp;
char rname[MAXNAMELEN + 1];
char path[MAXPATHLEN+MAXNAMELEN+2];
@@ -359,13 +352,7 @@ char *to_dir;
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 @@ char *to_dir;
}
}
- free(entp);
(void) closedir(dp);
}
diff --git a/usr/src/cmd/fs.d/ufs/volcopy/volcopy.c b/usr/src/cmd/fs.d/ufs/volcopy/volcopy.c
index ebba1140cb..318bf8ae6b 100644
--- a/usr/src/cmd/fs.d/ufs/volcopy/volcopy.c
+++ b/usr/src/cmd/fs.d/ufs/volcopy/volcopy.c
@@ -191,8 +191,8 @@ g_init(int *devtype, int *fdes)
*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 */
diff --git a/usr/src/cmd/init/init.c b/usr/src/cmd/init/init.c
index 16d5b81f2f..38c3edd56d 100644
--- a/usr/src/cmd/init/init.c
+++ b/usr/src/cmd/init/init.c
@@ -2832,8 +2832,8 @@ realcon()
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 {
diff --git a/usr/src/cmd/ldap/common/fileurl.c b/usr/src/cmd/ldap/common/fileurl.c
index f944ed4d08..c275f982a8 100755
--- a/usr/src/cmd/ldap/common/fileurl.c
+++ b/usr/src/cmd/ldap/common/fileurl.c
@@ -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 @@ ldaptool_berval_from_ldif_value( const char *value, int vlen,
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 @@ ldaptool_berval_from_ldif_value( const char *value, int vlen,
" -- 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;
diff --git a/usr/src/cmd/lp/cmd/lpadmin/chkopts.c b/usr/src/cmd/lp/cmd/lpadmin/chkopts.c
index 374c0cc223..caf021c84f 100644
--- a/usr/src/cmd/lp/cmd/lpadmin/chkopts.c
+++ b/usr/src/cmd/lp/cmd/lpadmin/chkopts.c
@@ -746,8 +746,7 @@ static int root_can_write (path)
* 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) {
diff --git a/usr/src/cmd/lp/cmd/lpsched/lpfsck.c b/usr/src/cmd/lp/cmd/lpsched/lpfsck.c
index 0fcb973f71..dbcb6766be 100644
--- a/usr/src/cmd/lp/cmd/lpsched/lpfsck.c
+++ b/usr/src/cmd/lp/cmd/lpsched/lpfsck.c
@@ -279,25 +279,27 @@ proto(int type, int rm_ok, ...)
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 @@ proto(int type, int rm_ok, ...)
/*
* 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;
diff --git a/usr/src/cmd/lp/cmd/lpsched/ports.c b/usr/src/cmd/lp/cmd/lpsched/ports.c
index bd1e3490c5..fefe30dce2 100644
--- a/usr/src/cmd/lp/cmd/lpsched/ports.c
+++ b/usr/src/cmd/lp/cmd/lpsched/ports.c
@@ -286,7 +286,7 @@ open_direct(char *ptype, PRINTER *pp)
* 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.
diff --git a/usr/src/cmd/lp/lib/forms/putform.c b/usr/src/cmd/lp/lib/forms/putform.c
index 22f8ebe605..beaff08220 100644
--- a/usr/src/cmd/lp/lib/forms/putform.c
+++ b/usr/src/cmd/lp/lib/forms/putform.c
@@ -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 @@ putform(char *name, FORM *formp, FALERT *alertp, FILE **p_align_fp)
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);
diff --git a/usr/src/cmd/lp/lib/printers/printwheels.c b/usr/src/cmd/lp/lib/printers/printwheels.c
index e739bc9b4e..4ba754be71 100644
--- a/usr/src/cmd/lp/lib/printers/printwheels.c
+++ b/usr/src/cmd/lp/lib/printers/printwheels.c
@@ -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 @@ putpwheel (name, pwheelp)
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);
diff --git a/usr/src/cmd/lp/lib/printers/putprinter.c b/usr/src/cmd/lp/lib/printers/putprinter.c
index 6320cf6357..f7214dfe65 100644
--- a/usr/src/cmd/lp/lib/printers/putprinter.c
+++ b/usr/src/cmd/lp/lib/printers/putprinter.c
@@ -138,7 +138,7 @@ putprinter(char *name, PRINTER *prbufp)
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);
diff --git a/usr/src/cmd/pack/pack.c b/usr/src/cmd/pack/pack.c
index c8aad347b3..9084f2dcf7 100644
--- a/usr/src/cmd/pack/pack.c
+++ b/usr/src/cmd/pack/pack.c
@@ -428,7 +428,7 @@ main(int argc, char *argv[])
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]);
diff --git a/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c b/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c
index e257904683..2adc6a64f3 100644
--- a/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c
+++ b/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c
@@ -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 @@ init_mc(void)
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 @@ extern struct dirent *readdir_r(DIR *__dp, struct dirent *__ent);
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 @@ extern struct dirent *readdir_r(DIR *__dp, struct dirent *__ent);
break;
}
}
- free(entp);
(void) closedir(dirp);
if (!found) {
diff --git a/usr/src/cmd/rcm_daemon/common/rcm_subr.c b/usr/src/cmd/rcm_daemon/common/rcm_subr.c
index 58281c1297..c6e6c52afa 100644
--- a/usr/src/cmd/rcm_daemon/common/rcm_subr.c
+++ b/usr/src/cmd/rcm_daemon/common/rcm_subr.c
@@ -1504,15 +1504,11 @@ rcmd_db_init()
{
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 @@ extern int readdir_r(DIR *, struct dirent *, struct dirent **);
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 @@ extern int readdir_r(DIR *, struct dirent *, struct dirent **);
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 @@ extern int readdir_r(DIR *, struct dirent *, struct dirent **);
(void) closedir(mod_dir);
}
- free(entp);
rcmd_db_print();
}
diff --git a/usr/src/cmd/rmformat/rmf_misc.c b/usr/src/cmd/rmformat/rmf_misc.c
index 77269cc028..4d9a9cc1ac 100644
--- a/usr/src/cmd/rmformat/rmf_misc.c
+++ b/usr/src/cmd/rmformat/rmf_misc.c
@@ -625,7 +625,7 @@ my_open(char *device_name, int32_t flags)
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 @@ lookup_device(char *supplied, char *found)
(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 @@ vol_name_to_dev_node(char *vname, char *found)
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)
diff --git a/usr/src/cmd/sgs/libld/common/map.c b/usr/src/cmd/sgs/libld/common/map.c
index 730a80bb74..9a958369be 100644
--- a/usr/src/cmd/sgs/libld/common/map.c
+++ b/usr/src/cmd/sgs/libld/common/map.c
@@ -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 @@ map_parse(const char *mapfile, Ofl_desc *ofl)
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 @@ map_parse(const char *mapfile, Ofl_desc *ofl)
}
(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);
}
diff --git a/usr/src/cmd/ssh/sftp/sftp-client.c b/usr/src/cmd/ssh/sftp/sftp-client.c
index d3b34489ec..420384476e 100644
--- a/usr/src/cmd/ssh/sftp/sftp-client.c
+++ b/usr/src/cmd/ssh/sftp/sftp-client.c
@@ -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 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
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);
}
diff --git a/usr/src/cmd/ssh/sftp/sftp-int.c b/usr/src/cmd/ssh/sftp/sftp-int.c
index 11df69d04f..8c7d375752 100644
--- a/usr/src/cmd/ssh/sftp/sftp-int.c
+++ b/usr/src/cmd/ssh/sftp/sftp-int.c
@@ -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 @@ is_dir(char *path)
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 @@ remote_is_dir(struct sftp_conn *conn, char *path)
return(0);
if (!(a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS))
return(0);
- return(a->perm & S_IFDIR);
+ return (S_ISDIR(a->perm));
}
static int
diff --git a/usr/src/cmd/sulogin/sulogin.c b/usr/src/cmd/sulogin/sulogin.c
index 077e2f33c7..6a6a581a14 100644
--- a/usr/src/cmd/sulogin/sulogin.c
+++ b/usr/src/cmd/sulogin/sulogin.c
@@ -403,10 +403,10 @@ pathcmp(char *adev, char *bdev)
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)
diff --git a/usr/src/cmd/swap/swap.c b/usr/src/cmd/swap/swap.c
index 3587df15db..4a53a1a14f 100644
--- a/usr/src/cmd/swap/swap.c
+++ b/usr/src/cmd/swap/swap.c
@@ -386,13 +386,15 @@ list(void)
(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 =
diff --git a/usr/src/cmd/syseventd/daemons/syseventd/syseventd.c b/usr/src/cmd/syseventd/daemons/syseventd/syseventd.c
index 38b88a25ec..995ff1048f 100644
--- a/usr/src/cmd/syseventd/daemons/syseventd/syseventd.c
+++ b/usr/src/cmd/syseventd/daemons/syseventd/syseventd.c
@@ -1152,7 +1152,7 @@ load_modules(char *dirname)
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 @@ load_modules(char *dirname)
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 @@ load_modules(char *dirname)
syseventd_print(3, "loaded module %s\n", entp->d_name);
}
- free(entp);
(void) closedir(mod_dir);
syseventd_print(3, "modules loaded\n");
}
diff --git a/usr/src/cmd/syseventd/modules/sysevent_conf_mod/sysevent_conf_mod.c b/usr/src/cmd/syseventd/modules/sysevent_conf_mod/sysevent_conf_mod.c
index 7a1bdb2413..b4b4d56ab1 100644
--- a/usr/src/cmd/syseventd/modules/sysevent_conf_mod/sysevent_conf_mod.c
+++ b/usr/src/cmd/syseventd/modules/sysevent_conf_mod/sysevent_conf_mod.c
@@ -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 @@ build_event_table()
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,
- 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 @@ err:
syslog(LOG_ERR, CLOSEDIR_ERR,
SYSEVENT_CONFIG_DIR, strerror(errno));
}
- sc_free(entry, dirent_size);
}
diff --git a/usr/src/cmd/tar/tar.c b/usr/src/cmd/tar/tar.c
index 66e60e225f..8fc42e7331 100644
--- a/usr/src/cmd/tar/tar.c
+++ b/usr/src/cmd/tar/tar.c
@@ -1615,7 +1615,7 @@ putfile(char *longname, char *shortname, char *parent,
*/
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 @@ putfile(char *longname, char *shortname, char *parent,
* 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 @@ putfile(char *longname, char *shortname, char *parent,
(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 @@ istape(int fd, int type)
{
int result = 0;
- if (type & S_IFCHR) {
+ if (S_ISCHR(type)) {
struct mtget mtg;
if (ioctl(fd, MTIOCGET, &mtg) != -1) {
diff --git a/usr/src/cmd/utmp_update/utmp_update.c b/usr/src/cmd/utmp_update/utmp_update.c
index 20e7c6a694..dc06b55f7e 100644
--- a/usr/src/cmd/utmp_update/utmp_update.c
+++ b/usr/src/cmd/utmp_update/utmp_update.c
@@ -460,9 +460,9 @@ bad_line(char *line)
/*
* 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 @@ bad_line(char *line)
/*
* 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);
diff --git a/usr/src/cmd/volmgt/vold/vold_config.c b/usr/src/cmd/volmgt/vold/vold_config.c
index 193a58c442..989596a969 100644
--- a/usr/src/cmd/volmgt/vold/vold_config.c
+++ b/usr/src/cmd/volmgt/vold/vold_config.c
@@ -506,7 +506,7 @@ conf_action(int argc, char **argv, uint_t ln)
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);
diff --git a/usr/src/cmd/volmgt/vold/vold_main.c b/usr/src/cmd/volmgt/vold/vold_main.c
index c8d010effd..86ace216a7 100644
--- a/usr/src/cmd/volmgt/vold/vold_main.c
+++ b/usr/src/cmd/volmgt/vold/vold_main.c
@@ -425,7 +425,7 @@ main(int argc, char **argv)
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);
diff --git a/usr/src/cmd/xntpd/xntpd/ntp_filegen.c b/usr/src/cmd/xntpd/xntpd/ntp_filegen.c
index fc250f2d1f..fc5a8c51ef 100644
--- a/usr/src/cmd/xntpd/xntpd/ntp_filegen.c
+++ b/usr/src/cmd/xntpd/xntpd/ntp_filegen.c
@@ -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 @@ filegen_open(gen, newid)
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... */
diff --git a/usr/src/cmd/ypcmd/shared/ancil.c b/usr/src/cmd/ypcmd/shared/ancil.c
index bd09a03a70..30787c4ab4 100644
--- a/usr/src/cmd/ypcmd/shared/ancil.c
+++ b/usr/src/cmd/ypcmd/shared/ancil.c
@@ -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 @@ ypcheck_domain(domain)
strcat(path, domain);
if (stat(path, &filestat) != -1) {
- if ((filestat.st_mode & S_IFDIR))
+ if (S_ISDIR(filestat.st_mode))
present = TRUE;
}
return (present);
diff --git a/usr/src/cmd/zoneadmd/zoneadmd.c b/usr/src/cmd/zoneadmd/zoneadmd.c
index 9b2f346883..91ef6539b9 100644
--- a/usr/src/cmd/zoneadmd/zoneadmd.c
+++ b/usr/src/cmd/zoneadmd/zoneadmd.c
@@ -254,7 +254,7 @@ mkzonedir(zlog_t *zlogp)
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);
}
diff --git a/usr/src/common/openssl/apps/ca.c b/usr/src/common/openssl/apps/ca.c
index 92af09716f..b40903e239 100644
--- a/usr/src/common/openssl/apps/ca.c
+++ b/usr/src/common/openssl/apps/ca.c
@@ -839,8 +839,8 @@ bad:
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);
diff --git a/usr/src/common/openssl/crypto/rand/randfile.c b/usr/src/common/openssl/crypto/rand/randfile.c
index f6301ae3a2..44ddf21750 100644
--- a/usr/src/common/openssl/crypto/rand/randfile.c
+++ b/usr/src/common/openssl/crypto/rand/randfile.c
@@ -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 @@ int RAND_load_file(const char *file, long bytes)
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 @@ int RAND_write_file(const char *file)
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
diff --git a/usr/src/lib/fm/libfmd_log/common/fmd_log.c b/usr/src/lib/fm/libfmd_log/common/fmd_log.c
index d47bc241ed..c052587099 100644
--- a/usr/src/lib/fm/libfmd_log/common/fmd_log.c
+++ b/usr/src/lib/fm/libfmd_log/common/fmd_log.c
@@ -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_load_xrdir(fmd_log_t *lp)
{
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 @@ fmd_log_load_xrdir(fmd_log_t *lp)
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 */
diff --git a/usr/src/lib/libdevinfo/devinfo_devlink.c b/usr/src/lib/libdevinfo/devinfo_devlink.c
index f020e8f8a4..5417b88bc3 100644
--- a/usr/src/lib/libdevinfo/devinfo_devlink.c
+++ b/usr/src/lib/libdevinfo/devinfo_devlink.c
@@ -2405,7 +2405,7 @@ do_recurse(
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 @@ do_recurse(
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 @@ next_entry:
break;
}
- free(entp);
(void) closedir(dp);
return (rv);
diff --git a/usr/src/lib/libdevinfo/devinfo_devperm.c b/usr/src/lib/libdevinfo/devinfo_devperm.c
index ef5ca55c48..b89544510a 100644
--- a/usr/src/lib/libdevinfo/devinfo_devperm.c
+++ b/usr/src/lib/libdevinfo/devinfo_devperm.c
@@ -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 @@ dir_dev_acc(char *path, char *left_to_do, uid_t uid, gid_t gid, mode_t mode,
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 @@ dir_dev_acc(char *path, char *left_to_do, uid_t uid, gid_t gid, mode_t mode,
}
}
- 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))
diff --git a/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c b/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c
index e7120da2a9..195c42f56d 100644
--- a/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c
+++ b/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c
@@ -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 @@ int
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 @@ list_dn(const char *location, char ***listppp, uint_t *countp)
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)
diff --git a/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c b/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c
index e62c30f43a..898d2bf01b 100644
--- a/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c
+++ b/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c
@@ -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 @@ int
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 @@ list_dn(const char *location, char ***listppp, uint_t *countp)
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;
diff --git a/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c b/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c
index 1270fbb364..9442c3df6c 100644
--- a/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c
+++ b/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c
@@ -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 @@ int
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 @@ list_dn(const char *location, char ***listppp, uint_t *countp)
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));
diff --git a/usr/src/lib/libdiskmgt/common/drive.c b/usr/src/lib/libdiskmgt/common/drive.c
index aed1db3b59..b3f32c70d6 100644
--- a/usr/src/lib/libdiskmgt/common/drive.c
+++ b/usr/src/lib/libdiskmgt/common/drive.c
@@ -658,21 +658,18 @@ drive_open_disk(disk_t *diskp, char *opath, int len)
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 @@ drive_open_disk(disk_t *diskp, char *opath, int len)
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 @@ drive_open_disk(disk_t *diskp, char *opath, int len)
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 @@ drive_open_disk(disk_t *diskp, char *opath, int len)
}
/* 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);
}
diff --git a/usr/src/lib/libdiskmgt/common/inuse_fs.c b/usr/src/lib/libdiskmgt/common/inuse_fs.c
index c2e751dcb2..1dafdc05e5 100644
--- a/usr/src/lib/libdiskmgt/common/inuse_fs.c
+++ b/usr/src/lib/libdiskmgt/common/inuse_fs.c
@@ -210,7 +210,7 @@ load_heuristics()
(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 @@ load_heuristics()
"/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;
diff --git a/usr/src/lib/libdiskmgt/common/partition.c b/usr/src/lib/libdiskmgt/common/partition.c
index 32141fc8ac..49fa757330 100644
--- a/usr/src/lib/libdiskmgt/common/partition.c
+++ b/usr/src/lib/libdiskmgt/common/partition.c
@@ -626,21 +626,18 @@ open_disk(disk_t *diskp, char *opath, int len)
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 @@ open_disk(disk_t *diskp, char *opath, int len)
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 @@ open_disk(disk_t *diskp, char *opath, int len)
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 @@ open_disk(disk_t *diskp, char *opath, int len)
}
/* 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);
}
diff --git a/usr/src/lib/libdiskmgt/common/slice.c b/usr/src/lib/libdiskmgt/common/slice.c
index c88c0a31c9..33997e1b0c 100644
--- a/usr/src/lib/libdiskmgt/common/slice.c
+++ b/usr/src/lib/libdiskmgt/common/slice.c
@@ -766,10 +766,10 @@ get_removable_assocs(descriptor_t *desc, char *volm_path, int *errp)
/* 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 @@ get_removable_assocs(descriptor_t *desc, char *volm_path, int *errp)
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;
-
- /* 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;
- }
+ if (S_ISCHR(buf.st_mode)) {
+ struct dk_minfo minfo;
- if (data_format != FMT_UNKNOWN) {
- /* has a readable label */
- slices[pos++] = cache_get_desc(DM_SLICE, desc->p.disk,
- devpath, media_name, errp);
- }
- }
+ /* 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;
+ }
- } else if (buf.st_mode & S_IFDIR) {
- DIR *dirp;
-#ifdef _LP64
- struct dirent *result;
-#endif
+ 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;
- /* rewind, num_removable_slices already traversed */
- (void) lseek(fd, 0, SEEK_SET);
+ /* rewind, num_removable_slices already traversed */
+ (void) lseek(fd, 0, SEEK_SET);
- if ((dirp = fdopendir(fd)) != NULL) {
- struct dirent *dentp;
+ if ((dirp = fdopendir(fd)) == NULL) {
+ *errp = errno;
+ (void) close(fd);
+ return (NULL);
+ }
- 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 @@ make_removable_descriptors(disk_t *dp)
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 @@ make_removable_descriptors(disk_t *dp)
/* 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 @@ make_volm_dir_descriptors(disk_t *dp, int dirfd, char *volm_path)
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 @@ match_removable_name(disk_t *diskp, char *name, int *errp)
*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 @@ num_removable_slices(int fd, struct stat *bufp, char *volm_path)
{
int cnt = 0;
- if (bufp->st_mode & S_IFCHR) {
- cnt = 1;
-
- } else if (bufp->st_mode & S_IFDIR) {
- /* each device file in the dir represents a slice */
- DIR *dirp;
+ if (S_ISCHR(bufp->st_mode))
+ return (1);
- if ((dirp = fdopendir(fd)) != NULL) {
+ if (S_ISDIR(bufp->st_mode)) {
+ /* each device file in the dir represents a slice */
+ DIR *dirp;
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);
}
diff --git a/usr/src/lib/libdtrace/common/dt_cc.c b/usr/src/lib/libdtrace/common/dt_cc.c
index 508bbc7389..bd7204101a 100644
--- a/usr/src/lib/libdtrace/common/dt_cc.c
+++ b/usr/src/lib/libdtrace/common/dt_cc.c
@@ -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 @@ err:
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 @@ dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path)
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 */
diff --git a/usr/src/lib/libdtrace/common/dt_module.c b/usr/src/lib/libdtrace/common/dt_module.c
index bd219579c9..46ad7c6529 100644
--- a/usr/src/lib/libdtrace/common/dt_module.c
+++ b/usr/src/lib/libdtrace/common/dt_module.c
@@ -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 @@ dtrace_update(dtrace_hdl_t *dtp)
*/
if (!(dtp->dt_oflags & DTRACE_O_NOSYS) &&
(dirp = opendir(OBJFS_ROOT)) != NULL) {
- struct dirent *dp, *ep;
-
- ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
- bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
+ struct dirent *dp;
- 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);
}
diff --git a/usr/src/lib/libresolv2/common/bsd/writev.c b/usr/src/lib/libresolv2/common/bsd/writev.c
index e3a97a0c39..6e348810ec 100644
--- a/usr/src/lib/libresolv2/common/bsd/writev.c
+++ b/usr/src/lib/libresolv2/common/bsd/writev.c
@@ -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 @@ __writev(int fd, struct iovec *iov, int iovlen)
/*
* 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));
diff --git a/usr/src/lib/libresolv2/common/isc/logging.c b/usr/src/lib/libresolv2/common/isc/logging.c
index 13fc49259d..48ce0859c9 100644
--- a/usr/src/lib/libresolv2/common/isc/logging.c
+++ b/usr/src/lib/libresolv2/common/isc/logging.c
@@ -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 @@ log_open_stream(log_channel chan) {
}
regular = 1;
} else
- regular = (sb.st_mode & S_IFREG);
+ regular = S_ISREG(sb.st_mode);
if (chan->out.file.versions) {
if (!regular) {
diff --git a/usr/src/lib/libsmedia/library/common/l_misc.c b/usr/src/lib/libsmedia/library/common/l_misc.c
index dc6ba063fd..f917e20cea 100644
--- a/usr/src/lib/libsmedia/library/common/l_misc.c
+++ b/usr/src/lib/libsmedia/library/common/l_misc.c
@@ -470,7 +470,7 @@ get_handle_from_fd(int32_t fd)
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);
diff --git a/usr/src/lib/libsysevent/libsysevent.c b/usr/src/lib/libsysevent/libsysevent.c
index 6dff4538df..3dd246babb 100644
--- a/usr/src/lib/libsysevent/libsysevent.c
+++ b/usr/src/lib/libsysevent/libsysevent.c
@@ -1756,7 +1756,7 @@ sysevent_open_channel_common(const char *channel_path)
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,
diff --git a/usr/src/lib/lvm/libmeta/common/meta_name.c b/usr/src/lib/lvm/libmeta/common/meta_name.c
index 7becd6af2f..793d21648a 100644
--- a/usr/src/lib/lvm/libmeta/common/meta_name.c
+++ b/usr/src/lib/lvm/libmeta/common/meta_name.c
@@ -95,13 +95,13 @@ rawname(
"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);
diff --git a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c
index b39e11244b..d67efb6b3d 100644
--- a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c
+++ b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c
@@ -835,27 +835,13 @@ cleanup:
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 @@ get_all_objs_in_dir(DIR *dirp, ks_obj_handle_t *ks_handle,
(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 @@ get_all_objs_in_dir(DIR *dirp, ks_obj_handle_t *ks_handle,
}
}
}
- free(dp);
return (CKR_OK);
}
@@ -1497,7 +1481,7 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held)
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 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held)
}
}
- 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 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held)
obj = malloc(sizeof (priobjs_t));
if (obj == NULL) {
- free(pri_ent);
goto cleanup2;
}
(void) snprintf(obj->orig_name, MAXPATHLEN,
@@ -1771,7 +1745,6 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held)
(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 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held)
pri_objs = obj;
}
}
- free(pri_ent);
/* rename all the private objects */
tmp = pri_objs;
@@ -2007,7 +1979,7 @@ soft_keystore_get_objs(ks_search_type_t search_type,
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 @@ soft_keystore_get_objs(ks_search_type_t search_type,
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;
diff --git a/usr/src/tools/cscope-fast/dir.c b/usr/src/tools/cscope-fast/dir.c
index d1c463293a..8d12ba56c0 100644
--- a/usr/src/tools/cscope-fast/dir.c
+++ b/usr/src/tools/cscope-fast/dir.c
@@ -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 @@ sourcedir(char *dirlist)
* 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 @@ includedir(char *dirlist)
* 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 @@ makefilelist(void)
/* 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 @@ issrcfile(char *file)
* 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);
}
}