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 |
|
27 #ifdef HAVE_UNISTD_H |
|
28 #ifdef HAVE_SYS_TYPES_H |
|
29 #include <sys/types.h> |
|
30 #endif |
|
31 #include <unistd.h> |
|
32 #endif |
|
33 |
|
34 #include "systime.h" |
|
35 |
|
36 #ifdef HAVE_POLL_H |
|
37 #include <poll.h> |
|
38 #elif HAVE_SYS_POLL_H |
|
39 #include <sys/poll.h> |
|
40 #endif |
|
41 |
3620
|
42 #include <stdarg.h> |
|
43 #include <stdio.h> |
|
44 #include <stdlib.h> |
3350
|
45 #include <string.h> |
|
46 |
3317
|
47 static void |
|
48 do_octave_usleep (unsigned int useconds) |
3311
|
49 { |
|
50 #if defined (HAVE_USLEEP) |
|
51 |
|
52 usleep (useconds); |
|
53 |
|
54 #elif defined (HAVE_SELECT) |
|
55 |
|
56 struct timeval delay; |
|
57 |
|
58 delay.tv_sec = 0; |
|
59 delay.tv_usec = useconds; |
|
60 |
|
61 select (0, 0, 0, 0, &delay); |
|
62 |
|
63 #elif defined (HAVE_POLL) |
|
64 |
|
65 struct pollfd pfd; |
|
66 int delay = useconds / 1000; |
|
67 |
3317
|
68 if (delay > 0) |
|
69 poll (&fd, 0, delay); |
3311
|
70 |
|
71 #endif |
|
72 } |
|
73 |
3317
|
74 void |
4067
|
75 octave_sleep (unsigned int seconds) |
|
76 { |
|
77 sleep (seconds); |
|
78 } |
|
79 |
|
80 void |
3317
|
81 octave_usleep (unsigned int useconds) |
|
82 { |
|
83 unsigned int sec = useconds / 1000000; |
|
84 unsigned int usec = useconds % 1000000; |
|
85 |
|
86 if (sec > 0) |
|
87 sleep (sec); |
|
88 |
3318
|
89 do_octave_usleep (usec); |
3317
|
90 } |
|
91 |
3350
|
92 int |
|
93 octave_strcasecmp (const char *s1, const char *s2) |
|
94 { |
|
95 return strcasecmp (s1, s2); |
|
96 } |
|
97 |
|
98 int |
|
99 octave_strncasecmp (const char *s1, const char *s2, size_t n) |
|
100 { |
|
101 return strncasecmp (s1, s2, n); |
|
102 } |
|
103 |
3620
|
104 char * |
3623
|
105 octave_vsnprintf (const char *fmt, va_list args) |
3620
|
106 { |
|
107 #if defined (HAVE_VSNPRINTF) |
|
108 size_t size = 100; |
|
109 |
|
110 char *buf = malloc (size); |
|
111 |
|
112 while (1) |
|
113 { |
|
114 int nchars = vsnprintf (buf, size, fmt, args); |
|
115 |
|
116 if (nchars > -1) |
|
117 return buf; |
|
118 else |
|
119 { |
|
120 size *= 2; |
|
121 buf = realloc (buf, size); |
|
122 } |
|
123 } |
|
124 #else |
|
125 return 0; |
|
126 #endif |
|
127 } |
|
128 |
|
129 char * |
3623
|
130 octave_snprintf (const char *fmt, ...) |
3620
|
131 { |
|
132 char *retval = 0; |
|
133 |
|
134 va_list args; |
|
135 va_start (args, fmt); |
|
136 |
3625
|
137 retval = octave_vsnprintf (fmt, args); |
3620
|
138 |
|
139 va_end (args); |
|
140 |
|
141 return retval; |
|
142 } |
|
143 |
3311
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; End: *** |
|
148 */ |