From 1a6e904583e14276b97a76a1e6978292a44f6c5d Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Thu, 14 Dec 2000 13:56:28 +0000 Subject: [PATCH] Rid nano of PATH_MAX\! git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@409 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 ++++-- files.c | 16 +++++++--------- global.c | 2 +- nano.c | 17 ++++++++++++----- proto.h | 2 +- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index a79f2de7..41bb6ff6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ CVS code - General - Added --disable-help option, affects acconfig.h, configure(.in), winio.c:do_help, nano.c:help_init,help_text_init. + - Changed filename to no longer use PATH_MAX, so it can work on the + HURD. Changes in files.c:write_file(), new function + nano.c:clear_filename(), many changed in main(), a few other + places. Please test this! - cut.c: do_uncut_text() - Fix renumbering bug when uncutting marked test at filebot. @@ -14,8 +18,6 @@ General - Change open call flags, basically copy joe's way of doing it so a more recent version will actually be included in (un)stable. - Remove useless fstat call. - - Use MAX_PATH instead of static 132 for strncpy, at least until - we no longer use MAX_PATH. open_file() - Added check for S_ISBLK and S_ISCHR, don't open device files! - nano.c: diff --git a/files.c b/files.c index 4f556a35..18f65211 100644 --- a/files.c +++ b/files.c @@ -306,7 +306,7 @@ int do_insertfile(void) int write_file(char *name, int tmp) { long size, lineswritten = 0; - char buf[PATH_MAX + 1]; + static char *buf = NULL; filestruct *fileptr; int fd, mask = 0, realexists, anyexists; struct stat st, lst; @@ -322,6 +322,9 @@ int write_file(char *name, int tmp) if (realname != NULL) free(realname); + if (buf != NULL) + free(buf); + #ifndef DISABLE_TABCOMP realname = real_dir_from_tilde(name); #else @@ -365,13 +368,8 @@ int write_file(char *name, int tmp) } /* Don't follow symlink. Create new file. */ else { - if (strlen(realname) > (PATH_MAX - 7)) { - statusbar(_("Could not open file: Path length exceeded.")); - return -1; - } - - memset(buf, 0x00, PATH_MAX + 1); - strcat(buf, realname); + buf = nmalloc(strlen(realname) + 8); + strncpy(buf, realname, strlen(realname)+1); strcat(buf, ".XXXXXX"); if ((fd = mkstemp(buf)) == -1) { if (ISSET(TEMP_OPT)) { @@ -472,7 +470,7 @@ int write_file(char *name, int tmp) mask, realname, strerror(errno)); if (!tmp) { - strncpy(filename, realname, PATH_MAX - 1); + filename = mallocstrcpy(filename, realname); statusbar(_("Wrote %d lines"), lineswritten); UNSET(MODIFIED); titlebar(); diff --git a/global.c b/global.c index 6366cf29..b7c6773b 100644 --- a/global.c +++ b/global.c @@ -39,7 +39,7 @@ int center_x = 0, center_y = 0; /* Center of screen */ WINDOW *edit; /* The file portion of the editor */ WINDOW *topwin; /* Top line of screen */ WINDOW *bottomwin; /* Bottom buffer */ -char filename[PATH_MAX]; /* Name of the file */ +char *filename = NULL; /* Name of the file */ int editwinrows = 0; /* How many rows long is the edit window? */ filestruct *current; /* Current buffer pointer */ diff --git a/nano.c b/nano.c index 89110e94..12e3ba4c 100644 --- a/nano.c +++ b/nano.c @@ -146,6 +146,13 @@ void print_view_warning(void) statusbar(_("Key illegal in VIEW mode")); } +void clear_filename(void) +{ + if (filename != NULL) + free(filename); + filename = nmalloc(1); + filename[0] = 0; +} /* Initialize global variables - no better way for now */ void global_init(void) @@ -2161,19 +2168,19 @@ int main(int argc, char *argv[]) /* See if there's a non-option in argv (first non-option is the filename, if +LINE is not given) */ if (argc == 1 || argc <= optind) - strcpy(filename, ""); + clear_filename(); else { /* Look for the +line flag... */ if (argv[optind][0] == '+') { startline = atoi(&argv[optind][1]); optind++; if (argc == 1 || argc <= optind) - strcpy(filename, ""); + clear_filename(); else - strncpy(filename, argv[optind], 132); - } else - strncpy(filename, argv[optind], 132); + filename = mallocstrcpy(filename, argv[optind]); + } else + filename = mallocstrcpy(filename, argv[optind]); } diff --git a/proto.h b/proto.h index fe22fea2..22f91b7d 100644 --- a/proto.h +++ b/proto.h @@ -38,7 +38,7 @@ extern int fill, flags,tabsize; extern int search_last_line; extern WINDOW *edit, *topwin, *bottomwin; -extern char filename[PATH_MAX]; +extern char *filename; extern char *answer; extern char *hblank, *help_text; extern char *last_search;