diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-08 20:30:44 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-08 20:30:44 +0300 |
commit | 10602a79c47b0bf6ef53b7308355ef2d4312003e (patch) | |
tree | 71cdcb6487eac0145a4e419288c2518a79abfdfe /profile.c | |
parent | f8b283eeed514287482d3bb56103c34ab9ae133b (diff) | |
parent | 969a8d5a0353c756199c0b354d0e8fa91977db86 (diff) | |
download | egawk-10602a79c47b0bf6ef53b7308355ef2d4312003e.tar.gz egawk-10602a79c47b0bf6ef53b7308355ef2d4312003e.tar.bz2 egawk-10602a79c47b0bf6ef53b7308355ef2d4312003e.zip |
Merge branch 'master' into feature/regex-type
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -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")); |