Mercurial > hg > octave-lyh
annotate liboctave/lo-cutils.c @ 10180:be952ce74023
bootstrap.conf fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 21 Jan 2010 03:25:23 -0500 |
parents | 6bd86b6287b1 |
children | 0522a65bcd56 |
rev | line source |
---|---|
3613 | 1 /* |
2 | |
7017 | 3 Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006, 2007 John W. Eaton |
3613 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3613 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3613 | 20 |
21 */ | |
22 | |
3803 | 23 /* |
24 | |
25 The function gethostname was adapted from a similar function from GNU | |
26 Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free | |
27 Software Foundation, Inc. | |
28 | |
29 */ | |
30 | |
3613 | 31 #ifdef HAVE_CONFIG_H |
32 #include <config.h> | |
33 #endif | |
34 | |
4290 | 35 /* This gives us a better chance of finding a prototype for strptime |
36 on some systems. */ | |
37 | |
38 #if ! defined (_XOPEN_SOURCE) | |
39 #define _XOPEN_SOURCE | |
40 #endif | |
41 | |
3803 | 42 #ifdef HAVE_UNISTD_H |
43 #ifdef HAVE_SYS_TYPES_H | |
44 #include <sys/types.h> | |
45 #endif | |
46 #include <unistd.h> | |
47 #endif | |
48 | |
3613 | 49 #include <stdlib.h> |
3803 | 50 #include <string.h> |
3706 | 51 #include <time.h> |
3613 | 52 |
5453 | 53 #include "syswait.h" |
54 | |
10172
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
55 OCTAVE_API int |
10175
d354be89b2c3
use link module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10174
diff
changeset
|
56 octave_link (const char *old_name, const char *new_name) |
d354be89b2c3
use link module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10174
diff
changeset
|
57 { |
d354be89b2c3
use link module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10174
diff
changeset
|
58 return link (old_name, new_name); |
d354be89b2c3
use link module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10174
diff
changeset
|
59 } |
d354be89b2c3
use link module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10174
diff
changeset
|
60 |
d354be89b2c3
use link module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10174
diff
changeset
|
61 OCTAVE_API int |
10176
a0665fa8798c
use symlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10175
diff
changeset
|
62 octave_symlink (const char *old_name, const char *new_name) |
a0665fa8798c
use symlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10175
diff
changeset
|
63 { |
a0665fa8798c
use symlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10175
diff
changeset
|
64 return symlink (old_name, new_name); |
a0665fa8798c
use symlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10175
diff
changeset
|
65 } |
a0665fa8798c
use symlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10175
diff
changeset
|
66 |
a0665fa8798c
use symlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10175
diff
changeset
|
67 OCTAVE_API int |
10177
cb3d926b4d9e
use readlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10176
diff
changeset
|
68 octave_readlink (const char *name, char *buf, size_t size) |
cb3d926b4d9e
use readlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10176
diff
changeset
|
69 { |
cb3d926b4d9e
use readlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10176
diff
changeset
|
70 return readlink (name, buf, size); |
cb3d926b4d9e
use readlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10176
diff
changeset
|
71 } |
cb3d926b4d9e
use readlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10176
diff
changeset
|
72 |
cb3d926b4d9e
use readlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10176
diff
changeset
|
73 OCTAVE_API int |
10172
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
74 octave_mkdir (const char *name, mode_t mode) |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
75 { |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
76 return mkdir (name, mode); |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
77 } |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
78 |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
79 OCTAVE_API int |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
80 octave_mkfifo (const char *name, mode_t mode) |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
81 { |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
82 return mkfifo (name, mode); |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
83 } |
96ed9db3345c
provide wrappers for mkdir and mkfifo
John W. Eaton <jwe@octave.org>
parents:
10170
diff
changeset
|
84 |
6108 | 85 OCTAVE_API void |
3613 | 86 octave_qsort (void *base, size_t n, size_t size, |
10180 | 87 int (*cmp) (const void *, const void *)) |
3613 | 88 { |
89 qsort (base, n, size, cmp); | |
90 } | |
91 | |
6108 | 92 OCTAVE_API char * |
3706 | 93 oct_strptime (const char *buf, const char *format, struct tm *tm) |
94 { | |
3786 | 95 return (char *) strptime (buf, format, tm); |
3706 | 96 } |
97 | |
4093 | 98 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
99 | |
100 #include <winsock.h> | |
101 | |
102 #elif ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H) | |
3707 | 103 |
3803 | 104 #include <sys/utsname.h> |
105 | |
106 int | |
107 gethostname (char *name, int namelen) | |
108 { | |
109 int i; | |
110 struct utsname ut; | |
111 | |
112 --namelen; | |
113 | |
114 uname (&ut); | |
115 i = strlen (ut.nodename) + 1; | |
116 strncpy (name, ut.nodename, i < namelen ? i : namelen); | |
117 name[namelen] = '\0'; | |
118 | |
119 return 0; | |
120 } | |
121 | |
122 #endif | |
123 | |
6108 | 124 OCTAVE_API int |
10169
06bd6e57f889
use rmdir module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
125 octave_rmdir (const char *name) |
06bd6e57f889
use rmdir module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
126 { |
06bd6e57f889
use rmdir module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
127 return rmdir (name); |
06bd6e57f889
use rmdir module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
128 } |
06bd6e57f889
use rmdir module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
129 |
06bd6e57f889
use rmdir module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
130 OCTAVE_API int |
10170
1dffc8b2fca7
use rename module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10169
diff
changeset
|
131 octave_rename (const char *from, const char *to) |
1dffc8b2fca7
use rename module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10169
diff
changeset
|
132 { |
1dffc8b2fca7
use rename module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10169
diff
changeset
|
133 return rename (from, to); |
1dffc8b2fca7
use rename module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10169
diff
changeset
|
134 } |
1dffc8b2fca7
use rename module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10169
diff
changeset
|
135 |
1dffc8b2fca7
use rename module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10169
diff
changeset
|
136 OCTAVE_API int |
6111 | 137 octave_strcasecmp (const char *s1, const char *s2) |
138 { | |
139 return strcasecmp (s1, s2); | |
140 } | |
141 | |
142 OCTAVE_API int | |
143 octave_strncasecmp (const char *s1, const char *s2, size_t n) | |
144 { | |
145 return strncasecmp (s1, s2, n); | |
146 } | |
147 | |
10178
6bd86b6287b1
provide wrapper for tempnam
John W. Eaton <jwe@octave.org>
parents:
10177
diff
changeset
|
148 OCTAVE_API char * |
6bd86b6287b1
provide wrapper for tempnam
John W. Eaton <jwe@octave.org>
parents:
10177
diff
changeset
|
149 octave_tempnam (const char *pdir, const char *ppfx) |
6bd86b6287b1
provide wrapper for tempnam
John W. Eaton <jwe@octave.org>
parents:
10177
diff
changeset
|
150 { |
6bd86b6287b1
provide wrapper for tempnam
John W. Eaton <jwe@octave.org>
parents:
10177
diff
changeset
|
151 return tempnam (pdir, ppfx); |
6bd86b6287b1
provide wrapper for tempnam
John W. Eaton <jwe@octave.org>
parents:
10177
diff
changeset
|
152 } |
6bd86b6287b1
provide wrapper for tempnam
John W. Eaton <jwe@octave.org>
parents:
10177
diff
changeset
|
153 |
10173 | 154 OCTAVE_API mode_t |
155 octave_umask (mode_t mode) | |
156 { | |
157 #if defined (HAVE_UMASK) | |
158 return umask (mode); | |
159 #else | |
160 return 0; | |
161 #endif | |
162 } | |
163 | |
6111 | 164 OCTAVE_API int |
10174
eb64bf1c6107
use unlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10173
diff
changeset
|
165 octave_unlink (const char *name) |
eb64bf1c6107
use unlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10173
diff
changeset
|
166 { |
eb64bf1c6107
use unlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10173
diff
changeset
|
167 return unlink (name); |
eb64bf1c6107
use unlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10173
diff
changeset
|
168 } |
eb64bf1c6107
use unlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10173
diff
changeset
|
169 |
eb64bf1c6107
use unlink module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10173
diff
changeset
|
170 OCTAVE_API int |
3803 | 171 octave_gethostname (char *name, int namelen) |
172 { | |
173 return gethostname (name, namelen); | |
174 } | |
3707 | 175 |
5451 | 176 #ifdef HAVE_LOADLIBRARY_API |
177 #include <windows.h> | |
178 | |
179 /* Need this since in C++ can't cast from int(*)() to void* */ | |
6108 | 180 OCTAVE_API void * |
5453 | 181 octave_w32_library_search (HINSTANCE handle, const char * name) |
5451 | 182 { |
183 return (GetProcAddress (handle, name)); | |
184 } | |
185 #endif | |
186 | |
6108 | 187 OCTAVE_API pid_t |
5453 | 188 octave_waitpid (pid_t pid, int *status, int options) |
189 { | |
190 return WAITPID (pid, status, options); | |
191 } |