xref: /titanic_51/usr/src/ucbcmd/touch/touch.c (revision cc6c5292fa8a241fe50604cf6a918edfbf7cd7d2)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef lint
287c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
297c478bd9Sstevel@tonic-gate #endif
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <stdio.h>
327c478bd9Sstevel@tonic-gate #include <ctype.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/stat.h>
357c478bd9Sstevel@tonic-gate #include <sys/file.h>
367c478bd9Sstevel@tonic-gate #include <sys/time.h>
377c478bd9Sstevel@tonic-gate #include <time.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <unistd.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate struct	stat	stbuf;
447c478bd9Sstevel@tonic-gate int	status;
457c478bd9Sstevel@tonic-gate #ifdef S5EMUL
467c478bd9Sstevel@tonic-gate int dmsize[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
47*cc6c5292Schin #endif /* S5EMUL */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate static char usage[] =
507c478bd9Sstevel@tonic-gate #ifdef S5EMUL
517c478bd9Sstevel@tonic-gate 		"[-amc] [mmddhhmm[yy]]";
527c478bd9Sstevel@tonic-gate #else /*!S5EMUL*/
537c478bd9Sstevel@tonic-gate 		"[-amcf]";
547c478bd9Sstevel@tonic-gate int	force = 0;
557c478bd9Sstevel@tonic-gate int	nowrite;
567c478bd9Sstevel@tonic-gate #endif /*!S5EMUL*/
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate int	mflg=1, aflg=1, cflg=0, nflg=0;
597c478bd9Sstevel@tonic-gate char	*prog;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #ifdef S5EMUL
627c478bd9Sstevel@tonic-gate char	*cbp;
63*cc6c5292Schin #endif /* S5EMUL */
647c478bd9Sstevel@tonic-gate time_t	time();
657c478bd9Sstevel@tonic-gate off_t	lseek();
667c478bd9Sstevel@tonic-gate time_t	timelocal(), timegm();
677c478bd9Sstevel@tonic-gate struct timeval timbuf;
687c478bd9Sstevel@tonic-gate static void timestruc_to_timeval(timestruc_t *, struct timeval *);
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #ifdef S5EMUL
717c478bd9Sstevel@tonic-gate struct tm *
727c478bd9Sstevel@tonic-gate gtime()
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate 	static struct tm newtime;
757c478bd9Sstevel@tonic-gate 	long nt;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	newtime.tm_mon = gpair() - 1;
787c478bd9Sstevel@tonic-gate 	newtime.tm_mday = gpair();
797c478bd9Sstevel@tonic-gate 	newtime.tm_hour = gpair();
807c478bd9Sstevel@tonic-gate 	if (newtime.tm_hour == 24) {
817c478bd9Sstevel@tonic-gate 		newtime.tm_hour = 0;
827c478bd9Sstevel@tonic-gate 		newtime.tm_mday++;
837c478bd9Sstevel@tonic-gate 	}
847c478bd9Sstevel@tonic-gate 	newtime.tm_min = gpair();
857c478bd9Sstevel@tonic-gate 	newtime.tm_sec = 0;
867c478bd9Sstevel@tonic-gate 	newtime.tm_year = gpair();
877c478bd9Sstevel@tonic-gate 	if (newtime.tm_year < 0) {
887c478bd9Sstevel@tonic-gate 		(void) time(&nt);
897c478bd9Sstevel@tonic-gate 		newtime.tm_year = localtime(&nt)->tm_year;
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 	return (&newtime);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate gpair()
957c478bd9Sstevel@tonic-gate {
96*cc6c5292Schin 	int c, d;
97*cc6c5292Schin 	char *cp;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	cp = cbp;
1007c478bd9Sstevel@tonic-gate 	if (*cp == 0)
1017c478bd9Sstevel@tonic-gate 		return (-1);
1027c478bd9Sstevel@tonic-gate 	c = (*cp++ - '0') * 10;
1037c478bd9Sstevel@tonic-gate 	if (c<0 || c>100)
1047c478bd9Sstevel@tonic-gate 		return (-1);
1057c478bd9Sstevel@tonic-gate 	if (*cp == 0)
1067c478bd9Sstevel@tonic-gate 		return (-1);
1077c478bd9Sstevel@tonic-gate 	if ((d = *cp++ - '0') < 0 || d > 9)
1087c478bd9Sstevel@tonic-gate 		return (-1);
1097c478bd9Sstevel@tonic-gate 	cbp = cp;
1107c478bd9Sstevel@tonic-gate 	return (c+d);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate #endif /*S5EMUL*/
1137c478bd9Sstevel@tonic-gate 
114*cc6c5292Schin int
115*cc6c5292Schin main(int argc, char *argv[])
1167c478bd9Sstevel@tonic-gate {
117*cc6c5292Schin 	int c;
1187c478bd9Sstevel@tonic-gate #ifdef S5EMUL
1197c478bd9Sstevel@tonic-gate 	int days_in_month;
1207c478bd9Sstevel@tonic-gate 	struct tm *tp;
121*cc6c5292Schin #endif /* S5EMUL */
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	int errflg=0, optc;
1247c478bd9Sstevel@tonic-gate 	extern char *optarg;
1257c478bd9Sstevel@tonic-gate 	extern int optind;
1267c478bd9Sstevel@tonic-gate 	extern int opterr;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	prog = argv[0];
1297c478bd9Sstevel@tonic-gate 	opterr = 0;			/* disable getopt() error msgs */
1307c478bd9Sstevel@tonic-gate 	while ((optc=getopt(argc, argv, "amcf")) != EOF)
1317c478bd9Sstevel@tonic-gate 		switch (optc) {
1327c478bd9Sstevel@tonic-gate 		case 'm':
1337c478bd9Sstevel@tonic-gate 			mflg++;
1347c478bd9Sstevel@tonic-gate 			aflg--;
1357c478bd9Sstevel@tonic-gate 			break;
1367c478bd9Sstevel@tonic-gate 		case 'a':
1377c478bd9Sstevel@tonic-gate 			aflg++;
1387c478bd9Sstevel@tonic-gate 			mflg--;
1397c478bd9Sstevel@tonic-gate 			break;
1407c478bd9Sstevel@tonic-gate 		case 'c':
1417c478bd9Sstevel@tonic-gate 			cflg++;
1427c478bd9Sstevel@tonic-gate 			break;
1437c478bd9Sstevel@tonic-gate #ifndef S5EMUL
1447c478bd9Sstevel@tonic-gate 		case 'f':
1457c478bd9Sstevel@tonic-gate 			force++;	/* SysV version ignores -f */
1467c478bd9Sstevel@tonic-gate 			break;
1477c478bd9Sstevel@tonic-gate #endif /*!S5EMUL*/
1487c478bd9Sstevel@tonic-gate 		case '?':
1497c478bd9Sstevel@tonic-gate 			errflg++;
1507c478bd9Sstevel@tonic-gate 		}
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	if (((argc-optind) < 1) || errflg) {
1537c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "usage: %s %s file ...\n", prog, usage);
1547c478bd9Sstevel@tonic-gate 		exit(2);
1557c478bd9Sstevel@tonic-gate 	}
1567c478bd9Sstevel@tonic-gate 	status = 0;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #ifdef S5EMUL
1597c478bd9Sstevel@tonic-gate 	if (!isnumber(argv[optind])) {	/* BSD version only sets Present */
1607c478bd9Sstevel@tonic-gate #endif /*S5EMUL*/
1617c478bd9Sstevel@tonic-gate 		if ((aflg <= 0) || (mflg <= 0))
1627c478bd9Sstevel@tonic-gate 			(void) gettimeofday(&timbuf, NULL);
1637c478bd9Sstevel@tonic-gate 		else
1647c478bd9Sstevel@tonic-gate 			nflg++;		/* no -a, -m, or date seen */
1657c478bd9Sstevel@tonic-gate #ifdef S5EMUL
1667c478bd9Sstevel@tonic-gate 	} else {			/* SysV version sets arbitrary date */
1677c478bd9Sstevel@tonic-gate 		cbp = (char *)argv[optind++];
1687c478bd9Sstevel@tonic-gate 		if ((tp = gtime()) == NULL) {
1697c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: bad date conversion\n",
1707c478bd9Sstevel@tonic-gate 			    prog);
1717c478bd9Sstevel@tonic-gate 			exit(2);
1727c478bd9Sstevel@tonic-gate 		}
1737c478bd9Sstevel@tonic-gate 		days_in_month = dmsize[tp->tm_mon];
1747c478bd9Sstevel@tonic-gate 		if (tp->tm_mon == 1 && isleap(tp->tm_year + 1900))
1757c478bd9Sstevel@tonic-gate 			days_in_month = 29;	/* February in leap year */
1767c478bd9Sstevel@tonic-gate 		if (tp->tm_mon < 0 || tp->tm_mon > 11 ||
1777c478bd9Sstevel@tonic-gate 		    tp->tm_mday < 1 || tp->tm_mday > days_in_month ||
1787c478bd9Sstevel@tonic-gate 		    tp->tm_hour < 0 || tp->tm_hour > 23 ||
1797c478bd9Sstevel@tonic-gate 		    tp->tm_min < 0 || tp->tm_min > 59 ||
1807c478bd9Sstevel@tonic-gate 		    tp->tm_sec < 0 || tp->tm_sec > 59) {
1817c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: bad date conversion\n",
1827c478bd9Sstevel@tonic-gate 			    prog);
1837c478bd9Sstevel@tonic-gate 			exit(2);
1847c478bd9Sstevel@tonic-gate 		}
1857c478bd9Sstevel@tonic-gate 		timbuf = timelocal(tp);
1867c478bd9Sstevel@tonic-gate 	}
1877c478bd9Sstevel@tonic-gate #endif /*S5EMUL*/
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	for (c = optind; c < argc; c++) {
1907c478bd9Sstevel@tonic-gate 		if (touch(argv[c]) < 0)
1917c478bd9Sstevel@tonic-gate 			status++;
1927c478bd9Sstevel@tonic-gate 	}
193*cc6c5292Schin 	return (status);
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate int
1977c478bd9Sstevel@tonic-gate touch(filename)
1987c478bd9Sstevel@tonic-gate 	char *filename;
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate 	struct timeval times[2];
201*cc6c5292Schin 	int fd;
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (stat(filename, &stbuf)) {
2047c478bd9Sstevel@tonic-gate 		/*
2057c478bd9Sstevel@tonic-gate 		 * if stat failed for reasons other than ENOENT,
2067c478bd9Sstevel@tonic-gate 		 * the file should not be created, since this
2077c478bd9Sstevel@tonic-gate 		 * can clobber the contents of an existing file
2087c478bd9Sstevel@tonic-gate 		 * (for example, a large file that results in overflow).
2097c478bd9Sstevel@tonic-gate 		 */
2107c478bd9Sstevel@tonic-gate 		if (errno != ENOENT) {
2117c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,"%s: cannot stat ", prog);
2127c478bd9Sstevel@tonic-gate 			perror(filename);
2137c478bd9Sstevel@tonic-gate 			return (-1);
2147c478bd9Sstevel@tonic-gate 		} else if (cflg) {
2157c478bd9Sstevel@tonic-gate 			return (-1);
2167c478bd9Sstevel@tonic-gate 		}
2177c478bd9Sstevel@tonic-gate 		else if ((fd = creat(filename, 0666)) < 0) {
2187c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: cannot create ", prog);
2197c478bd9Sstevel@tonic-gate 			perror(filename);
2207c478bd9Sstevel@tonic-gate 			return (-1);
2217c478bd9Sstevel@tonic-gate 		}
2227c478bd9Sstevel@tonic-gate 		else {
2237c478bd9Sstevel@tonic-gate 			(void) close(fd);
2247c478bd9Sstevel@tonic-gate 			if (stat(filename, &stbuf)) {
2257c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,"%s: cannot stat ", prog);
2267c478bd9Sstevel@tonic-gate 				perror(filename);
2277c478bd9Sstevel@tonic-gate 				return (-1);
2287c478bd9Sstevel@tonic-gate 			}
2297c478bd9Sstevel@tonic-gate 		}
2307c478bd9Sstevel@tonic-gate 		if (nflg)
2317c478bd9Sstevel@tonic-gate 			return (0);
2327c478bd9Sstevel@tonic-gate 	}
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	times[0] = times[1] = timbuf;
2357c478bd9Sstevel@tonic-gate 	if (mflg <= 0)
2367c478bd9Sstevel@tonic-gate 		timestruc_to_timeval(&stbuf.st_mtim, times + 1);
2377c478bd9Sstevel@tonic-gate 	if (aflg <= 0)
2387c478bd9Sstevel@tonic-gate 		timestruc_to_timeval(&stbuf.st_atim, times);
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate #ifndef S5EMUL
2417c478bd9Sstevel@tonic-gate 	/*
2427c478bd9Sstevel@tonic-gate 	 * Since utime() allows the owner to change file times without
2437c478bd9Sstevel@tonic-gate 	 * regard to access permission, enforce BSD semantics here
2447c478bd9Sstevel@tonic-gate 	 * (cannot touch if read-only and not -f).
2457c478bd9Sstevel@tonic-gate 	 */
2467c478bd9Sstevel@tonic-gate 	nowrite = access(filename, R_OK|W_OK);
2477c478bd9Sstevel@tonic-gate 	if (nowrite && !force) {
2487c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
2497c478bd9Sstevel@tonic-gate 		    "%s: cannot touch %s: no write permission\n",
2507c478bd9Sstevel@tonic-gate 		    prog, filename);
2517c478bd9Sstevel@tonic-gate 		return (-1);
2527c478bd9Sstevel@tonic-gate 	}
2537c478bd9Sstevel@tonic-gate #endif /*!S5EMUL*/
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	if (utimes(filename, nflg ? NULL : times)) {
2567c478bd9Sstevel@tonic-gate 		if (nflg && (errno != EROFS) && (errno != EACCES)) {
2577c478bd9Sstevel@tonic-gate 			/*
2587c478bd9Sstevel@tonic-gate 			 * If utime() failed to set the Present, it
2597c478bd9Sstevel@tonic-gate 			 * could be a BSD server that is complaining.
2607c478bd9Sstevel@tonic-gate 			 * If that's the case, try the old read/write trick.
2617c478bd9Sstevel@tonic-gate 			 */
2627c478bd9Sstevel@tonic-gate 			return (oldtouch(filename, &stbuf));
2637c478bd9Sstevel@tonic-gate 		}
2647c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,"%s: cannot change times on ", prog);
2657c478bd9Sstevel@tonic-gate 		perror(filename);
2667c478bd9Sstevel@tonic-gate 		return (-1);
2677c478bd9Sstevel@tonic-gate 	}
2687c478bd9Sstevel@tonic-gate 	return (0);
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate int
2727c478bd9Sstevel@tonic-gate oldtouch(filename, statp)
2737c478bd9Sstevel@tonic-gate 	char *filename;
274*cc6c5292Schin 	struct stat *statp;
2757c478bd9Sstevel@tonic-gate {
2767c478bd9Sstevel@tonic-gate 	int rwstatus;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	if ((statp->st_mode & S_IFMT) != S_IFREG) {
2797c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
2807c478bd9Sstevel@tonic-gate 		    "%s: %s: only owner may touch special files on this filesystem\n",
2817c478bd9Sstevel@tonic-gate 		    prog, filename);
2827c478bd9Sstevel@tonic-gate 		return (-1);
2837c478bd9Sstevel@tonic-gate 	}
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate #ifndef S5EMUL
2867c478bd9Sstevel@tonic-gate 	if (nowrite && force) {
2877c478bd9Sstevel@tonic-gate 		if (chmod(filename, 0666)) {
2887c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: could not chmod ", prog);
2897c478bd9Sstevel@tonic-gate 			perror(filename);
2907c478bd9Sstevel@tonic-gate 			return (-1);
2917c478bd9Sstevel@tonic-gate 		}
2927c478bd9Sstevel@tonic-gate 		rwstatus = readwrite(filename, statp->st_size);
2937c478bd9Sstevel@tonic-gate 		if (chmod(filename, (int)statp->st_mode)) {
2947c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: could not chmod back ", prog);
2957c478bd9Sstevel@tonic-gate 			perror(filename);
2967c478bd9Sstevel@tonic-gate 			return (-1);
2977c478bd9Sstevel@tonic-gate 		}
2987c478bd9Sstevel@tonic-gate 		return (rwstatus);
2997c478bd9Sstevel@tonic-gate 	} else
3007c478bd9Sstevel@tonic-gate #endif /*!S5EMUL*/
3017c478bd9Sstevel@tonic-gate 		return (readwrite(filename, statp->st_size));
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate int
3057c478bd9Sstevel@tonic-gate readwrite(filename, size)
3067c478bd9Sstevel@tonic-gate 	char	*filename;
3077c478bd9Sstevel@tonic-gate 	off_t	size;
3087c478bd9Sstevel@tonic-gate {
3097c478bd9Sstevel@tonic-gate 	int fd;
3107c478bd9Sstevel@tonic-gate 	char first;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	if (size) {
3137c478bd9Sstevel@tonic-gate 		if ((fd = open(filename, 2)) < 0)
3147c478bd9Sstevel@tonic-gate 			goto error;
3157c478bd9Sstevel@tonic-gate 		if (read(fd, &first, 1) != 1)
3167c478bd9Sstevel@tonic-gate 			goto closeerror;
3177c478bd9Sstevel@tonic-gate 		if (lseek(fd, 0L, 0) == -1)
3187c478bd9Sstevel@tonic-gate 			goto closeerror;
3197c478bd9Sstevel@tonic-gate 		if (write(fd, &first, 1) != 1)
3207c478bd9Sstevel@tonic-gate 			goto closeerror;
3217c478bd9Sstevel@tonic-gate 	} else {
3227c478bd9Sstevel@tonic-gate 		if ((fd = creat(filename, 0666)) < 0)
3237c478bd9Sstevel@tonic-gate 			goto error;
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 	if (close(fd) < 0)
3267c478bd9Sstevel@tonic-gate 		goto error;
3277c478bd9Sstevel@tonic-gate 	return (0);
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate closeerror:
3307c478bd9Sstevel@tonic-gate 	(void) close(fd);
3317c478bd9Sstevel@tonic-gate error:
3327c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: could not touch ", prog);
3337c478bd9Sstevel@tonic-gate 	perror(filename);
3347c478bd9Sstevel@tonic-gate 	return (-1);
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate #ifdef S5EMUL
3387c478bd9Sstevel@tonic-gate isnumber(s)
3397c478bd9Sstevel@tonic-gate 	char *s;
3407c478bd9Sstevel@tonic-gate {
341*cc6c5292Schin 	char c;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	while (c = *s++)
3447c478bd9Sstevel@tonic-gate 		if (!isdigit(c))
3457c478bd9Sstevel@tonic-gate 			return (0);
3467c478bd9Sstevel@tonic-gate 	return (1);
3477c478bd9Sstevel@tonic-gate }
348*cc6c5292Schin #endif /* S5EMUL */
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate /*
3517c478bd9Sstevel@tonic-gate  * nanoseconds are rounded off to microseconds by flooring.
3527c478bd9Sstevel@tonic-gate  */
3537c478bd9Sstevel@tonic-gate static void
3547c478bd9Sstevel@tonic-gate timestruc_to_timeval(timestruc_t *ts, struct timeval *tv)
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate 	tv->tv_sec = ts->tv_sec;
3577c478bd9Sstevel@tonic-gate 	tv->tv_usec = ts->tv_nsec / 1000;
3587c478bd9Sstevel@tonic-gate }
359