rem: _PC_NAME_MAX + 1)) == NULL) {
add: PATH_MAX + 1)) == NULL) {
context: open_disk(disk_t *diskp, char *opath, int len){	char	rmmedia_devpath[MAXPATHLEN];	if (diskp->removable && media_get_volm_path(diskp, rmmedia_devpath,	    sizeof (rmmedia_devpath))) {	    int		fd;	    struct stat	buf;	    if (rmmedia_devpath[0] == 0) {		/* removable but no media */		return (-1);	    }	    if ((fd = open(rmmedia_devpath, O_RDONLY|O_NDELAY)) < 0) {		return (-1);	    }	    if (fstat(fd, &buf) != 0) {		(void) close(fd);		return (-1);	    }	    if (buf.st_mode & S_IFCHR) {		/* opened, is device, so done */		if (opath != NULL) {		    (void) strlcpy(opath, rmmedia_devpath, len);		}		return (fd);	    } else if (buf.st_mode & S_IFDIR) {		/* 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 */		if ((dirp = fdopendir(fd)) == NULL) {		    (void) close(fd);		    return (-1);		}		if ((dentp = (struct dirent *)malloc(sizeof (struct dirent) +		    _PC_NAME_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		    char	slice_path[MAXPATHLEN];		    if (libdiskmgt_str_eq(".", dentp->d_name) ||			libdiskmgt_str_eq("..", dentp->d_name)) {			continue;		    }		    (void) snprintf(slice_path, sizeof (slice_path), "%s/%s",			rmmedia_devpath, dentp->d_name);		    if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) < 0) {			continue;		    }		    if (fstat(dfd, &buf) == 0 && (buf.st_mode & S_IFCHR)) {			/* opened, is device, so done */			free(dentp);			(void) close(fd);			if (opath != NULL) {			    (void) strlcpy(opath, slice_path, len);			}			return (dfd);		    }		    /* not a device, keep looking */		    (void) close(dfd);		}		/* did not find a device under the rmmedia_path */		free(dentp);		(void) close(fd);	    }	    /* didn't find a device under volume management control */	    return (-1);	}	/*	 * Not removable media under volume management control so just open the	 * first devpath.	 */	if (diskp->aliases != NULL && diskp->aliases->devpaths != NULL) {#ifdef sparc	    if (opath != NULL) {		(void) strlcpy(opath, diskp->aliases->devpaths->devpath, len);	    }	    return (open(diskp->aliases->devpaths->devpath, O_RDONLY|O_NDELAY));#else	    /* On intel we need to open partition device (e.g. c0d0p0). */	    char	part_dev[MAXPATHLEN];	    char	*p;	    (void) strlcpy(part_dev, diskp->aliases->devpaths->devpath,		sizeof (part_dev));	    p = strrchr(part_dev, '/');	    if (p == NULL) {		p = strrchr(part_dev, 's');		if (p != NULL) {		    *p = 'p';		}	    } else {		char *ps;		*p = 0;		ps = strrchr((p + 1), 's');		if (ps != NULL) {		    *ps = 'p';		}		*p = '/';	    }	    if (opath != NULL) {		(void) strlcpy(opath, part_dev, len);	    }	    return (open(part_dev, O_RDONLY|O_NDELAY));#endif	}	return (-1);}