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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2926
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
2926
|
29 #include <string> |
|
30 |
|
31 #ifdef HAVE_UNISTD_H |
|
32 #ifdef HAVE_SYS_TYPES_H |
|
33 #include <sys/types.h> |
|
34 #endif |
|
35 #include <unistd.h> |
|
36 #endif |
|
37 |
3069
|
38 #include "lo-error.h" |
2926
|
39 #include "pathlen.h" |
|
40 |
3504
|
41 std::string |
2926
|
42 octave_getcwd (void) |
|
43 { |
3504
|
44 std::string retval; |
3069
|
45 |
2926
|
46 char buf[MAXPATHLEN]; |
|
47 |
3069
|
48 char *tmp = 0; |
|
49 |
2926
|
50 #if defined (__EMX__) |
3069
|
51 tmp = _getcwd2 (buf, MAXPATHLEN); |
3112
|
52 #elif defined (HAVE_GETCWD) |
|
53 tmp = getcwd (buf, MAXPATHLEN); |
3069
|
54 #elif defined (HAVE_GETWD) |
|
55 tmp = getwd (buf); |
2926
|
56 #endif |
|
57 |
|
58 if (tmp) |
|
59 retval = tmp; |
3069
|
60 else |
|
61 (*current_liboctave_error_handler) ("unable to find current directory"); |
2926
|
62 |
|
63 return retval; |
|
64 } |
|
65 |
|
66 int |
3504
|
67 octave_chdir (const std::string& path) |
2926
|
68 { |
|
69 #if defined (__EMX__) |
|
70 int retval = -1; |
|
71 |
|
72 char *tmp_path = strsave (path.c_str ()); |
|
73 |
|
74 if (path.length () == 2 && path[1] == ':') |
|
75 { |
|
76 char *upper_case_dir_name = strupr (tmp_path); |
|
77 _chdrive (upper_case_dir_name[0]); |
|
78 if (_getdrive () == upper_case_dir_name[0]) |
|
79 retval = _chdir2 ("/"); |
|
80 } |
|
81 else |
|
82 retval = _chdir2 (tmp_path); |
|
83 |
|
84 delete [] tmp_path; |
|
85 |
|
86 return retval; |
|
87 #else |
|
88 return chdir (path.c_str ()); |
|
89 #endif |
|
90 } |
|
91 |
|
92 /* |
|
93 ;;; Local Variables: *** |
|
94 ;;; mode: C++ *** |
|
95 ;;; End: *** |
|
96 */ |