如何确定两个文件中使用系统调用中c是相同 [英] how to determine if two file are identical in c using system call
本文介绍了如何确定两个文件中使用系统调用中c是相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要看看如果2个文件相同
所以我用
结构统计
i need to see if 2 files are identical so i used struct stat
fdin = open(argv[0],O_RDONLY);
statos= fstat(fdin, &stat);
close(fdin);
fdin = open(argv[1],O_RDONLY);
statos1= fstat(fdin, &stat1);
close(fdin);
printf("file 1 is in size: %lu\n",stat1.st_ino);
printf("file 2 is in size: %lu\n",stat.st_ino);
结果
file 1 is in size: 9569486
file 2 is in size: 9569479
为什么是st.ino不具有相同的路径相同的文件相同??
我怎么能这样做,如果两个不同的文件是相同的,我可以用系统调用检查
why is the st.ino aren't identical for the same file with the same path?? and how can i do so if two different file are identical i could check it with system call
推荐答案
这是因为你打开两个不同的文件:
It's because you're opening two different files:
./a.out ab.txt ab.txt
的argv [0]
的可执行文件,的argv [1]
为ab.txt。
argv[0]
is the executable, argv[1]
is 'ab.txt'.
如果你把错误检查到code,这将是明显的。
If you put error checks into your code, it would be clear.
您也正在打印的inode的大小,出于某种原因。
You're also printing the inodes as "size", for some reason.
这篇关于如何确定两个文件中使用系统调用中c是相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文