cd - chdir() in C++ Getting Errors -
i trying run minimal terminal shell program through socket on unix machine. when use system("cd directory")
doesn't work. did bit of research , came across chdir()
, looked work. when tried it, though, gave me errors every single time. here code:
if (chdir(argument) < 0) { send(sock, "[*] directory not exits!\n", strlen("[*] directory not exits!\n"), 0); } else { string argumentstring(argument); string entiremessage = "[*] new working directory: " + argumentstring; char entiremessagechar[64]; int i; (i = 0; entiremessage[i] != '\0'; i++) { entiremessagechar[i] = entiremessage[i]; } send(sock, &entiremessage, strlen(entiremessagechar), 0); }
could please tell me why chdir()
isn't changing directories? thanks.
the value of errno
after chdir()
has exited needs checked determine why doesn't work.
likely exit status values include:
- eaccess (no permission target)
- enoent (file not exist)
- enotdir (target file, not directory).
check documentation operating system's implementation complete list.
Comments
Post a Comment