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