mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Use symbolic names for standard file descriptors.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
c81c6c9f54
commit
094fd0cd89
@ -23,6 +23,8 @@
|
|||||||
#include <time.h> /* AIX for tm */
|
#include <time.h> /* AIX for tm */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
/*** typedefs(not structures) and defined constants **********************************************/
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
#ifndef major
|
#ifndef major
|
||||||
@ -40,6 +42,18 @@
|
|||||||
#define makedev(major,minor) ((((major) & 0xff) << 8) | ((minor) & 0xff))
|
#define makedev(major,minor) ((((major) & 0xff) << 8) | ((minor) & 0xff))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef STDIN_FILENO
|
||||||
|
#define STDIN_FILENO 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STDOUT_FILENO
|
||||||
|
#define STDOUT_FILENO 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STDERR_FILENO
|
||||||
|
#define STDERR_FILENO 2
|
||||||
|
#endif
|
||||||
|
|
||||||
/*** enums ***************************************************************************************/
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
@ -58,11 +58,12 @@
|
|||||||
#ifdef HAVE_GET_PROCESS_STATS
|
#ifdef HAVE_GET_PROCESS_STATS
|
||||||
#include <sys/procstats.h>
|
#include <sys/procstats.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
|
#include "lib/unixcompat.h"
|
||||||
#include "lib/vfs/vfs.h" /* VFS_ENCODING_PREFIX */
|
#include "lib/vfs/vfs.h" /* VFS_ENCODING_PREFIX */
|
||||||
#include "lib/strutil.h" /* str_move() */
|
#include "lib/strutil.h" /* str_move() */
|
||||||
#include "lib/util.h"
|
#include "lib/util.h"
|
||||||
@ -516,8 +517,8 @@ open_error_pipe (void)
|
|||||||
{
|
{
|
||||||
message (D_NORMAL, _("Warning"), _("Pipe failed"));
|
message (D_NORMAL, _("Warning"), _("Pipe failed"));
|
||||||
}
|
}
|
||||||
old_error = dup (2);
|
old_error = dup (STDERR_FILENO);
|
||||||
if (old_error < 0 || close (2) || dup (error_pipe[1]) != 2)
|
if (old_error < 0 || close (STDERR_FILENO) != 0 || dup (error_pipe[1]) != STDERR_FILENO)
|
||||||
{
|
{
|
||||||
message (D_NORMAL, _("Warning"), _("Dup failed"));
|
message (D_NORMAL, _("Warning"), _("Dup failed"));
|
||||||
|
|
||||||
@ -577,7 +578,7 @@ close_error_pipe (int error, const char *text)
|
|||||||
title = _("Warning");
|
title = _("Warning");
|
||||||
if (old_error >= 0)
|
if (old_error >= 0)
|
||||||
{
|
{
|
||||||
if (dup2 (old_error, 2) == -1)
|
if (dup2 (old_error, STDERR_FILENO) == -1)
|
||||||
{
|
{
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
error = D_ERROR;
|
error = D_ERROR;
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "lib/unixcompat.h"
|
#include "lib/unixcompat.h"
|
||||||
|
@ -43,10 +43,11 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h> /* waitpid() */
|
#include <sys/wait.h> /* waitpid() */
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
|
#include "lib/unixcompat.h"
|
||||||
#include "lib/tty/key.h" /* add_select_channel(), delete_select_channel() */
|
#include "lib/tty/key.h" /* add_select_channel(), delete_select_channel() */
|
||||||
#include "lib/widget.h" /* message() */
|
#include "lib/widget.h" /* message() */
|
||||||
#include "lib/event-types.h"
|
#include "lib/event-types.h"
|
||||||
@ -547,18 +548,18 @@ do_background (file_op_context_t * ctx, char *info)
|
|||||||
top_dlg = NULL;
|
top_dlg = NULL;
|
||||||
|
|
||||||
/* Make stdin/stdout/stderr point somewhere */
|
/* Make stdin/stdout/stderr point somewhere */
|
||||||
close (0);
|
close (STDIN_FILENO);
|
||||||
close (1);
|
close (STDOUT_FILENO);
|
||||||
close (2);
|
close (STDERR_FILENO);
|
||||||
|
|
||||||
nullfd = open ("/dev/null", O_RDWR);
|
nullfd = open ("/dev/null", O_RDWR);
|
||||||
if (nullfd != -1)
|
if (nullfd != -1)
|
||||||
{
|
{
|
||||||
while (dup2 (nullfd, 0) == -1 && errno == EINTR)
|
while (dup2 (nullfd, STDIN_FILENO) == -1 && errno == EINTR)
|
||||||
;
|
;
|
||||||
while (dup2 (nullfd, 1) == -1 && errno == EINTR)
|
while (dup2 (nullfd, STDOUT_FILENO) == -1 && errno == EINTR)
|
||||||
;
|
;
|
||||||
while (dup2 (nullfd, 2) == -1 && errno == EINTR)
|
while (dup2 (nullfd, STDERR_FILENO) == -1 && errno == EINTR)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,10 +39,10 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
|
#include "lib/unixcompat.h"
|
||||||
#include "lib/tty/tty.h"
|
#include "lib/tty/tty.h"
|
||||||
#include "lib/skin.h" /* tty_set_normal_attrs */
|
#include "lib/skin.h" /* tty_set_normal_attrs */
|
||||||
#include "lib/tty/win.h"
|
#include "lib/tty/win.h"
|
||||||
@ -193,17 +193,17 @@ handle_console_linux (console_action_t action)
|
|||||||
/* Bind the pipe 0 to the standard input */
|
/* Bind the pipe 0 to the standard input */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (dup2 (pipefd1[0], 0) == -1)
|
if (dup2 (pipefd1[0], STDIN_FILENO) == -1)
|
||||||
break;
|
break;
|
||||||
status = close (pipefd1[0]);
|
status = close (pipefd1[0]);
|
||||||
/* Bind the pipe 1 to the standard output */
|
/* Bind the pipe 1 to the standard output */
|
||||||
if (dup2 (pipefd2[1], 1) == -1)
|
if (dup2 (pipefd2[1], STDOUT_FILENO) == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
status = close (pipefd2[1]);
|
status = close (pipefd2[1]);
|
||||||
/* Bind standard error to /dev/null */
|
/* Bind standard error to /dev/null */
|
||||||
status = open ("/dev/null", O_WRONLY);
|
status = open ("/dev/null", O_WRONLY);
|
||||||
if (dup2 (status, 2) == -1)
|
if (dup2 (status, STDERR_FILENO) == -1)
|
||||||
break;
|
break;
|
||||||
status = close (status);
|
status = close (status);
|
||||||
if (tty_name != NULL)
|
if (tty_name != NULL)
|
||||||
|
@ -67,7 +67,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
#include "lib/unixcompat.h" /* STDERR_FILENO */
|
||||||
|
|
||||||
#define LINUX_CONS_SAVER_C
|
#define LINUX_CONS_SAVER_C
|
||||||
#include "cons.saver.h"
|
#include "cons.saver.h"
|
||||||
@ -164,7 +165,7 @@ main (int argc, char **argv)
|
|||||||
const char *p, *q;
|
const char *p, *q;
|
||||||
struct winsize winsz;
|
struct winsize winsz;
|
||||||
|
|
||||||
close (2);
|
close (STDERR_FILENO);
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
die ();
|
die ();
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
|
@ -47,7 +47,6 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#endif
|
#endif
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_STROPTS_H
|
#ifdef HAVE_STROPTS_H
|
||||||
#include <stropts.h> /* For I_PUSH */
|
#include <stropts.h> /* For I_PUSH */
|
||||||
@ -55,6 +54,7 @@
|
|||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
|
#include "lib/unixcompat.h"
|
||||||
#include "lib/tty/tty.h" /* LINES */
|
#include "lib/tty/tty.h" /* LINES */
|
||||||
#include "lib/tty/key.h" /* XCTRL */
|
#include "lib/tty/key.h" /* XCTRL */
|
||||||
#include "lib/vfs/vfs.h"
|
#include "lib/vfs/vfs.h"
|
||||||
@ -94,18 +94,6 @@ gboolean update_subshell_prompt = FALSE;
|
|||||||
#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STDIN_FILENO
|
|
||||||
#define STDIN_FILENO 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef STDOUT_FILENO
|
|
||||||
#define STDOUT_FILENO 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef STDERR_FILENO
|
|
||||||
#define STDERR_FILENO 2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Initial length of the buffer for the subshell's prompt */
|
/* Initial length of the buffer for the subshell's prompt */
|
||||||
#define INITIAL_PROMPT_SIZE 10
|
#define INITIAL_PROMPT_SIZE 10
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "lib/unixcompat.h"
|
#include "lib/unixcompat.h"
|
||||||
|
@ -332,11 +332,11 @@ fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = dup2 (fileset1[0], 0);
|
res = dup2 (fileset1[0], STDIN_FILENO);
|
||||||
close (fileset1[0]);
|
close (fileset1[0]);
|
||||||
close (fileset1[1]);
|
close (fileset1[1]);
|
||||||
res = dup2 (fileset2[1], 1);
|
res = dup2 (fileset2[1], STDOUT_FILENO);
|
||||||
close (2);
|
close (STDERR_FILENO);
|
||||||
/* stderr to /dev/null */
|
/* stderr to /dev/null */
|
||||||
res = open ("/dev/null", O_WRONLY);
|
res = open ("/dev/null", O_WRONLY);
|
||||||
close (fileset2[0]);
|
close (fileset2[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user