#endif
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.106 2007/10/23 19:58:59 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.107 2007/11/08 00:31:37 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
const char *);
private int check_format_type(const char *, int);
private int check_format(struct magic_set *, struct magic *);
+private int get_op(char);
private size_t maxmagic = 0;
private size_t magicsize = sizeof(struct magic);
private const char hdr[] =
"cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
FILE *f;
- char line[BUFSIZ+1];
+ char line[BUFSIZ];
int errs = 0;
struct magic_entry *marray;
uint32_t marraycount, i, mentrycount = 0;
(void)fprintf(stderr, "%s\n", hdr);
/* read and parse this file */
- for (ms->line = 1; fgets(line, BUFSIZ, f) != NULL; ms->line++) {
+ for (ms->line = 1; fgets(line, sizeof(line), f) != NULL; ms->line++) {
size_t len;
len = strlen(line);
if (len == 0) /* null line, garbage, etc */
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.115 2007/10/25 15:33:17 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.116 2007/10/29 00:54:08 christos Exp $")
#endif /* lint */
int
main(int argc, char *argv[])
{
- int c, i;
+ int c;
+ size_t i;
int action = 0, didsomefiles = 0, errflg = 0;
int flags = 0;
char *home, *usermagic;
}
}
else {
- int i, wid, nw;
- for (wid = 0, i = optind; i < argc; i++) {
- nw = file_mbswidth(argv[i]);
+ size_t j, wid, nw;
+ for (wid = 0, j = (size_t)optind; j < (size_t)argc; j++) {
+ nw = file_mbswidth(argv[j]);
if (nw > wid)
wid = nw;
}
char buf[MAXPATHLEN];
FILE *f;
int wid = 0, cwid;
- size_t len;
if (strcmp("-", fn) == 0) {
f = stdin;
}
while (fgets(buf, MAXPATHLEN, f) != NULL) {
- len = strlen(buf);
- if (len > 0 && buf[len - 1] == '\n')
- buf[len - 1] = '\0';
+ buf[strcspn(buf, "\n")] = '\0';
cwid = file_mbswidth(buf);
if (cwid > wid)
wid = cwid;
rewind(f);
}
- while (fgets(buf, MAXPATHLEN, f) != NULL) {
- len = strlen(buf);
- if (len > 0 && buf[len - 1] == '\n')
- buf[len - 1] = '\0';
+ while (fgets(buf, sizeof(buf), f) != NULL) {
+ buf[strcspn(buf, "\n")] = '\0';
process(buf, wid);
if(nobuffer)
(void)fflush(stdout);
#endif
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.33 2007/06/15 00:01:15 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.34 2007/10/17 19:33:31 christos Exp $")
#endif /* lint */
#ifndef HAVE_VSNPRINTF
file_printf(struct magic_set *ms, const char *fmt, ...)
{
va_list ap;
- size_t len, size;
+ size_t size;
+ ssize_t len;
char *buf;
va_start(ap, fmt);
- if ((len = vsnprintf(ms->o.ptr, ms->o.left, fmt, ap)) >= ms->o.left) {
+ len = vsnprintf(ms->o.ptr, ms->o.left, fmt, ap);
+ if (len == -1)
+ goto out;
+ if (len >= (ssize_t)ms->o.left) {
long diff; /* XXX: really ptrdiff_t */
va_end(ap);
va_start(ap, fmt);
len = vsnprintf(ms->o.ptr, ms->o.left, fmt, ap);
+ if (len == -1)
+ goto out;
}
va_end(ap);
ms->o.ptr += len;
ms->o.left -= len;
return 0;
+out:
+ file_error(ms, errno, "vsnprintf failed");
+ return -1;
}
/*
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$File: magic.c,v 1.43 2007/09/26 20:45:26 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.44 2007/10/17 19:33:31 christos Exp $")
#endif /* lint */
#ifdef __EMX__
struct stat sb;
ssize_t nbytes = 0; /* number of bytes read from a datafile */
int ispipe = 0;
- int mime = ms->flags & MAGIC_MIME;
/*
* one extra for terminating '\0', and
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$File: print.c,v 1.59 2007/03/05 02:41:29 christos Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.60 2007/11/08 00:31:37 christos Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
protected const char *
file_fmttime(uint32_t v, int local)
{
- char *pp, *rt;
+ char *pp;
time_t t = (time_t)v;
struct tm *tm;
pp = asctime(tm);
}
- if ((rt = strchr(pp, '\n')) != NULL)
- *rt = '\0';
+ pp[strcspn(pp, "\n")] = '\0';
return pp;
}
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.101 2007/10/17 19:33:31 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.102 2007/11/08 00:31:37 christos Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
t = ms->offset + m->vallen;
}
else {
- if (*m->value.s == '\0') {
- char *cp = strchr(p->s,'\n');
- if (cp)
- *cp = '\0';
- }
+ if (*m->value.s == '\0')
+ p->s[strcspn(p->s, "\n")] = '\0';
if (file_printf(ms, m->desc, p->s) == -1)
return -1;
t = ms->offset + strlen(p->s);