Skip to content

Commit f230749

Browse files
committed
fix: pwd command
1 parent e9e76b9 commit f230749

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/command_factory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CommandFactory::CommandFactory() {
44
commands["exit"] = std::make_unique<ExitCommand>();
55
commands["echo"] = std::make_unique<EchoCommand>();
66
commands["type"] = std::make_unique<TypeCommand>();
7+
commands["pwd"] = std::make_unique<PwdCommand>();
78
}
89

910
Command* CommandFactory::get(const std::string& name) {

src/command_factory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "exit_command.h"
77
#include "echo_command.h"
88
#include "type_command.h"
9+
#include "pwd_command.h"
910

1011
class CommandFactory {
1112
std::map<std::string, std::unique_ptr<Command>> commands;

src/pwd_command.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
#include <unistd.h>
44

55
void PwdCommand::execute(const std::string& args) {
6-
char *cwd;
7-
getcwd(cwd, sizeof(cwd));
8-
if (cwd != nullptr) {
6+
char cwd[1024];
7+
if (getcwd(cwd, sizeof(cwd)) != nullptr) {
98
std::cout << cwd << std::endl;
109
} else {
1110
std::cerr << "Error getting current working directory" << std::endl;

0 commit comments

Comments
 (0)