#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.68 2003/10/14 19:17:17 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.69 2003/10/14 19:29:55 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
int mapped;
if (magicsize != FILE_MAGICSIZE) {
- file_error(ms, 0, "Magic element size %lu != %lu",
+ file_error(ms, 0, "magic element size %lu != %lu",
(unsigned long)sizeof(*magic),
(unsigned long)FILE_MAGICSIZE);
return -1;
#ifndef COMPILE_ONLY
if ((rv = apprentice_map(ms, &magic, &nmagic, fn)) == -1) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn("Using regular magic file `%s'", fn);
+ file_magwarn("using regular magic file `%s'", fn);
rv = apprentice_file(ms, &magic, &nmagic, fn, action);
if (rv != 0)
return -1;
free(mfn);
free(mlist);
mlist = NULL;
- file_error(ms, 0, "Couldn't find any magic files!");
+ file_error(ms, 0, "could not find any magic files!");
return NULL;
}
return mlist;
f = fopen(fn, "r");
if (f == NULL) {
if (errno != ENOENT)
- file_error(ms, errno, "Can't read magic file %s", fn);
+ file_error(ms, errno, "cannot read magic file `%s'",
+ fn);
return -1;
}
break;
default:
if (ms->flags & MAGIC_CHECK)
- file_magwarn("can't happen: m->type=%d\n",
+ file_magwarn("cannot happen: m->type=%d\n",
m->type);
return ~0U;
}
*p = getstr(ms, *p, m->value.s, sizeof(m->value.s), &slen);
if (*p == NULL) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn("Cannot get string from `%s'",
+ file_magwarn("cannot get string from `%s'",
m->value.s);
return -1;
}
if (isspace((unsigned char) c))
break;
if (p >= pmax) {
- file_error(ms, 0, "String too long: `%s'", origs);
+ file_error(ms, 0, "string too long: `%s'", origs);
return NULL;
}
if(c == '\\') {
return -1;
if (fstat(fd, &st) == -1) {
- file_error(ms, errno, "Cannot stat `%s'", dbname);
+ file_error(ms, errno, "cannot stat `%s'", dbname);
goto error;
}
#ifdef QUICK
if ((mm = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == MAP_FAILED) {
- file_error(ms, errno, "Cannot map `%s'", dbname);
+ file_error(ms, errno, "cannot map `%s'", dbname);
goto error;
}
#define RET 2
goto error;
}
if (read(fd, mm, (size_t)st.st_size) != (size_t)st.st_size) {
- file_error(ms, errno, "Read failed");
+ file_badread(ms);
goto error;
}
#define RET 1
ptr = (uint32_t *)(void *)*magicp;
if (*ptr != MAGICNO) {
if (swap4(*ptr) != MAGICNO) {
- file_error(ms, 0, "Bad magic in `%s'");
+ file_error(ms, 0, "bad magic in `%s'");
goto error;
}
needsbyteswap = 1;
return -1;
if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
- file_error(ms, errno, "Cannot open `%s'", dbname);
+ file_error(ms, errno, "cannot open `%s'", dbname);
return -1;
}
if (write(fd, ar, sizeof(ar)) != (ssize_t)sizeof(ar)) {
- file_error(ms, errno, "Error writing `%s'", dbname);
+ file_error(ms, errno, "error writing `%s'", dbname);
return -1;
}
if (lseek(fd, (off_t)sizeof(struct magic), SEEK_SET)
!= sizeof(struct magic)) {
- file_error(ms, errno, "Error seeking `%s'", dbname);
+ file_error(ms, errno, "error seeking `%s'", dbname);
return -1;
}
if (write(fd, *magicp, (sizeof(struct magic) * *nmagicp))
!= (ssize_t)(sizeof(struct magic) * *nmagicp)) {
- file_error(ms, errno, "Error writing `%s'", dbname);
+ file_error(ms, errno, "error writing `%s'", dbname);
return -1;
}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: apptype.c,v 1.4 2003/10/14 19:17:17 christos Exp $")
+FILE_RCSID("@(#)$Id: apptype.c,v 1.5 2003/10/14 19:29:55 christos Exp $")
#endif /* lint */
#ifdef __EMX__
if (fn)
filename = strdup(fn);
else if ((filename = tempnam("./", "tmp")) == NULL) {
- file_error(ms, errno, "Can't create tempnam");
+ file_error(ms, errno, "cannot create tempnam");
return -1;
}
/* qualify the filename to prevent extraneous searches */
if (fn == NULL) {
if ((fp = fopen(path, "wb")) == NULL) {
- file_error(ms, errno, "Can't open tmp file `%s'", path);
+ file_error(ms, errno, "cannot open tmp file `%s'", path);
return -1;
}
if (fwrite(buf, 1, nb, fp) != nb) {
- file_error(ms, errno, "Can't write tmp file `%s'", path);
+ file_error(ms, errno, "cannot write tmp file `%s'",
+ path);
return -1;
}
(void)fclose(fp);
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: compress.c,v 1.33 2003/10/14 19:17:17 christos Exp $")
+FILE_RCSID("@(#)$Id: compress.c,v 1.34 2003/10/14 19:29:55 christos Exp $")
#endif
#endif
if (tfd == -1) {
file_error(ms, errno,
- "Can't create temporary file for pipe copy");
+ "cannot create temporary file for pipe copy");
return -1;
}
switch (r) {
case -1:
- file_error(ms, errno, "Error copying from pipe to temp file");
+ file_error(ms, errno, "error copying from pipe to temp file");
return -1;
case 0:
break;
default:
- file_error(ms, errno, "Error while writing to temp file");
+ file_error(ms, errno, "error while writing to temp file");
return -1;
}
* can still access the phantom inode.
*/
if ((fd = dup2(tfd, fd)) == -1) {
- file_error(ms, errno, "Couldn't dup destcriptor for temp file");
+ file_error(ms, errno, "could not dup descriptor for temp file");
return -1;
}
(void)close(tfd);
#endif
if (pipe(fdin) == -1 || pipe(fdout) == -1) {
- file_error(ms, errno, "Cannot create pipe");
+ file_error(ms, errno, "cannot create pipe");
return 0;
}
switch (fork()) {
exit(1);
/*NOTREACHED*/
case -1:
- file_error(ms, errno, "Could not fork");
+ file_error(ms, errno, "could not fork");
return 0;
default: /* parent */
#endif
#include <stdlib.h>
#include <sys/stat.h>
-/* Since major is a function on SVR4, we can't use `ifndef major'. */
+/* Since major is a function on SVR4, we cannot use `ifndef major'. */
#ifdef MAJOR_IN_MKDEV
# include <sys/mkdev.h>
# define HAVE_MAJOR
#undef HAVE_MAJOR
#ifndef lint
-FILE_RCSID("@(#)$Id: fsmagic.c,v 1.42 2003/10/14 19:17:17 christos Exp $")
+FILE_RCSID("@(#)$Id: fsmagic.c,v 1.43 2003/10/14 19:29:55 christos Exp $")
#endif /* lint */
protected int
if (ret) {
if (ms->flags & MAGIC_ERROR) {
- file_error(ms, errno, "Can't stat `%s'", fn);
+ file_error(ms, errno, "cannot stat `%s'", fn);
return -1;
}
- if (file_printf(ms, "Can't stat `%s' (%s)",
+ if (file_printf(ms, "cannot open (%s)",
fn, strerror(errno)) == -1)
return -1;
return 1;
va_list va;
/* Only the first error is ok */
if (ms->haderr)
- return;
+ return;
va_start(va, f);
- (void) vsnprintf(ms->o.buf, ms->o.size, f, va);
+ (void)vsnprintf(ms->o.buf, ms->o.size, f, va);
+ va_end(va);
+ if (error > 0) {
+ size_t len = strlen(ms->o.buf);
+ (void)snprintf(ms->o.buf + len, ms->o.size - len, " (%s)",
+ strerror(error));
+ }
ms->haderr++;
ms->error = error;
- va_end(va);
}
protected void
file_oomem(struct magic_set *ms)
{
- file_error(ms, errno, "Cannot allocate memory");
+ file_error(ms, errno, "cannot allocate memory");
}
protected void
file_badseek(struct magic_set *ms)
{
- file_error(ms, errno, "Error seeking");
+ file_error(ms, errno, "error seeking");
}
protected void
file_badread(struct magic_set *ms)
{
- file_error(ms, errno, "Error reading");
+ file_error(ms, errno, "error reading");
}
protected int
file_reset(struct magic_set *ms)
{
if (ms->mlist == NULL) {
- file_error(ms, 0, "No magic files loaded");
+ file_error(ms, 0, "no magic files loaded");
return -1;
}
ms->o.ptr = ms->o.buf;
#include "tar.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: is_tar.c,v 1.22 2003/03/27 19:09:45 christos Exp $")
+FILE_RCSID("@(#)$Id: is_tar.c,v 1.23 2003/10/14 19:29:55 christos Exp $")
#endif
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
p = header->charptr;
for (i = sizeof(union record); --i >= 0;) {
/*
- * We can't use unsigned char here because of old compilers,
+ * We cannot use unsigned char here because of old compilers,
* e.g. V7.
*/
sum += 0xFF & *p++;
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: magic.c,v 1.13 2003/10/14 19:17:17 christos Exp $")
+FILE_RCSID("@(#)$Id: magic.c,v 1.14 2003/10/14 19:29:55 christos Exp $")
#endif /* lint */
#ifdef __EMX__
if (inname == NULL)
fd = STDIN_FILENO;
else if ((fd = open(inname, O_RDONLY)) < 0) {
- /* We can't open it, but we were able to stat it. */
+ /* We cannot open it, but we were able to stat it. */
if (sb.st_mode & 0002)
if (file_printf(ms, "writable, ") == -1)
return NULL;
* try looking at the first HOWMANY bytes
*/
if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
- file_error(ms, errno, "Cannot read `%s'", inname);
+ file_error(ms, errno, "cannot read `%s'", inname);
goto done;
}
* be an ELF file, and the file is at least 5 bytes
* long, so if it's an ELF file it has at least one
* byte past the ELF magic number - try extracting
- * information from the ELF headers that can't easily
+ * information from the ELF headers that cannot easily
* be extracted with rules in the magic file.
*/
file_tryelf(ms, fd, buf, (size_t)nbytes);
return ms->haderr ? ms->o.buf : NULL;
}
+public int
+magic_errno(struct magic_set *ms)
+{
+ return ms->haderr ? ms->error : 0;
+}
+
public int
magic_setflags(struct magic_set *ms, int flags)
{
int magic_load(magic_t, const char *);
int magic_compile(magic_t, const char *);
int magic_check(magic_t, const char *);
+int magic_errno(magic_t);
#ifdef __cplusplus
};
* appear at fixed offsets into the file. Don't make HOWMANY
* too high unless you have a very fast CPU.
*
- * $Id: names.h,v 1.22 2003/09/25 18:30:26 christos Exp $
+ * $Id: names.h,v 1.23 2003/10/14 19:29:55 christos Exp $
*/
/*
{ "HTML document", "text/html", },
{ "BCPL program", "text/x-bcpl" },
{ "M4 macro language pre-processor", "text/x-m4" },
- { "can't happen error on names.h/types", "error/x-error" },
+ { "cannot happen error on names.h/types", "error/x-error" },
{ 0, 0}
};
#include "readelf.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: readelf.c,v 1.34 2003/10/14 19:17:17 christos Exp $")
+FILE_RCSID("@(#)$Id: readelf.c,v 1.35 2003/10/14 19:29:55 christos Exp $")
#endif
#ifdef ELFCORE
ssize_t bufsize;
if (size != ph_size) {
- file_error(ms, 0, "Corrupted program header size");
+ file_error(ms, 0, "corrupted program header size");
return -1;
}
/*
Elf64_Shdr sh64;
if (size != sh_size) {
- file_error(ms, 0, "Corrupted section header size");
+ file_error(ms, 0, "corrupted section header size");
return -1;
}
off_t savedoffset;
if (size != ph_size) {
- file_error(ms, 0, "Corrupted program header size");
+ file_error(ms, 0, "corrupted program header size");
return -1;
}
if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
int swap;
/*
- * If we can't seek, it must be a pipe, socket or fifo.
+ * If we cannot seek, it must be a pipe, socket or fifo.
*/
if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
fd = file_pipe2file(ms, fd, buf, nbytes);
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.61 2003/10/14 19:17:17 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.62 2003/10/14 19:29:55 christos Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
default:
matched = 0;
- file_error(ms, 0, "can't happen: invalid relation `%c'",
+ file_error(ms, 0, "cannot happen: invalid relation `%c'",
m->reln);
return -1;
}
*
* Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
*
- * $Id: tar.h,v 1.6 2003/03/23 21:16:26 christos Exp $ # checkin only
+ * $Id: tar.h,v 1.7 2003/10/14 19:29:56 christos Exp $ # checkin only
*/
/*
- * Kludge for handling systems that can't cope with multiple
+ * Kludge for handling systems that cannot cope with multiple
* external definitions of a variable. In ONE routine (tar.c),
* we #define TAR_EXTERN to null; here, we set it to "extern" if
* it is not already set.