wmpager: EWMH support
[dockapps.git] / wmweather+ / diff.c
blob4d1c09b685bbca512ea34143d2d964736c7cadd6
1 #include "config.h"
3 /* Copyright (C) 2002 Brad Jorsch <anomie@users.sourceforge.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <stdio.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <sys/stat.h>
25 #include "wmweather+.h"
27 int diff(char *file1, char *file2){
28 FILE *fp1, *fp2;
29 size_t len1, len2;
30 struct stat statbuf;
31 int ret;
32 int len=BIGBUF_LEN/2;
33 char *s1=(char *)bigbuf, *s2=(char *)(bigbuf+len);
35 if((fp1=fopen(file1, "r"))==NULL) return -1;
36 if((fp2=fopen(file2, "r"))==NULL){ fclose(fp1); return -1; }
37 if(fstat(fileno(fp1), &statbuf)<0 || !S_ISREG(statbuf.st_mode)){
38 fclose(fp1);
39 fclose(fp2);
40 return -1;
42 len1=statbuf.st_size;
43 if(fstat(fileno(fp2), &statbuf)<0 || !S_ISREG(statbuf.st_mode)){
44 fclose(fp1);
45 fclose(fp2);
46 return -1;
48 len2=statbuf.st_size;
49 if(len1!=len2){ fclose(fp1); fclose(fp2); return 1; }
50 if(len1==0){ fclose(fp1); fclose(fp2); return 0; }
51 while(!feof(fp1) && !feof(fp2)){
52 len1=fread(s1, sizeof(char), len, fp1);
53 len2=fread(s2, sizeof(char), len, fp2);
54 if(len1!=len2 || memcmp(s1, s2, len1)){
55 fclose(fp1); fclose(fp2); return 1;
58 ret=(!feof(fp1) || !feof(fp2));
59 fclose(fp1);
60 fclose(fp2);
61 return ret;