1
1
/* stringhelp.c - standard string helper functions
2
* Copyright (C) 1998, 1999, 2000, 2001, 2003,
3
* 2004, 2005 Free Software Foundation, Inc.
2
* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005,
3
* 2006 Free Software Foundation, Inc.
5
5
* This file is part of GnuPG.
17
17
* You should have received a copy of the GNU General Public License
18
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22
23
#include <config.h>
237
make_basename(const char *filepath)
238
make_basename(const char *filepath, const char *inputpath)
243
return riscos_make_basename(filepath, inputpath);
241
246
if ( !(p=strrchr(filepath, '/')) )
242
#ifdef HAVE_DRIVE_LETTERS
247
#ifdef HAVE_DRIVE_LETTERS
243
248
if ( !(p=strrchr(filepath, '\\')) )
244
249
if ( !(p=strrchr(filepath, ':')) )
247
252
return jnlib_xstrdup(filepath);
341
/* Convert 2 hex characters at S to a byte value. Return this value
342
or -1 if there is an error. */
344
hextobyte (const char *s)
348
if ( *s >= '0' && *s <= '9' )
350
else if ( *s >= 'A' && *s <= 'F' )
351
c = 16 * (10 + *s - 'A');
352
else if ( *s >= 'a' && *s <= 'f' )
353
c = 16 * (10 + *s - 'a');
357
if ( *s >= '0' && *s <= '9' )
359
else if ( *s >= 'A' && *s <= 'F' )
361
else if ( *s >= 'a' && *s <= 'f' )
335
369
/* Print a BUFFER to stream FP while replacing all control characters
336
and the character DELIM with standard C escape sequences. Returns
337
the number of characters printed. */
370
and the characters DELIM and DELIM2 with standard C escape
371
sequences. Returns the number of characters printed. */
339
print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
373
print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
374
int delim, int delim2)
342
376
const unsigned char *p = buffer;
343
377
size_t count = 0;
345
379
for (; length; length--, p++, count++)
347
if (*p < 0x20 || *p == 0x7f || *p == delim)
381
/* Fixme: Check whether *p < 0xa0 is correct for utf8 encoding. */
383
|| (*p >= 0x7f && *p < 0xa0)
386
|| ((delim || delim2) && *p=='\\'))
353
395
else if (*p == '\r')
355
400
else if (*p == '\f')
357
405
else if (*p == '\v')
359
410
else if (*p == '\b')
365
422
fprintf (fp, "x%02x", *p);
436
/* Same as print_sanitized_buffer2 but with just one delimiter. */
438
print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
441
return print_sanitized_buffer2 (fp, buffer, length, delim, 0);
377
446
print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
378
447
size_t length, int delim)
473
print_sanitized_string2 (FILE *fp, const char *string, int delim, int delim2)
475
return string? print_sanitized_buffer2 (fp, string, strlen (string),
404
480
print_sanitized_string (FILE *fp, const char *string, int delim)
406
482
return string? print_sanitized_buffer (fp, string, strlen (string), delim):0;
424
500
const unsigned char *save_p;
425
501
char *buffer, *d;
427
/* first count length */
503
/* First count length. */
428
504
for (save_n = n, save_p = p, buflen=1 ; n; n--, p++ )
430
506
if ( *p < 0x20 || *p == 0x7f || *p == delim || (delim && *p=='\\'))