当我硬编码chemin
到open(chemin, O_RDONLY)
文件名时,程序可以工作,但是当我离开时,open(chemin, O_RDONLY)
我得到No such file or directory
.
为什么不在chemin
type_fichier 中使用?
当我使用printf("%s", chemin)
时,type_fichier
我得到'
int type_fichier(char * chemin) {
int fp;
if ((fp = open(chemin, O_RDONLY)) == -1) { perror(""); exit(0); }
struct stat fileStat;
if(fstat(fp, &fileStat) < 0)
return 1;
switch(fileStat.st_mode & S_IFMT) {
case S_IFBLK: printf("block device\n"); break;
case S_IFCHR: printf("character device\n"); break;
case S_IFDIR: printf("directory\n"); break;
case S_IFIFO: printf("FIFO/pipe\n"); break;
case S_IFLNK: printf("symlink\n"); break;
case S_IFREG: printf("regular file\n"); break;
case S_IFSOCK: printf("socket\n"); break;
default: printf("unknown?\n"); break;
}
}
int main(int argc, char *argv[]) {
char fn = "file";
type_fichier(&fn);
}