FreeNOS
ChangeDirCommand.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 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 "ChangeDirCommand.h"
19 #include <stdlib.h>
20 #include <errno.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <Log.h>
24 
26  : ShellCommand("cd", 1)
27 {
28  m_help = "Change the current working directory";
29 }
30 
31 int ChangeDirCommand::execute(const Size nparams, const char **params)
32 {
33  if (chdir(params[0]) != 0)
34  {
35  ERROR(getName() << ": failed to change directory to `" << params[0] << "': " << strerror(errno));
36  return EXIT_FAILURE;
37  }
38  return EXIT_SUCCESS;
39 }
EXIT_FAILURE
#define EXIT_FAILURE
Unsuccessful termination.
Definition: stdlib.h:36
errno
C int errno
The lvalue errno is used by many functions to return error values.
string.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
ShellCommand::getName
const char * getName() const
Get command name.
Definition: ShellCommand.cpp:31
Log.h
strerror
char * strerror(int errnum)
The strerror function maps the number in errnum to a message string.
Definition: strerror.cpp:20
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
ChangeDirCommand::ChangeDirCommand
ChangeDirCommand()
Constructor function.
Definition: ChangeDirCommand.cpp:25
EXIT_SUCCESS
#define EXIT_SUCCESS
Successful termination.
Definition: stdlib.h:33
unistd.h
ChangeDirCommand::execute
virtual int execute(const Size nparams, const char **params)
Executes the command.
Definition: ChangeDirCommand.cpp:31
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
chdir
int chdir(const char *filepath)
Change working directory.
Definition: chdir.cpp:27
stdlib.h
ChangeDirCommand.h
errno.h