LCOV - code coverage report
Current view: top level - src/utils - sleep.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 8 9 88.9 %
Date: 2025-01-18 12:13:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 2015 Ziglio Frediano
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Library General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2 of the License, or (at your option) any later version.
       8             :  *
       9             :  * This library 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 GNU
      12             :  * Library General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Library General Public
      15             :  * License along with this library; if not, write to the
      16             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      17             :  * Boston, MA 02111-1307, USA.
      18             :  */
      19             : 
      20             : #include <config.h>
      21             : 
      22             : #include <stdio.h>
      23             : 
      24             : #if HAVE_UNISTD_H
      25             : #include <unistd.h>
      26             : #endif /* HAVE_UNISTD_H */
      27             : 
      28             : #if HAVE_ERRNO_H
      29             : #include <errno.h>
      30             : #endif /* HAVE_ERRNO_H */
      31             : 
      32             : #if HAVE_POLL_H
      33             : #include <poll.h>
      34             : #endif /* HAVE_POLL_H */
      35             : 
      36             : #include <freetds/time.h>
      37             : #include <freetds/sysdep_private.h>
      38             : #include <freetds/utils.h>
      39             : 
      40             : void
      41         120 : tds_sleep_s(unsigned sec)
      42             : {
      43             : #ifdef _WIN32
      44             :         Sleep(sec * 1000u);
      45             : #else
      46         120 :         sleep(sec);
      47             : #endif
      48         120 : }
      49             : 
      50             : void
      51       12081 : tds_sleep_ms(unsigned ms)
      52             : {
      53             : #ifdef _WIN32
      54             :         Sleep(ms);
      55             : #elif defined(HAVE_NANOSLEEP)
      56       12081 :         struct timespec ts = { ms / 1000u, (ms % 1000u) * 1000000lu }, rem;
      57             :         int r;
      58             : 
      59             :         for (;;) {
      60       12081 :                 r = nanosleep(&ts, &rem);
      61       12081 :                 if (!r || errno != EINTR)
      62             :                         break;
      63           0 :                 ts = rem;
      64             :         }
      65             : #elif defined(HAVE_USLEEP)
      66             :         usleep(ms * 1000u);
      67             : #else
      68             :         struct pollfd fd;
      69             :         poll(&fd, 0, ms);
      70             : #endif
      71       12081 : }

Generated by: LCOV version 1.13