diff options
author | attilamolnar <attilamolnar@hush.com> | 2012-07-09 18:06:08 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2012-07-11 16:34:50 +0200 |
commit | 074a96c9ffc85763da833bccadefc9978152482c (patch) | |
tree | 76af533d362cc62a348f5beeb3c2a8ab0ceeab8a /include | |
parent | fa586546fa8b7d17199d08bc7f9814de7aaa3ac7 (diff) |
Close files opened with popen() with pclose() instead of fclose()
Diffstat (limited to 'include')
-rw-r--r-- | include/configparser.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/include/configparser.h b/include/configparser.h index 478899ed9..4b83d26d7 100644 --- a/include/configparser.h +++ b/include/configparser.h @@ -61,13 +61,19 @@ struct ParseStack struct FileWrapper { FILE* const f; - FileWrapper(FILE* file) : f(file) {} + bool close_with_pclose; + FileWrapper(FILE* file, bool use_pclose = false) : f(file), close_with_pclose(use_pclose) {} operator bool() { return f; } operator FILE*() { return f; } ~FileWrapper() { if (f) - fclose(f); + { + if (close_with_pclose) + pclose(f); + else + fclose(f); + } } }; |