* Sleep for a specified number of milliseconds. * * Always returns True. **/
| 34 | * Always returns True. |
| 35 | **/ |
| 36 | int msleep(int t) |
| 37 | { |
| 38 | #ifdef HAVE_NANOSLEEP |
| 39 | struct timespec ts; |
| 40 | |
| 41 | ts.tv_sec = t / 1000; |
| 42 | ts.tv_nsec = (t % 1000) * 1000000L; |
| 43 | |
| 44 | while (nanosleep(&ts, &ts) < 0 && errno == EINTR) {} |
| 45 | |
| 46 | #elif defined HAVE_USLEEP |
| 47 | usleep(t*1000); |
| 48 | |
| 49 | #else |
| 50 | int tdiff = 0; |
| 51 | struct timeval tval, t1, t2; |
| 52 | |
| 53 | gettimeofday(&t1, NULL); |
| 54 | |
| 55 | while (tdiff < t) { |
| 56 | tval.tv_sec = (t-tdiff)/1000; |
| 57 | tval.tv_usec = 1000*((t-tdiff)%1000); |
| 58 | |
| 59 | errno = 0; |
| 60 | select(0,NULL,NULL, NULL, &tval); |
| 61 | |
| 62 | gettimeofday(&t2, NULL); |
| 63 | tdiff = (t2.tv_sec - t1.tv_sec)*1000 + |
| 64 | (t2.tv_usec - t1.tv_usec)/1000; |
| 65 | if (tdiff < 0) |
| 66 | t1 = t2; /* Time went backwards, so start over. */ |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | return True; |
| 71 | } |
| 72 | |
| 73 | void *my_alloc(void *ptr, size_t num, size_t size, const char *file, int line) |
| 74 | { |
no outgoing calls
no test coverage detected