usleep.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: usleep.c /main/6 1998/04/06 13:32:38 mgreess $ */
  24. /*
  25. */
  26. /* *
  27. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  28. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  29. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  30. * (c) Copyright 1993, 1994 Novell, Inc. *
  31. */
  32. /*-
  33. * usleep.c - OS dependant implementation of usleep().
  34. *
  35. * Copyright (c) 1991 by Patrick J. Naughton.
  36. *
  37. * Revision History:
  38. * 30-Aug-90: written.
  39. *
  40. */
  41. #include "dtscreen.h"
  42. #if !defined(_AIX) && !defined(hpV4) && !defined(__linux__) && !defined(sun) && !defined(CSRG_BASED)
  43. int
  44. usleep(unsigned long usec)
  45. {
  46. #ifdef SYSV
  47. poll((struct poll *) 0, (size_t) 0, usec / 1000); /* ms resolution */
  48. #else
  49. struct timeval timeout;
  50. timeout.tv_usec = usec % (unsigned long) 1000000;
  51. timeout.tv_sec = usec / (unsigned long) 1000000;
  52. select(0, (void *) 0, (void *) 0, (void *) 0, &timeout);
  53. #endif
  54. return 0;
  55. }
  56. #endif /* !_AIX && !hpV4*/
  57. /*
  58. * returns the number of seconds since 01-Jan-70.
  59. * This is used to control rate and timeout in many of the animations.
  60. */
  61. long
  62. seconds(void)
  63. {
  64. struct timeval now;
  65. gettimeofday(&now, (struct timezone *) 0);
  66. return now.tv_sec;
  67. }