Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Oct 1997 20:18:52 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        xaa@stack.nl (Mark Huizer)
Cc:        joerg_wunsch@uriah.heep.sax.de, freebsd-hackers@FreeBSD.ORG, denny1@home.com
Subject:   Re: wish /bin/sleep handled fractions of a second.
Message-ID:  <199710122018.NAA18736@usr05.primenet.com>
In-Reply-To: <19971012152916.52277@xaa.stack.nl> from "Mark Huizer" at Oct 12, 97 03:29:16 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> I'd like it too. Is it too tough? Perhaps in 2 weeks, after finishing my
> graduation, I could look at it. Either you change sleep to look like:
> 
> sleep [-m] NUMBER
> 
> where -m means: the NUMBER is in milliseconds
> 
> or you make it:
> 
> sleep NUMBER[.NUMBER]
> 
> where .number is the decimal part of the second.
> 
> Any preferences?

Yes.  I prefer that someone else fix the man page after this patch is
committed.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.
Index: sleep.c
===================================================================
RCS file: /b/cvstree/ncvs/src/bin/sleep/sleep.c,v
retrieving revision 1.6
diff -c -r1.6 sleep.c
*** 1.6	1997/03/28 15:24:40
--- sleep.c	1997/10/12 20:09:28
***************
*** 55,60 ****
--- 55,62 ----
  	char *argv[];
  {
  	int ch, secs;
+ 	double fsecs;
+ 
  
  	while ((ch = getopt(argc, argv, "")) != -1)
  		switch(ch) {
***************
*** 68,75 ****
  	if (argc != 1)
  		usage();
  
! 	if ((secs = atoi(*argv)) > 0)
! 		(void)sleep(secs);
  	exit(0);
  }
  
--- 70,83 ----
  	if (argc != 1)
  		usage();
  
! 	if ((fsecs = atof(*argv)) > 0) {
! 		secs = fsecs;
! 		if ((fsecs - secs) > 0) {
! 			unsigned int usecs = fsecs * 1000000.0;
! 			(void)usleep(usecs);
! 		} else
! 			(void)sleep(secs);
! 	}
  	exit(0);
  }
  
***************
*** 77,82 ****
  usage()
  {
  
! 	(void)fprintf(stderr, "usage: sleep seconds\n");
  	exit(1);
  }
--- 85,90 ----
  usage()
  {
  
! 	(void)fprintf(stderr, "usage: sleep seconds[.fractional_seconds]\n");
  	exit(1);
  }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199710122018.NAA18736>