sleep.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Implementation of the SLEEP intrinsic.
  2. Copyright (C) 2005-2015 Free Software Foundation, Inc.
  3. Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
  4. This file is part of the GNU Fortran 95 runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. #include <errno.h>
  22. #ifdef HAVE_UNISTD_H
  23. #include <unistd.h>
  24. #endif
  25. #ifdef __MINGW32__
  26. # include <windows.h>
  27. # undef sleep
  28. # define sleep(x) Sleep(1000*(x))
  29. # define HAVE_SLEEP 1
  30. #endif
  31. /* SUBROUTINE SLEEP(SECONDS)
  32. INTEGER, INTENT(IN) :: SECONDS
  33. A choice had to be made if SECONDS is negative. For g77, this is
  34. equivalent to SLEEP(0). */
  35. #ifdef HAVE_SLEEP
  36. extern void sleep_i4_sub (GFC_INTEGER_4 *);
  37. iexport_proto(sleep_i4_sub);
  38. void
  39. sleep_i4_sub (GFC_INTEGER_4 *seconds)
  40. {
  41. sleep (*seconds < 0 ? 0 : (unsigned int) *seconds);
  42. }
  43. iexport(sleep_i4_sub);
  44. extern void sleep_i8_sub (GFC_INTEGER_8 *);
  45. iexport_proto(sleep_i8_sub);
  46. void
  47. sleep_i8_sub (GFC_INTEGER_8 *seconds)
  48. {
  49. sleep (*seconds < 0 ? 0 : (unsigned int) *seconds);
  50. }
  51. iexport(sleep_i8_sub);
  52. #endif