[xiph-commits] r16132 - trunk/ffmpeg2theora/src
j at svn.xiph.org
j at svn.xiph.org
Sun Jun 14 12:08:53 PDT 2009
Author: j
Date: 2009-06-14 12:08:53 -0700 (Sun, 14 Jun 2009)
New Revision: 16132
Modified:
trunk/ffmpeg2theora/src/avinfo.c
Log:
pad oshash with 0, deal with files < 64k
Modified: trunk/ffmpeg2theora/src/avinfo.c
===================================================================
--- trunk/ffmpeg2theora/src/avinfo.c 2009-06-14 18:57:18 UTC (rev 16131)
+++ trunk/ffmpeg2theora/src/avinfo.c 2009-06-14 19:08:53 UTC (rev 16132)
@@ -273,24 +273,32 @@
* os hash
* based on public domain example from
* http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes
- * -works only on little-endian procesor DEC, Intel and compatible
- * -sizeof(unsigned long long) must be 8
+ *
+ * plus modification for files < 64k, buffer is filled with file data and padded with 0
*/
unsigned long long gen_oshash(char const *filename) {
FILE *file;
int i;
unsigned long long t1=0;
unsigned long long buffer1[8192*2];
+ struct stat st;
-
file = fopen(filename, "rb");
if (file) {
- fread(buffer1, 8192, 8, file);
- fseek(file, -65536, SEEK_END);
- fread(&buffer1[8192], 8192, 8, file);
+ //add filesize
+ stat(filename, &st);
+ t1 = st.st_size;
+ if(t1 < 65536) {
+ fread(buffer1, t1/8, 8, file);
+ for (i=t1/8; i < 8192*2; i++)
+ buffer1[i] = 0;
+ } else {
+ fread(buffer1, 8192, 8, file);
+ fseek(file, -65536, SEEK_END);
+ fread(&buffer1[8192], 8192, 8, file);
+ }
for (i=0; i < 8192*2; i++)
t1+=buffer1[i];
- t1+= ftell(file); //add filesize
fclose(file);
}
return t1;
@@ -299,9 +307,9 @@
void json_oshash(FILE *output, char const *filename) {
char hash[32];
#ifdef WIN32
- sprintf(hash,"%16I64x", gen_oshash(filename));
+ sprintf(hash,"%016I64x", gen_oshash(filename));
#else
- sprintf(hash,"%qx", gen_oshash(filename));
+ sprintf(hash,"%016qx", gen_oshash(filename));
#endif
json_add_key_value(output, "oshash", (void *)hash, JSON_STRING, 0);
}
More information about the commits
mailing list