From 5a85c5b45972f44a03f77bbb1b853d9dfd2ea1cd Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 7 Apr 2015 21:59:54 +0300 Subject: Update copyrights and prep towards release. --- profile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index fd37bc61..28bb442a 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. -- cgit v1.2.3 From d6fecb7fa6188d819c3bc24841cebcd58082a52d Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 8 Apr 2015 18:08:56 +0300 Subject: Allow to redirect profile to stdout more portably. --- profile.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 28bb442a..fe411e43 100644 --- a/profile.c +++ b/profile.c @@ -66,7 +66,10 @@ void set_prof_file(const char *file) { assert(file != NULL); - prof_fp = fopen(file, "w"); + if (strcmp(file, "-") == 0) + prof_fp = stdout; + else + prof_fp = fopen(file, "w"); if (prof_fp == NULL) { warning(_("could not open `%s' for writing: %s"), file, strerror(errno)); -- cgit v1.2.3 From acdfa6d81af4d9069e609780750f6dd8f98d6bff Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 8 Apr 2015 19:23:52 +0300 Subject: Enable special filenames for profiling output. --- profile.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index fe411e43..74fc4f9c 100644 --- a/profile.c +++ b/profile.c @@ -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")); -- cgit v1.2.3