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
31int 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}
virtual int execute(const Size nparams, const char **params)
Executes the command.
ChangeDirCommand()
Constructor function.
Builtin command for the Shell.
const char * getName() const
Get command name.
const char * m_help
Command help text.
C char * strerror(int errnum)
The strerror function maps the number in errnum to a message string.
Definition strerror.cpp:20
C int errno
The lvalue errno is used by many functions to return error values.
#define EXIT_SUCCESS
Successful termination.
Definition stdlib.h:33
#define EXIT_FAILURE
Unsuccessful termination.
Definition stdlib.h:36
C int chdir(const char *path)
Change working directory.
Definition chdir.cpp:27
#define ERROR(msg)
Output an error message.
Definition Log.h:61
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128