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.



Relevant Pages

  • Unix C programming for finding file
    ... The matched file must have the ... meeting a file, execute the system shell command "diff" to compare the ... I wonder if there is any library function that can compare two ...
    (comp.unix.programmer)
  • Re: Awk help?
    ... I want to compare the ... awk is certainly capable of meeting the needs of your situation, but dedicated and optimized Unix tools do have their place. ...
    (comp.lang.awk)
  • Re: Find Someone Men or Women for Threesome
    ... Meeting with someone special is always awesome thing for anybody.Getting attachment with two partner is more awesome in compare two single one. ... The best thing is spend time with unforgettable moments. ...
    (soc.history.science)
  • Re: Awk help?
    ... I want to compare the ... awk is certainly capable of meeting the needs of your situation, but dedicated and optimized Unix tools do have their place. ...
    (comp.lang.awk)
  • Re: Unix C programming for finding file
    ... I wonder if there is any library function that can compare two ... but you can use memcmp(). ...
    (comp.unix.programmer)