Problems with the read syscall

0

I am writing a simple program that reads data from two files and performs a byte-by-byte comparison to find the first(if any) difference between the two.

Here is the code I'm having trouble with: it checks to see if the lengths of the files are different and prints appropriately:

len1 = read(dumpFile, file1, 1024);
len2 = read(fumpFile, file2, 1024);

if(len1<len2){
    printf("%d: EOF 0x%x\n", len1, file2[len1]);
    return;
}
if(len1>len2){
    printf("%d: 0x%x EOF\n", len2, file1[len2]);
    return;
}

Here's the thing, if the first conditional is triggered, the output is fine: 10: EOF 0x71

Triggering the second, oddly enough, produces weird output even when the same files are used in different places: 10: 0xfffffffe EOF

I can't see anything I could do to fix this; it should be pretty straightforward. Any ideas?

c
linux
system-calls
asked on Stack Overflow Jun 6, 2019 by OldIslander

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0