Fossil SCM

Use the same definition of BINARY in multiple places of fossil. Reported by sky5walk.

jan.nijtmans 2015-11-06 08:09 trunk
Commit b51ba29365b93b3fa13f7fc05034ec6a8dc38b22
1 file changed +3 -14
+3 -14
--- src/doc.c
+++ src/doc.c
@@ -35,15 +35,10 @@
3535
const char *mimetype_from_content(Blob *pBlob){
3636
int i;
3737
int n;
3838
const unsigned char *x;
3939
40
- static const char isBinary[256] = {
41
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1,
42
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1
43
- };
44
-
4540
/* A table of mimetypes based on file content prefixes
4641
*/
4742
static const struct {
4843
const char *zPrefix; /* The file prefix */
4944
int size; /* Length of the prefix */
@@ -54,21 +49,15 @@
5449
{ "\211PNG\r\n\032\n", 8, "image/png" },
5550
{ "\377\332\377", 3, "image/jpeg" },
5651
{ "\377\330\377", 3, "image/jpeg" },
5752
};
5853
54
+ if( !looks_like_binary(pBlob) ) {
55
+ return 0; /* Plain text */
56
+ }
5957
x = (const unsigned char*)blob_buffer(pBlob);
6058
n = blob_size(pBlob);
61
- for(i=0; i<n; i++){
62
- unsigned char c = x[i];
63
- if( isBinary[c] ){
64
- break;
65
- }
66
- }
67
- if( i>=n ){
68
- return 0; /* Plain text */
69
- }
7059
for(i=0; i<ArraySize(aMime); i++){
7160
if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){
7261
return aMime[i].zMimetype;
7362
}
7463
}
7564
--- src/doc.c
+++ src/doc.c
@@ -35,15 +35,10 @@
35 const char *mimetype_from_content(Blob *pBlob){
36 int i;
37 int n;
38 const unsigned char *x;
39
40 static const char isBinary[256] = {
41 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1,
42 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1
43 };
44
45 /* A table of mimetypes based on file content prefixes
46 */
47 static const struct {
48 const char *zPrefix; /* The file prefix */
49 int size; /* Length of the prefix */
@@ -54,21 +49,15 @@
54 { "\211PNG\r\n\032\n", 8, "image/png" },
55 { "\377\332\377", 3, "image/jpeg" },
56 { "\377\330\377", 3, "image/jpeg" },
57 };
58
 
 
 
59 x = (const unsigned char*)blob_buffer(pBlob);
60 n = blob_size(pBlob);
61 for(i=0; i<n; i++){
62 unsigned char c = x[i];
63 if( isBinary[c] ){
64 break;
65 }
66 }
67 if( i>=n ){
68 return 0; /* Plain text */
69 }
70 for(i=0; i<ArraySize(aMime); i++){
71 if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){
72 return aMime[i].zMimetype;
73 }
74 }
75
--- src/doc.c
+++ src/doc.c
@@ -35,15 +35,10 @@
35 const char *mimetype_from_content(Blob *pBlob){
36 int i;
37 int n;
38 const unsigned char *x;
39
 
 
 
 
 
40 /* A table of mimetypes based on file content prefixes
41 */
42 static const struct {
43 const char *zPrefix; /* The file prefix */
44 int size; /* Length of the prefix */
@@ -54,21 +49,15 @@
49 { "\211PNG\r\n\032\n", 8, "image/png" },
50 { "\377\332\377", 3, "image/jpeg" },
51 { "\377\330\377", 3, "image/jpeg" },
52 };
53
54 if( !looks_like_binary(pBlob) ) {
55 return 0; /* Plain text */
56 }
57 x = (const unsigned char*)blob_buffer(pBlob);
58 n = blob_size(pBlob);
 
 
 
 
 
 
 
 
 
59 for(i=0; i<ArraySize(aMime); i++){
60 if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){
61 return aMime[i].zMimetype;
62 }
63 }
64

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button