summaryrefslogtreecommitdiff
path: root/src/input.h
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2020-12-08 00:12:36 +0000
committerAdrian Thurston <thurston@colm.net>2020-12-08 00:12:36 +0000
commitfe0e546c65accd2e9ca0fa5410fd88a9b64b36a4 (patch)
tree19335864620e514d73d62b38c76c773c1bf8e227 /src/input.h
parent5f310c57af176d7a9a113cbe7fc5b0ff4e4b75f5 (diff)
downloadcolm-fe0e546c65accd2e9ca0fa5410fd88a9b64b36a4.tar.gz
use fopencookie to avoid leaking FILE structs
If we use fdopen for stdin/out/err we cannot close it to free the file struct without also closing the file descriptor. If fopencookie is available, use that to wrap the file descriptor, but allow closing without closing the fd. This is useful when embedding in long running programs.
Diffstat (limited to 'src/input.h')
-rw-r--r--src/input.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/input.h b/src/input.h
index 8cb20088..1d86a11b 100644
--- a/src/input.h
+++ b/src/input.h
@@ -193,6 +193,12 @@ struct stream_impl_data
char *name;
FILE *file;
+ // There is one condition when we don't want to close the FILE struct. If
+ // there is no fopencookie available, we need to use fdopen to wrap FD 0, 1
+ // and 2. However, closing those also closes the file descriptor, and when
+ // a colm program is embedded in a bigger program, we don't want that.
+ int no_file_close;
+
struct colm_str_collect *collect;
int consumed;