From: Arnaud Lacombe <lacombar@gmail.com>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: linux-kbuild <linux-kbuild@vger.kernel.org>,
Arnaud Lacombe <lacombar@gmail.com>,
Nir Tzachar <nir.tzachar@gmail.com>
Subject: [PATCH 1/4] kbuild: don't assign `stdout' and `stderr'
Date: Mon, 16 Aug 2010 00:19:03 -0400 [thread overview]
Message-ID: <1281932346-19067-1-git-send-email-lacombar@gmail.com> (raw)
These may not be modifiable, as per C99 comment:
section 7.19.5.4, note 232:
"
The primary use of the freopen function is to change the file associated with a
standard text stream (stderr, stdin, or stdout), as those identifiers need not
be modifiable lvalues to which the value returned by the fopen function may be
assigned.
"
Use a duplicate of stdout as ncurses' output terminal, then redirect it
to /dev/null for conf_write().
This fixes nconf.c build on NetBSD.
Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
CC: Nir Tzachar <nir.tzachar@gmail.com>
---
scripts/kconfig/nconf.c | 46 +++++++++++++++++++++-------------------------
1 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index 2ba71bc..e08a064 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -709,25 +709,6 @@ static const char *set_config_filename(const char *config_filename)
return menu_backtitle;
}
-/* command = 0 is supress, 1 is restore */
-static void supress_stdout(int command)
-{
- static FILE *org_stdout;
- static FILE *org_stderr;
-
- if (command == 0) {
- org_stdout = stdout;
- org_stderr = stderr;
- stdout = fopen("/dev/null", "a");
- stderr = fopen("/dev/null", "a");
- } else {
- fclose(stdout);
- fclose(stderr);
- stdout = org_stdout;
- stderr = org_stderr;
- }
-}
-
/* return = 0 means we are successful.
* -1 means go on doing what you were doing
*/
@@ -753,9 +734,7 @@ static int do_exit(void)
/* if we got here, the user really wants to exit */
switch (res) {
case 0:
- supress_stdout(0);
res = conf_write(filename);
- supress_stdout(1);
if (res)
btn_dialog(
main_window,
@@ -1449,9 +1428,7 @@ static void conf_save(void)
case 0:
if (!dialog_input_result[0])
return;
- supress_stdout(0);
res = conf_write(dialog_input_result);
- supress_stdout(1);
if (!res) {
char buf[1024];
sprintf(buf, "%s %s",
@@ -1495,6 +1472,8 @@ void setup_windows(void)
int main(int ac, char **av)
{
char *mode;
+ FILE *fp;
+ int fd;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -1509,8 +1488,25 @@ int main(int ac, char **av)
single_menu_mode = 1;
}
+ /* Duplicate stdout before redirecting it */
+ fd = dup(STDOUT_FILENO);
+ if (fd < 0) {
+ perror("dup");
+ return 1;
+ }
+
+ fp = fdopen(fd, "a");
+ if (fp == NULL) {
+ perror("fdopen");
+ return 1;
+ }
+
+ freopen("/dev/null", "a", stdout);
+ freopen("/dev/null", "a", stderr);
+
/* Initialize curses */
- initscr();
+ newterm(NULL, fp, stdin);
+
/* set color theme */
set_colors();
@@ -1521,7 +1517,7 @@ int main(int ac, char **av)
if (COLS < 75 || LINES < 20) {
endwin();
- printf("Your terminal should have at "
+ fprintf(fp, "Your terminal should have at "
"least 20 lines and 75 columns\n");
return 1;
}
--
1.7.2.30.gc37d7.dirty
next reply other threads:[~2010-08-16 4:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-16 4:19 Arnaud Lacombe [this message]
2010-08-16 4:19 ` [PATCH 2/4] kbuild: don't include `check-lxdialog' ldflags in global HOST_LOADLIBES Arnaud Lacombe
2010-08-17 9:01 ` Michal Marek
2010-08-16 4:19 ` [PATCH 3/4] kbuild: `nconf' needs -lintl Arnaud Lacombe
2010-08-17 9:00 ` Michal Marek
2010-08-17 15:55 ` Arnaud Lacombe
2010-08-23 0:03 ` [PATCH] kbuild: don't overwrite HOST_EXTRACFLAGS Arnaud Lacombe
2010-08-23 0:17 ` Arnaud Lacombe
2010-08-26 12:00 ` Michal Marek
2010-08-26 12:11 ` Sam Ravnborg
2010-08-16 4:19 ` [PATCH 4/4] kbuild: fix typo Arnaud Lacombe
2010-08-17 8:27 ` [PATCH 1/4] kbuild: don't assign `stdout' and `stderr' Michal Marek
2010-08-17 15:28 ` Arnaud Lacombe
2010-08-18 5:16 ` Nir Tzachar
2010-10-21 2:22 ` Arnaud Lacombe
2010-10-27 22:56 ` Michal Marek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1281932346-19067-1-git-send-email-lacombar@gmail.com \
--to=lacombar@gmail.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=nir.tzachar@gmail.com \
--cc=sam@ravnborg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox