00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include <iostream>
00028 #include <string>
00029
00030 #ifdef HAVE_UNISTD_H
00031 #ifdef HAVE_SYS_TYPES_H
00032 #include <sys/types.h>
00033 #endif
00034 #include <unistd.h>
00035 #endif
00036
00037 #include "lo-error.h"
00038 #include "pathlen.h"
00039
00040 std::string
00041 octave_getcwd (void)
00042 {
00043 std::string retval;
00044
00045 char buf[MAXPATHLEN];
00046
00047 char *tmp = 0;
00048
00049 #if defined (__EMX__)
00050 tmp = _getcwd2 (buf, MAXPATHLEN);
00051 #elif defined (HAVE_GETCWD)
00052 tmp = getcwd (buf, MAXPATHLEN);
00053 #elif defined (HAVE_GETWD)
00054 tmp = getwd (buf);
00055 #endif
00056
00057 if (tmp)
00058 retval = tmp;
00059 else
00060 (*current_liboctave_error_handler) ("unable to find current directory");
00061
00062 return retval;
00063 }
00064
00065 int
00066 octave_chdir (const std::string& path)
00067 {
00068 #if defined (__EMX__)
00069 int retval = -1;
00070
00071 char *tmp_path = strsave (path.c_str ());
00072
00073 if (path.length () == 2 && path[1] == ':')
00074 {
00075 char *upper_case_dir_name = strupr (tmp_path);
00076 _chdrive (upper_case_dir_name[0]);
00077 if (_getdrive () == upper_case_dir_name[0])
00078 retval = _chdir2 ("/");
00079 }
00080 else
00081 retval = _chdir2 (tmp_path);
00082
00083 delete [] tmp_path;
00084
00085 return retval;
00086 #else
00087 return chdir (path.c_str ());
00088 #endif
00089 }
00090
00091
00092
00093
00094
00095