1
/* miscellaneous.c - Stuff not fitting elsewhere
2
* Copyright (C) 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
29
/* Decide whether the filename is stdout or a real filename and return
30
* an appropriate string. */
32
print_fname_stdout (const char *s)
34
if( !s || (*s == '-' && !s[1]) )
40
/* Decide whether the filename is stdin or a real filename and return
41
* an appropriate string. */
43
print_fname_stdin (const char *s)
45
if( !s || (*s == '-' && !s[1]) )
51
print_string( FILE *fp, const byte *p, size_t n, int delim )
53
print_sanitized_buffer (fp, p, n, delim);
57
print_utf8_string2 ( FILE *fp, const byte *p, size_t n, int delim )
59
print_sanitized_utf8_buffer (fp, p, n, delim);
63
print_utf8_string( FILE *fp, const byte *p, size_t n )
65
print_utf8_string2 (fp, p, n, 0);
69
make_printable_string( const byte *p, size_t n, int delim )
71
return sanitize_buffer (p, n, delim);
76
* Check if the file is compressed.
79
is_file_compressed (const char *s, int *ret_rc)
85
struct magic_compress_s {
89
{ 3, { 0x42, 0x5a, 0x68, 0x00 } }, /* bzip2 */
90
{ 3, { 0x1f, 0x8b, 0x08, 0x00 } }, /* gzip */
91
{ 4, { 0x50, 0x4b, 0x03, 0x04 } }, /* (pk)zip */
94
if ( !s || (*s == '-' && !s[1]) || !ret_rc )
95
return 0; /* We can't check stdin or no file was given */
99
*ret_rc = gpg_error_from_errno (errno);
103
if ( iobuf_get_filelength( a ) < 4 ) {
108
if ( iobuf_read( a, buf, 4 ) == -1 ) {
113
for ( i = 0; i < DIM( magic ); i++ ) {
114
if ( !memcmp( buf, magic[i].magic, magic[i].len ) ) {