GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lo-cutils.c
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2000-2013 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "lo-error.h"
28 
29 /* This gives us a better chance of finding a prototype for strptime
30  on some systems. */
31 
32 #if ! defined (_XOPEN_SOURCE)
33 #define _XOPEN_SOURCE
34 #endif
35 
36 #include <sys/types.h>
37 #include <unistd.h>
38 
39 #include <stdlib.h>
40 #include <string.h>
41 #include <time.h>
42 
43 #include "lo-cutils.h"
44 #include "syswait.h"
45 
46 OCTAVE_API void
47 octave_qsort (void *base, size_t n, size_t size,
48  int (*cmp) (const void *, const void *))
49 {
50  qsort (base, n, size, cmp);
51 }
52 
53 OCTAVE_API int
54 octave_strcasecmp (const char *s1, const char *s2)
55 {
56  return strcasecmp (s1, s2);
57 }
58 
59 OCTAVE_API int
60 octave_strncasecmp (const char *s1, const char *s2, size_t n)
61 {
62  return strncasecmp (s1, s2, n);
63 }
64 
65 #ifdef HAVE_LOADLIBRARY_API
66 #include <windows.h>
67 
68 /* Need this since in C++ can't cast from int(*)() to void* */
69 OCTAVE_API void *
70 octave_w32_library_search (HINSTANCE handle, const char * name)
71 {
72  return (GetProcAddress (handle, name));
73 }
74 #endif
75 
76 OCTAVE_API pid_t
77 octave_waitpid (pid_t pid, int *status, int options)
78 {
79  return WAITPID (pid, status, options);
80 }
81 
82 static inline void
83 gripe_missing_wait_macro (const char *id, int status)
84 {
85  (*current_liboctave_warning_handler)
86  ("%s always returns false in this version of Octave; status = %d",
87  id, status);
88 }
89 
90 OCTAVE_API int
91 octave_wifexited (int status)
92 {
93  int retval = 0;
94 
95 #if defined (WIFEXITED)
96  retval = WIFEXITED (status);
97 #else
98  gripe_missing_wait_macro ("WIFEXITED", status);
99 #endif
100 
101  return retval;
102 }
103 
104 OCTAVE_API int
105 octave_wexitstatus (int status)
106 {
107  int retval = 0;
108 
109 #if defined (WEXITSTATUS)
110  retval = WEXITSTATUS (status);
111 #else
112  gripe_missing_wait_macro ("WEXITSTATUS", status);
113 #endif
114 
115  return retval;
116 }
117 
118 OCTAVE_API int
119 octave_wifsignaled (int status)
120 {
121  int retval = 0;
122 
123 #if defined (WIFSIGNALED)
124  retval = WIFSIGNALED (status);
125 #else
126  gripe_missing_wait_macro ("WIFSIGNALED", status);
127 #endif
128 
129  return retval;
130 }
131 
132 OCTAVE_API int
133 octave_wtermsig (int status)
134 {
135  int retval = 0;
136 
137 #if defined (WTERMSIG)
138  retval = WTERMSIG (status);
139 #else
140  gripe_missing_wait_macro ("WTERMSIG", status);
141 #endif
142 
143  return retval;
144 }
145 
146 OCTAVE_API int
147 octave_wcoredump (int status)
148 {
149  int retval = 0;
150 
151 #if defined (WCOREDUMP)
152  retval = WCOREDUMP (status);
153 #else
154  gripe_missing_wait_macro ("WCOREDUMP", status);
155 #endif
156 
157  return retval;
158 }
159 
160 OCTAVE_API int
161 octave_wifstopped (int status)
162 {
163  int retval = 0;
164 
165 #if defined (WIFSTOPPED)
166  retval = WIFSTOPPED (status);
167 #else
168  gripe_missing_wait_macro ("WIFSTOPPED", status);
169 #endif
170 
171  return retval;
172 }
173 
174 OCTAVE_API int
175 octave_wstopsig (int status)
176 {
177  int retval = 0;
178 
179 #if defined (WSTOPSIG)
180  retval = WSTOPSIG (status);
181 #else
182  gripe_missing_wait_macro ("WSTOPSIG", status);
183 #endif
184 
185  return retval;
186 }
187 
188 OCTAVE_API int
190 {
191  int retval = 0;
192 
193 #if defined (WIFCONTINUED)
194  retval = WIFCONTINUED (status);
195 #else
196  gripe_missing_wait_macro ("WIFCONTINUED", status);
197 #endif
198 
199  return retval;
200 }