diff -u 32/files.c 33/files.c --- 32/files.c Thu Sep 5 20:51:49 2002 +++ 33/files.c Thu Sep 5 20:49:05 2002 @@ -1230,6 +1230,23 @@ #endif /* !DISABLE_SPELLER */ #ifndef DISABLE_OPERATINGDIR + +/* Initialize full_operating_dir based on operating_dir. */ +void init_operating_dir(void) +{ + assert(full_operating_dir == NULL); + full_operating_dir = get_full_path(operating_dir); + + /* If get_full_path() failed or the operating directory is + inaccessible, unset operating_dir. */ + if (!full_operating_dir || chdir(full_operating_dir) == -1) { + free(full_operating_dir); + full_operating_dir = NULL; + free(operating_dir); + operating_dir = NULL; + } +} + /* * Check to see if we're inside the operating directory. Return 0 if we * are, or 1 otherwise. If allow_tabcomp is nonzero, allow incomplete @@ -1251,40 +1268,6 @@ if (!operating_dir) return 0; - /* if the operating directory is "/", that's the same as having no - operating directory, so discard it and get out */ - if (!strcmp(operating_dir, "/")) { - free(operating_dir); - operating_dir = NULL; - return 0; - } - - /* get the full operating (if we don't have it already) and current - directories, and then search the current for the operating (for - normal usage) and the operating for the current (for tab - completion, if we're allowing it); if the current directory's path - doesn't exist, assume we're outside the operating directory */ - if (!full_operating_dir) { - full_operating_dir = get_full_path(operating_dir); - - /* if get_full_path() failed, discard the operating directory */ - if (!full_operating_dir) { - free(operating_dir); - operating_dir = NULL; - return 0; - } - - /* if the full operating directory is "/", that's the same as - having no operating directory, so discard it and get out */ - if (!strcmp(full_operating_dir, "/")) { - free(full_operating_dir); - full_operating_dir = NULL; - free(operating_dir); - operating_dir = NULL; - return 0; - } - } - fullpath = get_full_path(currpath); if (!fullpath) return 1; diff -u 32/nano.c 33/nano.c --- 32/nano.c Thu Sep 5 20:51:49 2002 +++ 33/nano.c Thu Sep 5 20:49:05 2002 @@ -3085,12 +3085,6 @@ #ifndef DISABLE_OPERATINGDIR case 'o': operating_dir = mallocstrcpy(operating_dir, optarg); - - /* make sure we're inside the operating directory */ - if (check_operating_dir(".", 0) && chdir(operating_dir) == -1) { - free(operating_dir); - operating_dir = NULL; - } break; #endif case 'p': @@ -3144,6 +3138,12 @@ } } +#ifndef DISABLE_OPERATINGDIR + /* Set up the operating directory. This entails chdir()ing there, so + that file reads and writes will be based there. */ + init_operating_dir(); +#endif + /* Clear the filename we'll be using */ filename = charalloc(1); filename[0] = '\0'; diff -u 32/proto.h 33/proto.h --- 32/proto.h Thu Sep 5 20:51:49 2002 +++ 33/proto.h Thu Sep 5 20:49:40 2002 @@ -136,6 +136,7 @@ int open_nextfile_void(void); #endif #ifndef DISABLE_OPERATINGDIR +void init_operating_dir(void); int check_operating_dir(const char *currpath, int allow_tabcomp); #endif int do_writeout(const char *path, int exiting, int append);