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 |
|
75 octave_usleep (unsigned int useconds) |
|
76 { |
|
77 unsigned int sec = useconds / 1000000; |
|
78 unsigned int usec = useconds % 1000000; |
|
79 |
|
80 if (sec > 0) |
|
81 sleep (sec); |
|
82 |
3318
|
83 do_octave_usleep (usec); |
3317
|
84 } |
|
85 |
3350
|
86 int |
|
87 octave_strcasecmp (const char *s1, const char *s2) |
|
88 { |
|
89 return strcasecmp (s1, s2); |
|
90 } |
|
91 |
|
92 int |
|
93 octave_strncasecmp (const char *s1, const char *s2, size_t n) |
|
94 { |
|
95 return strncasecmp (s1, s2, n); |
|
96 } |
|
97 |
3620
|
98 char * |
3623
|
99 octave_vsnprintf (const char *fmt, va_list args) |
3620
|
100 { |
|
101 #if defined (HAVE_VSNPRINTF) |
|
102 size_t size = 100; |
|
103 |
|
104 char *buf = malloc (size); |
|
105 |
|
106 while (1) |
|
107 { |
|
108 int nchars = vsnprintf (buf, size, fmt, args); |
|
109 |
|
110 if (nchars > -1) |
|
111 return buf; |
|
112 else |
|
113 { |
|
114 size *= 2; |
|
115 buf = realloc (buf, size); |
|
116 } |
|
117 } |
|
118 #else |
|
119 return 0; |
|
120 #endif |
|
121 } |
|
122 |
|
123 char * |
3623
|
124 octave_snprintf (const char *fmt, ...) |
3620
|
125 { |
|
126 char *retval = 0; |
|
127 |
|
128 va_list args; |
|
129 va_start (args, fmt); |
|
130 |
3625
|
131 retval = octave_vsnprintf (fmt, args); |
3620
|
132 |
|
133 va_end (args); |
|
134 |
|
135 return retval; |
|
136 } |
|
137 |
3311
|
138 /* |
|
139 ;;; Local Variables: *** |
|
140 ;;; mode: C++ *** |
|
141 ;;; End: *** |
|
142 */ |