#include <stdio.h>
#include <unistd.h>
#define EXIT_FAILURE /*implementation defined*/
#define EXIT_SUCCESS /*implementation defined*/
int main(void)
{
char *swd;
int ret;
swd = getcwd(NULL,0);
printf("1.%s\n",swd);
printf("2.%s\n",getcwd(NULL,0));
if(!swd){
perror("getcwd");
exit(EXIT_FAILURE);
}
ret = chdir("dd");
//printf("3.%s\n",ret);
printf("4.%s\n",getcwd(NULL,0));
if(ret){
perror("chdir");
}
ret = chdir(swd);
printf("5.%s\n",getcwd(NULL,0));
enter code here
if(ret){
perror("chdir");
exit(1);
}
free(swd);
}
答案 0 :(得分:5)
正如评论中所述,您已将EXIT_FAILURE
定义为什么都没有,顺便在EXIT_FAILURE
中定义stdlib.h
,因此您无需定义它,只需将其包含并使用即可。如果你想定义它,你的自己会这样:
#define EXIT_FAILURE -1 /* A number not equal to 0 */
#define EXIT_SUCCESS 0