=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/edit.c,v retrieving revision 1.1.1.2 retrieving revision 1.1.1.3 diff -u -r1.1.1.2 -r1.1.1.3 --- src/usr.bin/less/edit.c 2003/04/13 18:21:21 1.1.1.2 +++ src/usr.bin/less/edit.c 2011/09/16 17:47:04 1.1.1.3 @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2002 Mark Nudelman + * Copyright (C) 1984-2011 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -10,6 +10,9 @@ #include "less.h" +#if HAVE_STAT +#include +#endif public int fd0 = 0; @@ -36,6 +39,11 @@ extern char *namelogfile; #endif +#if HAVE_STAT_INO +public dev_t curr_dev; +public ino_t curr_ino; +#endif + char *curr_altfilename = NULL; static void *curr_altpipe; @@ -178,6 +186,9 @@ curr_altfilename = NULL; } curr_ifile = NULL_IFILE; +#if HAVE_STAT_INO + curr_ino = curr_dev = 0; +#endif } /* @@ -322,6 +333,14 @@ /* * Re-open the current file. */ + if (was_curr_ifile == ifile) + { + /* + * Whoops. The "current" ifile is the one we just deleted. + * Just give up. + */ + quit(QUIT_ERROR); + } reedit_ifile(was_curr_ifile); return (1); } else if ((f = open(qopen_filename, OPEN_READ)) < 0) @@ -352,7 +371,6 @@ } } } - free(qopen_filename); /* * Get the new ifile. @@ -377,10 +395,23 @@ if (namelogfile != NULL && is_tty) use_logfile(namelogfile); #endif +#if HAVE_STAT_INO + /* Remember the i-number and device of the opened file. */ + { + struct stat statbuf; + int r = stat(qopen_filename, &statbuf); + if (r == 0) + { + curr_ino = statbuf.st_ino; + curr_dev = statbuf.st_dev; + } + } +#endif if (every_first_cmd != NULL) ungetsc(every_first_cmd); } + free(qopen_filename); no_display = !any_display; flush(); any_display = TRUE; @@ -498,7 +529,7 @@ /* - * Edit the next or previous file in the command line (ifile) list. + * Edit the n-th next or previous file in the command line (ifile) list. */ static int edit_istep(h, n, dir) @@ -547,14 +578,14 @@ IFILE h; int n; { - return (edit_istep(h, n, 1)); + return (edit_istep(h, n, +1)); } public int edit_next(n) int n; { - return edit_istep(curr_ifile, n, 1); + return edit_istep(curr_ifile, n, +1); } static int @@ -649,6 +680,14 @@ quit(QUIT_ERROR); } + public void +reopen_curr_ifile() +{ + IFILE save_ifile = save_curr_ifile(); + close_file(); + reedit_ifile(save_ifile); +} + /* * Edit standard input. */ @@ -739,7 +778,7 @@ * Append: open the file and seek to the end. */ logfile = open(filename, OPEN_APPEND); - if (lseek(logfile, (off_t)0, 2) == BAD_LSEEK) + if (lseek(logfile, (off_t)0, SEEK_END) == BAD_LSEEK) { close(logfile); logfile = -1;