diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-08 19:23:52 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-08 19:23:52 +0300 |
commit | acdfa6d81af4d9069e609780750f6dd8f98d6bff (patch) | |
tree | c863ffb717b373adf882d40d10af29f3f0128ddb /profile.c | |
parent | 98837e032b31aeb9f358edaedda1440a450c9c1d (diff) | |
download | egawk-acdfa6d81af4d9069e609780750f6dd8f98d6bff.tar.gz egawk-acdfa6d81af4d9069e609780750f6dd8f98d6bff.tar.bz2 egawk-acdfa6d81af4d9069e609780750f6dd8f98d6bff.zip |
Enable special filenames for profiling output.
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -65,12 +65,29 @@ static long indent_level = 0; void set_prof_file(const char *file) { + int fd; + assert(file != NULL); - if (strcmp(file, "-") == 0) + fd = devopen_simple(file, "w", true); + if (fd == INVALID_HANDLE) + prof_fp = NULL; + else if (fd == fileno(stdout)) prof_fp = stdout; + else if (fd == fileno(stderr)) + prof_fp = stderr; else - prof_fp = fopen(file, "w"); + prof_fp = fdopen(fd, "w"); + if (prof_fp == NULL) { + /* don't leak file descriptors */ + int e = errno; + + if ( fd != INVALID_HANDLE + && fd != fileno(stdout) + && fd != fileno(stderr)) + (void) close(fd); + + errno = e; warning(_("could not open `%s' for writing: %s"), file, strerror(errno)); warning(_("sending profile to standard error")); |