diff options
author | delphij <delphij@FreeBSD.org> | 2015-01-02 21:20:02 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2015-01-02 21:20:02 +0000 |
commit | 1bda30591aca9572e7da640b3af5447296f6d005 (patch) | |
tree | f4ff57ef01d3be17382b5421746e088c6954eeda /contrib/file/src/funcs.c | |
parent | 2ea8fb0629743808332e7dce5b26fd8deb275d99 (diff) | |
parent | f243c198ffedd6408e117b77e39a5a6277aa57b2 (diff) | |
download | FreeBSD-src-1bda30591aca9572e7da640b3af5447296f6d005.zip FreeBSD-src-1bda30591aca9572e7da640b3af5447296f6d005.tar.gz |
MFV r276568:
Update file to 5.22.
MFC after: 2 weeks
Diffstat (limited to 'contrib/file/src/funcs.c')
-rw-r--r-- | contrib/file/src/funcs.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/contrib/file/src/funcs.c b/contrib/file/src/funcs.c index f190349..a60ccaa 100644 --- a/contrib/file/src/funcs.c +++ b/contrib/file/src/funcs.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: funcs.c,v 1.77 2014/11/28 02:46:39 christos Exp $") +FILE_RCSID("@(#)$File: funcs.c,v 1.79 2014/12/16 20:52:49 christos Exp $") #endif /* lint */ #include "magic.h" @@ -531,3 +531,28 @@ file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) free(pb); return rbuf; } + +/* + * convert string to ascii printable format. + */ +protected char * +file_printable(char *buf, size_t bufsiz, const char *str) +{ + char *ptr, *eptr; + const unsigned char *s = (const unsigned char *)str; + + for (ptr = buf, eptr = ptr + bufsiz - 1; ptr < eptr && *s; s++) { + if (isprint(*s)) { + *ptr++ = *s; + continue; + } + if (ptr >= eptr - 3) + break; + *ptr++ = '\\'; + *ptr++ = ((*s >> 6) & 7) + '0'; + *ptr++ = ((*s >> 3) & 7) + '0'; + *ptr++ = ((*s >> 0) & 7) + '0'; + } + *ptr = '\0'; + return buf; +} |