FreeNOS
StdioCommand.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <unistd.h>
19 #include <fcntl.h>
20 #include "StdioCommand.h"
21 
23 {
24  m_help = "Change standard I/O of the shell";
25 }
26 
27 int StdioCommand::execute(const Size nparams, const char **params)
28 {
29  // Close current standard I/O
30  close(0);
31  close(1);
32  close(2);
33 
34  // Reopen standard I/O
35  open(params[0], O_RDWR);
36  open(params[1], O_RDWR);
37  open(params[1], O_RDWR);
38 
39  // Done
40  return 0;
41 }
fcntl.h
ShellCommand
Builtin command for the Shell.
Definition: ShellCommand.h:38
ShellCommand::m_help
const char * m_help
Command help text.
Definition: ShellCommand.h:91
open
int open(const char *path, int oflag,...)
Open file relative to directory file descriptor.
Definition: open.cpp:26
StdioCommand.h
close
int close(int fildes)
Close a file descriptor.
Definition: close.cpp:22
StdioCommand::execute
virtual int execute(const Size nparams, const char **params)
Executes the command.
Definition: StdioCommand.cpp:27
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
StdioCommand::StdioCommand
StdioCommand()
Constructor function.
Definition: StdioCommand.cpp:22
O_RDWR
#define O_RDWR
Open for reading and writing.
Definition: fcntl.h:84
unistd.h