1 /* miscellaneous.c - Stuff not fitting elsewhere
2 * Copyright (C) 2003, 2006 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
30 /* Decide whether the filename is stdout or a real filename and return
31 * an appropriate string. */
33 print_fname_stdout (const char *s
)
35 if( !s
|| (*s
== '-' && !s
[1]) )
41 /* Decide whether the filename is stdin or a real filename and return
42 * an appropriate string. */
44 print_fname_stdin (const char *s
)
46 if( !s
|| (*s
== '-' && !s
[1]) )
51 /* fixme: Globally replace it by print_sanitized_buffer. */
53 print_string( FILE *fp
, const byte
*p
, size_t n
, int delim
)
55 print_sanitized_buffer (fp
, p
, n
, delim
);
59 print_utf8_string2 ( FILE *fp
, const byte
*p
, size_t n
, int delim
)
61 print_sanitized_utf8_buffer (fp
, p
, n
, delim
);
65 print_utf8_string( FILE *fp
, const byte
*p
, size_t n
)
67 print_utf8_string2 (fp
, p
, n
, 0);
71 make_printable_string (const void *p
, size_t n
, int delim
)
73 return sanitize_buffer (p
, n
, delim
);
78 * Check if the file is compressed.
81 is_file_compressed (const char *s
, int *ret_rc
)
88 struct magic_compress_s
{
92 { 3, { 0x42, 0x5a, 0x68, 0x00 } }, /* bzip2 */
93 { 3, { 0x1f, 0x8b, 0x08, 0x00 } }, /* gzip */
94 { 4, { 0x50, 0x4b, 0x03, 0x04 } }, /* (pk)zip */
97 if ( iobuf_is_pipe_filename (s
) || !ret_rc
)
98 return 0; /* We can't check stdin or no file was given */
102 *ret_rc
= gpg_error_from_syserror ();
106 if ( iobuf_get_filelength( a
, &overflow
) < 4 && !overflow
) {
111 if ( iobuf_read( a
, buf
, 4 ) == -1 ) {
116 for ( i
= 0; i
< DIM( magic
); i
++ ) {
117 if ( !memcmp( buf
, magic
[i
].magic
, magic
[i
].len
) ) {
130 /* Try match against each substring of multistr, delimited by | */
132 match_multistr (const char *multistr
,const char *match
)
136 size_t seglen
= strcspn (multistr
,"|");
139 /* Using the localized strncasecmp! */
140 if (strncasecmp(multistr
,match
,seglen
)==0)
143 if (*multistr
== '|')