3311
|
1 /* |
|
2 |
|
3 Copyright (C) 1999 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3311
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
4086
|
28 #include <stdarg.h> |
|
29 #include <stdio.h> |
|
30 #include <stdlib.h> |
|
31 #include <string.h> |
|
32 |
|
33 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
34 |
|
35 #include <windows.h> |
|
36 |
|
37 #else |
|
38 |
3311
|
39 #ifdef HAVE_UNISTD_H |
|
40 #ifdef HAVE_SYS_TYPES_H |
|
41 #include <sys/types.h> |
|
42 #endif |
|
43 #include <unistd.h> |
|
44 #endif |
|
45 |
|
46 #include "systime.h" |
|
47 |
|
48 #ifdef HAVE_POLL_H |
|
49 #include <poll.h> |
|
50 #elif HAVE_SYS_POLL_H |
|
51 #include <sys/poll.h> |
|
52 #endif |
|
53 |
|
54 #endif |
|
55 |
3317
|
56 void |
4067
|
57 octave_sleep (unsigned int seconds) |
|
58 { |
4084
|
59 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
60 Sleep (1000 * seconds); |
|
61 #else |
4067
|
62 sleep (seconds); |
4084
|
63 #endif |
4067
|
64 } |
|
65 |
|
66 void |
3317
|
67 octave_usleep (unsigned int useconds) |
|
68 { |
|
69 unsigned int sec = useconds / 1000000; |
|
70 unsigned int usec = useconds % 1000000; |
|
71 |
|
72 if (sec > 0) |
4086
|
73 octave_sleep (sec); |
|
74 |
|
75 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
76 |
|
77 /* Round to the nearest millisecond, with a minimum of 1 millisecond |
|
78 if usleep was called with a a non-zero value. */ |
|
79 |
|
80 if (usec > 500) |
|
81 Sleep ((usec+500)/1000); |
|
82 else if (usec > 0) |
|
83 Sleep (1); |
|
84 else |
|
85 Sleep (0); |
|
86 |
|
87 #elif defined (HAVE_USLEEP) |
|
88 |
|
89 usleep (usec); |
3317
|
90 |
4086
|
91 #elif defined (HAVE_SELECT) |
|
92 |
4581
|
93 { |
|
94 struct timeval delay; |
4086
|
95 |
4581
|
96 delay.tv_sec = 0; |
|
97 delay.tv_usec = usec; |
4086
|
98 |
4581
|
99 select (0, 0, 0, 0, &delay); |
|
100 } |
4086
|
101 |
|
102 #elif defined (HAVE_POLL) |
|
103 |
4581
|
104 { |
|
105 struct pollfd pfd; |
5141
|
106 |
4581
|
107 int delay = usec / 1000; |
4086
|
108 |
4581
|
109 if (delay > 0) |
5141
|
110 poll (&pfd, 0, delay); |
4581
|
111 } |
4086
|
112 |
|
113 #endif |
3317
|
114 } |
|
115 |
3350
|
116 int |
|
117 octave_strcasecmp (const char *s1, const char *s2) |
|
118 { |
|
119 return strcasecmp (s1, s2); |
|
120 } |
|
121 |
|
122 int |
|
123 octave_strncasecmp (const char *s1, const char *s2, size_t n) |
|
124 { |
|
125 return strncasecmp (s1, s2, n); |
|
126 } |
|
127 |
4302
|
128 int |
|
129 octave_raw_vsnprintf (char *buf, size_t n, const char *fmt, va_list args) |
3620
|
130 { |
4302
|
131 return vsnprintf (buf, n, fmt, args); |
3620
|
132 } |
|
133 |
3311
|
134 /* |
|
135 ;;; Local Variables: *** |
|
136 ;;; mode: C++ *** |
|
137 ;;; End: *** |
|
138 */ |