3613
|
1 /* |
|
2 |
|
3 Copyright (C) 2000 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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3613
|
21 |
|
22 */ |
|
23 |
3803
|
24 /* |
|
25 |
|
26 The function gethostname was adapted from a similar function from GNU |
|
27 Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free |
|
28 Software Foundation, Inc. |
|
29 |
|
30 */ |
|
31 |
3613
|
32 #ifdef HAVE_CONFIG_H |
|
33 #include <config.h> |
|
34 #endif |
|
35 |
4290
|
36 /* This gives us a better chance of finding a prototype for strptime |
|
37 on some systems. */ |
|
38 |
|
39 #if ! defined (_XOPEN_SOURCE) |
|
40 #define _XOPEN_SOURCE |
|
41 #endif |
|
42 |
3803
|
43 #ifdef HAVE_UNISTD_H |
|
44 #ifdef HAVE_SYS_TYPES_H |
|
45 #include <sys/types.h> |
|
46 #endif |
|
47 #include <unistd.h> |
|
48 #endif |
|
49 |
3613
|
50 #include <stdlib.h> |
3803
|
51 #include <string.h> |
3706
|
52 #include <time.h> |
3613
|
53 |
|
54 void |
|
55 octave_qsort (void *base, size_t n, size_t size, |
|
56 int (*cmp) (const void *, const void *)) |
|
57 { |
|
58 qsort (base, n, size, cmp); |
|
59 } |
|
60 |
3706
|
61 char * |
|
62 oct_strptime (const char *buf, const char *format, struct tm *tm) |
|
63 { |
3786
|
64 return (char *) strptime (buf, format, tm); |
3706
|
65 } |
|
66 |
4093
|
67 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
68 |
|
69 #include <winsock.h> |
|
70 |
|
71 #elif ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H) |
3707
|
72 |
3803
|
73 #include <sys/utsname.h> |
|
74 |
|
75 int |
|
76 gethostname (char *name, int namelen) |
|
77 { |
|
78 int i; |
|
79 struct utsname ut; |
|
80 |
|
81 --namelen; |
|
82 |
|
83 uname (&ut); |
|
84 i = strlen (ut.nodename) + 1; |
|
85 strncpy (name, ut.nodename, i < namelen ? i : namelen); |
|
86 name[namelen] = '\0'; |
|
87 |
|
88 return 0; |
|
89 } |
|
90 |
|
91 #endif |
|
92 |
|
93 int |
|
94 octave_gethostname (char *name, int namelen) |
|
95 { |
|
96 return gethostname (name, namelen); |
|
97 } |
3707
|
98 |
3613
|
99 /* |
|
100 ;;; Local Variables: *** |
|
101 ;;; mode: C++ *** |
|
102 ;;; End: *** |
|
103 */ |