【发布时间】:2014-03-25 17:17:19
【问题描述】:
这里是C新手。
用这个把我的头撞到墙上......:/ 我正在尝试与任何其他进程未使用的文件进行比较,这意味着它们是静态的,仅使用系统调用。使用 fopen() 这样做没有问题,但仅使用 open()、read() 和 write() 时感觉要复杂得多...
这是我目前得到的:
...//Some code here to get file descriptors and other file manipulation checks
int one = read(srcfd1,buf1,src1_size);
int two = read(srcfd2,buf2,src2_size);
printf("%s\n",buf1); //works fine till it gets here...
int samefile = strcmp(buf1,buf2); //Crashes somewhere around here..
if (samefile != 0)
{
printf("not equle\n");
return(1);
}
else
{
printf("equle\n");
return(2);
}
所以基本上,我认为我需要做的是比较两个缓冲区,但这似乎不起作用......
我发现了一些我认为应该给我一些想法的东西 here 但我无法理解它(链接中的最后一个答案......)。
返回值无关紧要。
感谢我能得到的任何帮助...:/
【问题讨论】:
标签: c compare system-calls file-descriptor