#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>
Go to the source code of this file.
Functions | |
| int | main (int argc, char **argv) |
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 5 of file checksum.c.
References fd.
00006 { 00007 int fd; 00008 struct stat statbuf; 00009 unsigned int checksum,i; 00010 unsigned int seek,len,size; 00011 char *buf; 00012 seek = strtoul(argv[2],0,0); 00013 len = strtoul(argv[3],0,0); 00014 if(stat(argv[1],&statbuf)!=0) 00015 { 00016 printf("error read file %s\n",argv[1]); 00017 exit(-1); 00018 } 00019 printf("open file %s,size %d\n",argv[1],statbuf.st_size); 00020 buf=malloc(statbuf.st_size+4); 00021 if(!buf)printf("error allocate memory\n"); 00022 fd=open(argv[1],O_RDONLY); 00023 read(fd,buf,statbuf.st_size); 00024 close(fd); 00025 checksum = 0; 00026 size = (statbuf.st_size+3)&~3; 00027 if(len+seek>size) len=size; 00028 00029 for(i=seek,checksum=0;i<seek+len;i+=4) 00030 { 00031 checksum += *(unsigned int *)(buf+i); 00032 } 00033 printf("checksum 0x%08x\n",checksum); 00034 00035 return 0; 00036 }
1.5.6