aboutsummaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-04-08 20:31:22 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-04-08 20:31:22 +0300
commitd047b198dca5da3577f696ac868c19feb030bc7a (patch)
tree98d84d796d8c8646854f43f3c8633dc74210ae5e /profile.c
parentcc307380da7838f4d9f0f8addd7193e0b1f33e37 (diff)
parent969a8d5a0353c756199c0b354d0e8fa91977db86 (diff)
downloadegawk-d047b198dca5da3577f696ac868c19feb030bc7a.tar.gz
egawk-d047b198dca5da3577f696ac868c19feb030bc7a.tar.bz2
egawk-d047b198dca5da3577f696ac868c19feb030bc7a.zip
Merge branch 'master' into feature/cmake
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/profile.c b/profile.c
index 3e9ef783..c6c1e309 100644
--- a/profile.c
+++ b/profile.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1999-2013 the Free Software Foundation, Inc.
+ * Copyright (C) 1999-2015 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -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"));