Various minor things done to project files Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way) Updated regex project file and makefile --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401971
		
			
				
	
	
		
			47 lines
		
	
	
		
			742 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			742 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include <stdio.h>
 | |
| #include <stdlib.h>
 | |
| #include <sm_crc32.h>
 | |
| 
 | |
| int main(int argc, char **argv)
 | |
| {
 | |
| 	if (argc < 2)
 | |
| 	{
 | |
| 		fprintf(stderr, "Usage: crc32 <file>\n");
 | |
| 		exit(1);
 | |
| 	}
 | |
| 
 | |
| 	FILE *fp = fopen(argv[1], "rb");
 | |
| 	if (!fp)
 | |
| 	{
 | |
| 		fprintf(stderr, "Could not open file: %s\n", argv[1]);
 | |
| 		exit(1);
 | |
| 	}
 | |
| 
 | |
| 	fseek(fp, 0, SEEK_END);
 | |
| 	size_t size = ftell(fp);	
 | |
| 	if (!size)
 | |
| 	{
 | |
| 		fprintf(stderr, "Cannot checksum an empty file.\n");
 | |
| 		exit(1);
 | |
| 	}
 | |
| 
 | |
| 	fseek(fp, 0, SEEK_SET);
 | |
| 
 | |
| 	void *buffer = malloc(size);
 | |
| 	if (!buffer)
 | |
| 	{
 | |
| 		fprintf(stderr, "Unable to allocate %d bytes of memory.\n", size);
 | |
| 		exit(1);
 | |
| 	}
 | |
| 
 | |
| 	fread(buffer, size, 1, fp);
 | |
| 	unsigned int crc32 = UTIL_CRC32(buffer, size);
 | |
| 	free(buffer);
 | |
| 	fclose(fp);
 | |
| 
 | |
| 	fprintf(stdout, "%08X\n", crc32);
 | |
| 
 | |
| 	return 0;
 | |
| }
 | |
| 
 |