File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
1
#include <sys/types.h>
2
2
#include <stdio.h>
3
+ #include <stdlib.h>
3
4
#include <stdbool.h>
4
5
#include <stdint.h>
5
6
#include <string.h>
9
10
#else
10
11
#include <sys/wait.h>
11
12
#include <unistd.h>
13
+ #include <time.h>
14
+ #include <errno.h>
12
15
#endif // _WIN32
13
16
14
17
// Typedefs
@@ -248,7 +251,34 @@ void process_wait(float seconds)
248
251
Sleep (dwMilliseconds );
249
252
#else
250
253
int uSeconds = (int ) 1.0e6 * seconds ;
251
- usleep (uSeconds );
254
+
255
+ struct timespec t ;
256
+
257
+ t .tv_sec = seconds ;
258
+ t .tv_nsec = seconds * 1000000 ;
259
+
260
+ int ierr = nanosleep (& t , NULL );
261
+
262
+ if (ierr != 0 ){
263
+ switch (errno ){
264
+ case EINTR :
265
+ fprintf (stderr , "nanosleep() interrupted\n" );
266
+ break ;
267
+ case EINVAL :
268
+ fprintf (stderr , "nanosleep() bad milliseconds value\n" );
269
+ exit (EINVAL );
270
+ case EFAULT :
271
+ fprintf (stderr , "nanosleep() bad milliseconds value\n" );
272
+ exit (EFAULT );
273
+ case ENOSYS :
274
+ fprintf (stderr , "nanosleep() not supported on this system\n" );
275
+ exit (ENOSYS );
276
+ default :
277
+ fprintf (stderr , "nanosleep() error\n" );
278
+ exit (1 );
279
+ }
280
+ }
281
+
252
282
#endif // _WIN32
253
283
}
254
284
You can’t perform that action at this time.
0 commit comments