klaptopdaemon
checkcrc.h
Go to the documentation of this file.00001 /* 00002 * checkcrc.h 00003 * 00004 * Copyright (c) 2003 Paul Campbell <paul@taniwha.com> 00005 * Requires the Qt widget libraries, available at no cost at 00006 * http://www.troll.no/ 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef _CHECKCRC_H_ 00024 #define _CHECKCRC_H_ 00025 00026 00027 00028 #include <zlib.h> 00029 #include <stdio.h> 00030 00031 static void 00032 checkcrc(const char *name, unsigned long &len_res, unsigned long &crc_res) 00033 { 00034 unsigned long crc = ::crc32(0L, Z_NULL, 0); 00035 unsigned long len = 0; 00036 00037 FILE *f = ::fopen(name, "r"); 00038 if (f) { 00039 unsigned char buffer[1024]; 00040 for (;;) { 00041 int l = ::fread(buffer, 1, sizeof(buffer), f); 00042 if (l <= 0) 00043 break; 00044 len += l; 00045 crc = ::crc32(crc, buffer, l); 00046 } 00047 ::fclose(f); 00048 } 00049 crc_res = crc; 00050 len_res = len; 00051 } 00052 00053 #endif
KDE 4.0 API Reference