-1
我正在unix下C下的ftp服務器上工作,我在實現change工作目錄功能時遇到了困難,我已經有<unistd.h>
包括你認爲的問題是什麼是什麼?chdir不工作在unix下的c代碼總是無法更改目錄
static int cwd(int ctrlfd, char *cmdline) {
printf("cmdline:%s\n", cmdline);
char *space = strtok(cmdline, " \n");
printf("cwd to :%s\n", cmdline);
if (chdir(space) == 0) {
getcwd(space, sizeof(space));
printf("changing directory successful %s\n", space);
return ftp_send_resp(ctrlfd, 250);
} else {
printf("changing directory failed\n");
return ftp_send_resp(ctrlfd, 550);
}
}
你好謝謝對於你的回覆,getcwd()與這種方式的大小在另一個函數 – Ayman
中運行良好,但在我的代碼中它甚至沒有進入該區域cz chdir總是給出!= 0 – Ayman
@Ayman:'space'可能被定義爲數組中的其他函數。關於當前的問題,printf(「cmdline:%s \ n」,cmdline);'? – chqrlie