sleep.c 965 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. void
  12. main(int argc, char *argv[])
  13. {
  14. int32_t n;
  15. char *p, *q;
  16. if(argc>1){
  17. for(n = strtol(argv[1], &p, 0); n > 0; n--)
  18. sleep(1000);
  19. /*
  20. * no floating point because it is useful to
  21. * be able to run sleep when bootstrapping
  22. * a machine.
  23. */
  24. if(*p++ == '.' && (n = strtol(p, &q, 10)) > 0){
  25. switch(q - p){
  26. case 0:
  27. break;
  28. case 1:
  29. n *= 100;
  30. break;
  31. case 2:
  32. n *= 10;
  33. break;
  34. default:
  35. p[3] = 0;
  36. n = strtol(p, 0, 10);
  37. break;
  38. }
  39. sleep(n);
  40. }
  41. }
  42. exits(0);
  43. }