sleep.c 544 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <u.h>
  2. #include <libc.h>
  3. void
  4. main(int argc, char *argv[])
  5. {
  6. char *p;
  7. long secs;
  8. if(argc>1){
  9. for(secs = atol(argv[1]); secs > 0; secs--)
  10. sleep(1000);
  11. /*
  12. * no floating point because it is useful to
  13. * be able to run sleep when bootstrapping
  14. * a machine.
  15. */
  16. if(p = strchr(argv[1], '.')){
  17. p++;
  18. switch(strlen(p)){
  19. case 0:
  20. break;
  21. case 1:
  22. sleep(atoi(p)*100);
  23. break;
  24. case 2:
  25. sleep(atoi(p)*10);
  26. break;
  27. default:
  28. p[3] = 0;
  29. sleep(atoi(p));
  30. break;
  31. }
  32. }
  33. }
  34. exits(0);
  35. }