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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
4086
|
27 #include <stdarg.h> |
|
28 #include <stdio.h> |
|
29 #include <stdlib.h> |
|
30 #include <string.h> |
|
31 |
|
32 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
33 |
|
34 #include <windows.h> |
|
35 |
|
36 #else |
|
37 |
3311
|
38 #ifdef HAVE_UNISTD_H |
|
39 #ifdef HAVE_SYS_TYPES_H |
|
40 #include <sys/types.h> |
|
41 #endif |
|
42 #include <unistd.h> |
|
43 #endif |
|
44 |
|
45 #include "systime.h" |
|
46 |
|
47 #ifdef HAVE_POLL_H |
|
48 #include <poll.h> |
|
49 #elif HAVE_SYS_POLL_H |
|
50 #include <sys/poll.h> |
|
51 #endif |
|
52 |
|
53 #endif |
|
54 |
3317
|
55 void |
4067
|
56 octave_sleep (unsigned int seconds) |
|
57 { |
4084
|
58 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
59 Sleep (1000 * seconds); |
|
60 #else |
4067
|
61 sleep (seconds); |
4084
|
62 #endif |
4067
|
63 } |
|
64 |
|
65 void |
3317
|
66 octave_usleep (unsigned int useconds) |
|
67 { |
|
68 unsigned int sec = useconds / 1000000; |
|
69 unsigned int usec = useconds % 1000000; |
|
70 |
|
71 if (sec > 0) |
4086
|
72 octave_sleep (sec); |
|
73 |
|
74 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
75 |
|
76 /* Round to the nearest millisecond, with a minimum of 1 millisecond |
|
77 if usleep was called with a a non-zero value. */ |
|
78 |
|
79 if (usec > 500) |
|
80 Sleep ((usec+500)/1000); |
|
81 else if (usec > 0) |
|
82 Sleep (1); |
|
83 else |
|
84 Sleep (0); |
|
85 |
|
86 #elif defined (HAVE_USLEEP) |
|
87 |
|
88 usleep (usec); |
3317
|
89 |
4086
|
90 #elif defined (HAVE_SELECT) |
|
91 |
4581
|
92 { |
|
93 struct timeval delay; |
4086
|
94 |
4581
|
95 delay.tv_sec = 0; |
|
96 delay.tv_usec = usec; |
4086
|
97 |
4581
|
98 select (0, 0, 0, 0, &delay); |
|
99 } |
4086
|
100 |
|
101 #elif defined (HAVE_POLL) |
|
102 |
4581
|
103 { |
|
104 struct pollfd pfd; |
|
105 int delay = usec / 1000; |
4086
|
106 |
4581
|
107 if (delay > 0) |
|
108 poll (&fd, 0, delay); |
|
109 } |
4086
|
110 |
|
111 #endif |
3317
|
112 } |
|
113 |
3350
|
114 int |
|
115 octave_strcasecmp (const char *s1, const char *s2) |
|
116 { |
|
117 return strcasecmp (s1, s2); |
|
118 } |
|
119 |
|
120 int |
|
121 octave_strncasecmp (const char *s1, const char *s2, size_t n) |
|
122 { |
|
123 return strncasecmp (s1, s2, n); |
|
124 } |
|
125 |
4302
|
126 int |
|
127 octave_raw_vsnprintf (char *buf, size_t n, const char *fmt, va_list args) |
3620
|
128 { |
4302
|
129 return vsnprintf (buf, n, fmt, args); |
3620
|
130 } |
|
131 |
3311
|
132 /* |
|
133 ;;; Local Variables: *** |
|
134 ;;; mode: C++ *** |
|
135 ;;; End: *** |
|
136 */ |