Unix C programming for finding file

From: dawn (ming_at_lian.com)
Date: 11/24/04

Date: Wed, 24 Nov 2004 23:53:26 +0800

Hi all,
    I am now working on a C program under Unix.
    The requirement for the program is that:
      A file name is passed to program as a parameter. The program will
Find files under a specified directory. The matched file must have the
same content with the given file. It does not matter whether the
filenames are the same.

    It is easy to find file that has the same name with given file, but
may be hard to find the files that with the same content. In my
knowledge, i give two solutions:

    1) Go throught the directory and its sub direcotry tree, and when
meeting a file, Use the stand C library function to open that file and
the given file, and then compare those contents in buffers to see if
they are the same.

    2) Go through the directory and its sub deirectroy tree, and when
meeting a file, execute the system shell command "diff" to compare the
two files to see if they are the same in content.

    The two solutions seems not very smart and they are very running
slowly. I wonder if there is any library function that can compare two
file contents just like "strcmp" to compare two string.
    Or maybe there are some other smart ways to achieve it.

    Thank you for suggestions.