OpenVAS Manager  7.0.3~git
utils.c
Go to the documentation of this file.
1 /* OpenVAS Manager
2  * $Id$
3  * Description: OpenVAS Manager: General utilities.
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  *
8  * Copyright:
9  * Copyright (C) 2016 Greenbone Networks GmbH
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #include "utils.h"
27 
28 #include <errno.h>
29 #include <time.h>
30 
38 int
39 openvas_usleep (unsigned int microseconds)
40 {
41  struct timespec a, b, *requested, *remaining;
42  int ret;
43 
44  requested = &a;
45  remaining = &b;
46 
47  requested->tv_sec = microseconds / 1000000;
48  requested->tv_nsec = (microseconds % 1000000) * 1000;
49 
50  while ((ret = nanosleep (requested, remaining)) && (errno == EINTR))
51  {
52  struct timespec *temp;
53  temp = requested;
54  requested = remaining;
55  remaining = temp;
56  }
57  if (ret)
58  return -1;
59  return 0;
60 }
61 
69 int
70 openvas_sleep (unsigned int seconds)
71 {
72  return openvas_usleep (seconds * 1000000);
73 }
int openvas_sleep(unsigned int seconds)
Sleep for some number of seconds, handling interrupts.
Definition: utils.c:70
int openvas_usleep(unsigned int microseconds)
Sleep for some number of microseconds, handling interrupts.
Definition: utils.c:39