diff --git a/src/buf.c b/src/buf.c index 8c24892..55d0a78 100644 --- a/src/buf.c +++ b/src/buf.c @@ -1,6 +1,6 @@ /* buf.c: Buffer routines for the ed line editor. * - * Copyright © 1993-2022 Andrew L. Moore, SlewSys Research + * Copyright © 1993-2024 Andrew L. Moore, SlewSys Research * * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-or-later OR MIT */ @@ -193,8 +193,8 @@ init_ed_command (int init_glob, ed_buffer_t *ed) /* File info */ #ifdef WANT_FILE_LOCK - /* GNU/Linux double-frees on fclose() here... */ -#if __linux__ + /* XXX: GNU/Linux double-frees on fclose(). */ +#ifndef __linux__ if (ed->file->handle) /* Assert: No writes since fopen(3). */ diff --git a/src/io.c b/src/io.c index 60f5c98..a7c9738 100644 --- a/src/io.c +++ b/src/io.c @@ -1,6 +1,6 @@ /* io.c: I/O routines for the ed line editor. * - * Copyright © 1993-2022 Andrew L. Moore, SlewSys Research + * Copyright © 1993-2024 Andrew L. Moore, SlewSys Research * * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-or-later OR MIT */ @@ -615,7 +615,8 @@ write_file (const char *fn, int is_default, off_t from, off_t to, * File-locking requires file write access, so this case should not * be reached. */ - else if (file_already_open && fclose (ed->file->handle) < 0) + else if (file_already_open + && (fclose (ed->file->handle) < 0 || !(ed->file->handle = NULL))) { fprintf (stderr, "%s: %s\n", ed->file->name, strerror (errno)); ed->exec->err = _("File close error"); diff --git a/src/main.c b/src/main.c index fb7891b..546687b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ /* main.c: Entry point for the ed line editor. * - * Copyright © 1993-2023 Andrew L. Moore, SlewSys Research + * Copyright © 1993-2024 Andrew L. Moore, SlewSys Research * * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-or-later OR MIT */ @@ -410,6 +410,13 @@ main (int argc, char **argv) goto error; #endif + /* Command-line files still available and stdin seekable... */ + if (ed->file->list->gl_offs && ed->file->list->gl_pathc > 1 + && FSEEK(stdin, 0L, SEEK_SET) != -1) + { + status = EOF_NEXT; + goto next; + } quit (ed->exec->status, ed); case EMOD: ed->exec->err = _("WARNING: Buffer modified since last write");