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