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 |
3069
|
50 #include "lo-error.h" |
2926
|
51 #include "pathlen.h" |
|
52 |
|
53 string |
|
54 octave_getcwd (void) |
|
55 { |
|
56 string retval; |
3069
|
57 |
2926
|
58 char buf[MAXPATHLEN]; |
|
59 |
3069
|
60 char *tmp = 0; |
|
61 |
2926
|
62 #if defined (__EMX__) |
3069
|
63 tmp = _getcwd2 (buf, MAXPATHLEN); |
|
64 #elif defined (HAVE_GETWD) |
|
65 tmp = getwd (buf); |
|
66 #elif defined (HAVE_GETCWD) |
|
67 tmp = getcwd (buf, MAXPATHLEN); |
2926
|
68 #endif |
|
69 |
|
70 if (tmp) |
|
71 retval = tmp; |
3069
|
72 else |
|
73 (*current_liboctave_error_handler) ("unable to find current directory"); |
2926
|
74 |
|
75 return retval; |
|
76 } |
|
77 |
|
78 int |
|
79 octave_chdir (const string& path) |
|
80 { |
|
81 #if defined (__EMX__) |
|
82 int retval = -1; |
|
83 |
|
84 char *tmp_path = strsave (path.c_str ()); |
|
85 |
|
86 if (path.length () == 2 && path[1] == ':') |
|
87 { |
|
88 char *upper_case_dir_name = strupr (tmp_path); |
|
89 _chdrive (upper_case_dir_name[0]); |
|
90 if (_getdrive () == upper_case_dir_name[0]) |
|
91 retval = _chdir2 ("/"); |
|
92 } |
|
93 else |
|
94 retval = _chdir2 (tmp_path); |
|
95 |
|
96 delete [] tmp_path; |
|
97 |
|
98 return retval; |
|
99 #else |
|
100 return chdir (path.c_str ()); |
|
101 #endif |
|
102 } |
|
103 |
|
104 #if ! defined (HAVE_GETHOSTNAME) && defined (HAVE_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 |
|
124 /* |
|
125 ;;; Local Variables: *** |
|
126 ;;; mode: C++ *** |
|
127 ;;; End: *** |
|
128 */ |