1 // posix.cc -- Helper functions for POSIX-flavored OSs.
3 /* Copyright (C) 2000 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
18 extern "C" unsigned long long _clock (void);
21 // gettimeofday implementation.
23 _Jv_gettimeofday (struct timeval *tv)
25 #if defined (HAVE_GETTIMEOFDAY)
26 gettimeofday (tv, NULL);
27 #elif defined (HAVE_TIME)
28 tv->tv_sec = time (NULL);
30 #elif defined (HAVE_FTIME)
34 tv->tv_usec = t.millitm * 1000;
37 tv->tv_sec = _clock () / 1000;
40 // In the absence of any function, time remains forever fixed.
46 // A wrapper for select() which ignores EINTR.
48 _Jv_select (int n, fd_set *readfds, fd_set *writefds,
49 fd_set *exceptfds, struct timeval *timeout)
52 // If we have a timeout, compute the absolute ending time.
53 struct timeval end, delay;
56 _Jv_gettimeofday (&end);
57 end.tv_usec += timeout->tv_usec;
58 if (end.tv_usec >= 1000000)
61 end.tv_usec -= 1000000;
63 end.tv_sec += timeout->tv_sec;
69 delay.tv_sec = delay.tv_usec = 0;
74 int r = select (n, readfds, writefds, exceptfds,
75 timeout ? &delay : NULL);
76 if (r != -1 || errno != EINTR)
82 _Jv_gettimeofday (&after);
83 // Now compute new timeout argument.
84 delay.tv_usec = end.tv_usec - after.tv_usec;
85 delay.tv_sec = end.tv_sec - after.tv_sec;
86 if (delay.tv_usec < 0)
89 delay.tv_usec += 1000000;
93 // We assume that the user wants a valid select() call
94 // more than precise timing. So if we get a series of
95 // EINTR we just keep trying with delay 0 until we get a
101 #else /* HAVE_SELECT */