2926
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 /* |
|
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 |
|
31 #ifdef HAVE_CONFIG_H |
|
32 #include <config.h> |
|
33 #endif |
|
34 |
|
35 #include <string> |
|
36 |
|
37 #include <iostream.h> |
|
38 |
|
39 #ifdef HAVE_UNISTD_H |
|
40 #ifdef HAVE_SYS_TYPES_H |
|
41 #include <sys/types.h> |
|
42 #endif |
|
43 #include <unistd.h> |
|
44 #endif |
|
45 |
|
46 #if ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H) |
|
47 #include <sys/utsname.h> |
|
48 #endif |
|
49 |
|
50 #include "pathlen.h" |
|
51 |
|
52 string |
|
53 octave_getcwd (void) |
|
54 { |
|
55 string retval; |
|
56 char buf[MAXPATHLEN]; |
|
57 |
|
58 #if defined (__EMX__) |
|
59 char *tmp = _getcwd2 (buf, MAXPATHLEN); |
|
60 #else |
|
61 char *tmp = getcwd (buf, MAXPATHLEN); |
|
62 #endif |
|
63 |
|
64 if (tmp) |
|
65 retval = tmp; |
|
66 |
|
67 return retval; |
|
68 } |
|
69 |
|
70 int |
|
71 octave_chdir (const string& path) |
|
72 { |
|
73 #if defined (__EMX__) |
|
74 int retval = -1; |
|
75 |
|
76 char *tmp_path = strsave (path.c_str ()); |
|
77 |
|
78 if (path.length () == 2 && path[1] == ':') |
|
79 { |
|
80 char *upper_case_dir_name = strupr (tmp_path); |
|
81 _chdrive (upper_case_dir_name[0]); |
|
82 if (_getdrive () == upper_case_dir_name[0]) |
|
83 retval = _chdir2 ("/"); |
|
84 } |
|
85 else |
|
86 retval = _chdir2 (tmp_path); |
|
87 |
|
88 delete [] tmp_path; |
|
89 |
|
90 return retval; |
|
91 #else |
|
92 return chdir (path.c_str ()); |
|
93 #endif |
|
94 } |
|
95 |
|
96 #if ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H) |
|
97 |
|
98 int |
|
99 gethostname (char *name, int namelen) |
|
100 { |
|
101 int i; |
|
102 struct utsname ut; |
|
103 |
|
104 --namelen; |
|
105 |
|
106 uname (&ut); |
|
107 i = strlen (ut.nodename) + 1; |
|
108 strncpy (name, ut.nodename, i < namelen ? i : namelen); |
|
109 name[namelen] = '\0'; |
|
110 |
|
111 return 0; |
|
112 } |
|
113 |
|
114 #endif |
|
115 |
|
116 /* |
|
117 ;;; Local Variables: *** |
|
118 ;;; mode: C++ *** |
|
119 ;;; End: *** |
|
120 */ |