]> granicus.if.org Git - file/commitdiff
Limit the CSV test to text files and say so...
authorChristos Zoulas <christos@zoulas.com>
Wed, 26 Jun 2019 20:31:31 +0000 (20:31 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 26 Jun 2019 20:31:31 +0000 (20:31 +0000)
src/file.h
src/funcs.c
src/is_csv.c

index e3c88569ef5b1b27dc448e1276eff0f26eec2b6b..947f2089d0af89372fc0f2709564f7d4e5039d44 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.207 2019/06/08 22:16:24 christos Exp $
+ * @(#)$File: file.h,v 1.208 2019/06/26 20:31:31 christos Exp $
  */
 
 #ifndef __file_h__
@@ -479,7 +479,7 @@ protected int file_ascmagic_with_encoding(struct magic_set *,
 protected int file_encoding(struct magic_set *, const struct buffer *,
     unichar **, size_t *, const char **, const char **, const char **);
 protected int file_is_json(struct magic_set *, const struct buffer *);
-protected int file_is_csv(struct magic_set *, const struct buffer *);
+protected int file_is_csv(struct magic_set *, const struct buffer *, int);
 protected int file_is_tar(struct magic_set *, const struct buffer *);
 protected int file_softmagic(struct magic_set *, const struct buffer *,
     uint16_t *, uint16_t *, int, int);
index 33df4194d3ef846ddaab02c274878e3ca27f013d..069e4d04c8166cac69af988777572e873188e5c9 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.105 2019/06/08 22:16:24 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.106 2019/06/26 20:31:31 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -285,7 +285,7 @@ file_buffer(struct magic_set *ms, int fd, struct stat *st,
 
        /* Check if we have a CSV file */
        if ((ms->flags & MAGIC_NO_CHECK_CSV) == 0) {
-               m = file_is_csv(ms, &b);
+               m = file_is_csv(ms, &b, looks_text);
                if ((ms->flags & MAGIC_DEBUG) != 0)
                        (void)fprintf(stderr, "[try csv %d]\n", m);
                if (m) {
index 961975d94acda17f0284e3f2efbc71e502a6c534..0081088c80eca521293eb39e77b44cf735d28d1f 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: is_csv.c,v 1.3 2019/06/24 23:40:03 christos Exp $")
+FILE_RCSID("@(#)$File: is_csv.c,v 1.4 2019/06/26 20:31:31 christos Exp $")
 #endif
 
 #include <string.h>
@@ -131,12 +131,14 @@ csv_parse(const unsigned char *uc, const unsigned char *ue)
 
 #ifndef TEST
 int
-file_is_csv(struct magic_set *ms, const struct buffer *b)
+file_is_csv(struct magic_set *ms, const struct buffer *b, int looks_text)
 {
        const unsigned char *uc = CAST(const unsigned char *, b->fbuf);
        const unsigned char *ue = uc + b->flen;
        int mime = ms->flags & MAGIC_MIME;
 
+       if (!looks_text)
+               return 0;
 
        if ((ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION)) != 0)
                return 0;
@@ -153,7 +155,7 @@ file_is_csv(struct magic_set *ms, const struct buffer *b)
                return 1;
        }
 
-       if (file_printf(ms, "CSV data") == -1)
+       if (file_printf(ms, "CSV text") == -1)
                return -1;
 
        return 1;