File: diff.c

package info (click to toggle)
wmweather+ 2.15-1.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,100 kB
  • ctags: 579
  • sloc: ansic: 5,822; sh: 1,294; makefile: 42
file content (62 lines) | stat: -rw-r--r-- 1,999 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "config.h"

/*  Copyright (C) 2002  Brad Jorsch <anomie@users.sourceforge.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>

#include "wmweather+.h"

int diff(char *file1, char *file2){
    FILE *fp1, *fp2;
    size_t len1, len2;
    struct stat statbuf;
    int ret;
    int len=BIGBUF_LEN/2;
    char *s1=(char *)bigbuf, *s2=(char *)(bigbuf+len);

    if((fp1=fopen(file1, "r"))==NULL) return -1;
    if((fp2=fopen(file2, "r"))==NULL){ fclose(fp1); return -1; }
    if(fstat(fileno(fp1), &statbuf)<0 || !S_ISREG(statbuf.st_mode)){
       fclose(fp1);
       fclose(fp2);
       return -1;
    }
    len1=statbuf.st_size;
    if(fstat(fileno(fp2), &statbuf)<0 || !S_ISREG(statbuf.st_mode)){
       fclose(fp1);
       fclose(fp2);
       return -1;
    }
    len2=statbuf.st_size;
    if(len1!=len2){ fclose(fp1); fclose(fp2); return 1; }
    if(len1==0){ fclose(fp1); fclose(fp2); return 0; }
    while(!feof(fp1) && !feof(fp2)){
        len1=fread(s1, sizeof(char), len, fp1);
        len2=fread(s2, sizeof(char), len, fp2);
        if(len1!=len2 || memcmp(s1, s2, len1)){
            fclose(fp1); fclose(fp2); return 1;
        } 
    }
    ret=(!feof(fp1) || !feof(fp2));
    fclose(fp1);
    fclose(fp2);
    return ret;
}