지정한 디렉토리의 파일에 대한 정보를 나열하려하지만 메모리 덤프 코어 덤프 오류가 발생합니다. 목록 디렉토리 방법 :c - scandir, memory fault 코어 덤프 오류
int listdir(char *path) {
struct dirent **dirlist;
int n;
char *fullpath;
n = scandir(path, &dirlist, NULL, alphasort);
while (n--) {
strcpy(fullpath, path);
strcat(fullpath, dirlist[n]->d_name);
(void)printfinf(fullpath);
free(dirlist[n]);
}
free(dirlist);
return 0;
}
Printfinf 방법 -이 방법이 잘 작동, 당신은하지 않았다, 당신은 대상 경로 문자열에 대한 메모리를 할당하는 데 필요한 파일
int printfinf(char *path) {
struct stat info;
struct passwd *pswd;
lstat(path,&info);
pswd = getpwuid(info.st_uid);
char *modestr = mode2str(info.st_mode, getuid(), getgid());
char *timestr = time2str(info.st_mtime);
printf("%s %s %10lld %s %s\n", modestr, pswd->pw_name, info.st_size, timestr, path);
char c = modestr[0];
if(c == 'd')
return FTYPE_DIR;
else if(c == 'f')
return FTYPE_REG;
else if(c == 'e')
return FTYPE_EXE;
else if(c == 'l')
return FTYPE_LNK;
else return FTYPE_OTH;
}
안녕하세요! 질문에서 코드를 삭제 한 이유는 무엇입니까? 이제는 완전히 불분명합니다. – ventiseis
질문에서 코드를 삭제하지 마십시오. 스택 오버플로에 오신 것을 환영합니다. 여기서 '감사합니다'라고 말하면 가장 좋은 방법은 위의 좋은 질문과 유용한 답변 (충분한 답변을 얻으려면 명을 얻은 것임)이며, 질문에 대한 가장 유용한 답변을 수락하면됩니다. (이는 또한 평판에 대한 귀하의 에 약간의 도움이됩니다). [정보] 페이지 및 [질문은 어떻게합니까? 여기에 있습니까?] (http://stackoverflow.com/help/how-to-ask) 및 [내 질문에 대한 대답은 무엇을해야합니까? ?] (http://stackoverflow.com/help/someone-answers) –