summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2019-10-23 12:45:08 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2019-10-23 12:45:08 -0700
commit0741eb600481a97c3baddb290e0ab1a33a9e4921 (patch)
treea3bfe8535ad4b6b57fc226719737c6ef103f63f6
parent4b58ec1b8f7626517077a70049805878b3dcd50b (diff)
downloadnasm-0741eb600481a97c3baddb290e0ab1a33a9e4921.tar.gz
listing: make it possible to flush the listing output after every line
Add the -Lw option to flush the list file after every line output. This is handy for debugging if nasm hangs. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
-rw-r--r--asm/listing.c7
-rw-r--r--asm/nasm.c1
-rw-r--r--include/nasmlib.h8
-rw-r--r--nasmlib/file.c14
4 files changed, 27 insertions, 3 deletions
diff --git a/asm/listing.c b/asm/listing.c
index 3101a258..9b101ff4 100644
--- a/asm/listing.c
+++ b/asm/listing.c
@@ -148,6 +148,8 @@ static void list_cleanup(void)
static void list_init(const char *fname)
{
+ enum file_flags flags = NF_TEXT;
+
if (listfp)
list_cleanup();
@@ -156,7 +158,10 @@ static void list_init(const char *fname)
return;
}
- listfp = nasm_open_write(fname, NF_TEXT);
+ if (list_option('w'))
+ flags |= NF_IOLBF;
+
+ listfp = nasm_open_write(fname, flags);
if (!listfp) {
nasm_nonfatal("unable to open listing file `%s'", fname);
return;
diff --git a/asm/nasm.c b/asm/nasm.c
index 07a360b2..a30831dc 100644
--- a/asm/nasm.c
+++ b/asm/nasm.c
@@ -2067,6 +2067,7 @@ static void help(FILE *out)
" -Lm show multi-line macro calls with expanded parmeters\n"
" -Lp output a list file every pass, in case of errors\n"
" -Ls show all single-line macro definitions\n"
+ " -Lw flush the output after every line\n"
" -L+ enable all listing options (very verbose!)\n"
"\n"
" -Oflags... optimize opcodes, immediates and branch offsets\n"
diff --git a/include/nasmlib.h b/include/nasmlib.h
index 2e2519f5..940f1cb7 100644
--- a/include/nasmlib.h
+++ b/include/nasmlib.h
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 1996-2018 The NASM Authors - All Rights Reserved
+ * Copyright 1996-2019 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -355,8 +355,12 @@ enum file_flags {
NF_TEXT = 0x00000001, /* Text file */
NF_NONFATAL = 0x00000000, /* Don't die on open failure (default) */
NF_FATAL = 0x00000002, /* Die on open failure */
- NF_FORMAP = 0x00000004 /* Intended to use nasm_map_file() */
+ NF_FORMAP = 0x00000004, /* Intended to use nasm_map_file() */
+ NF_IONBF = 0x00000010, /* Force unbuffered stdio */
+ NF_IOLBF = 0x00000020, /* Force line buffered stdio */
+ NF_IOFBF = 0000000030 /* Force fully buffered stdio */
};
+#define NF_BUF_MASK 0x30
FILE *nasm_open_read(const char *filename, enum file_flags flags);
FILE *nasm_open_write(const char *filename, enum file_flags flags);
diff --git a/nasmlib/file.c b/nasmlib/file.c
index e5c0e335..a8cd3057 100644
--- a/nasmlib/file.c
+++ b/nasmlib/file.c
@@ -210,6 +210,20 @@ FILE *nasm_open_write(const char *filename, enum file_flags flags)
nasm_fatalf(ERR_NOFILE, "unable to open output file: `%s': %s",
filename, strerror(errno));
+ switch (flags & NF_BUF_MASK) {
+ case NF_IONBF:
+ setvbuf(f, NULL, _IONBF, 0);
+ break;
+ case NF_IOLBF:
+ setvbuf(f, NULL, _IOLBF, 0);
+ break;
+ case NF_IOFBF:
+ setvbuf(f, NULL, _IOFBF, 0);
+ break;
+ default:
+ break;
+ }
+
return f;
}