summaryrefslogtreecommitdiff
path: root/profile.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-04-08 19:37:48 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-04-08 19:37:48 +0300
commit4f43502b3852c7214c6def1141dc6d2ab57cd075 (patch)
tree476bfcef0da0d2a40826c4b17acdbacb9957e495 /profile.c
parentbe7aafc0b212669de461aeda752e704a727d1cb5 (diff)
parent38a62381d79aebbea120ed73921fb57a171d77e7 (diff)
downloadgawk-4f43502b3852c7214c6def1141dc6d2ab57cd075.tar.gz
Merge branch 'gawk-4.1-stable'
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/profile.c b/profile.c
index 3b4e134f..c6c1e309 100644
--- a/profile.c
+++ b/profile.c
@@ -67,9 +67,29 @@ static long indent_level = 0;
void
set_prof_file(const char *file)
{
+ int fd;
+
assert(file != NULL);
- prof_fp = fopen(file, "w");
+ 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 = 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"));