support.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* support.h - Cryptoki implementation support functions.
  2. Copyright (C) 2006 g10 Code GmbH
  3. This file is part of Scute.
  4. Scute is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. Scute is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Scute; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. In addition, as a special exception, g10 Code GmbH gives permission
  16. to link this library: with the Mozilla Foundation's code for
  17. Mozilla (or with modified versions of it that use the same license
  18. as the "Mozilla" code), and distribute the linked executables. You
  19. must obey the GNU General Public License in all respects for all of
  20. the code used other than "Mozilla". If you modify this file, you
  21. may extend this exception to your version of the file, but you are
  22. not obligated to do so. If you do not wish to do so, delete this
  23. exception statement from your version. */
  24. #ifndef SUPPORT_H
  25. #define SUPPORT_H 1
  26. #define spacep(p) (*(p) == ' ' || *(p) == '\t')
  27. #define digitp(p) (*(p) >= '0' && *(p) <= '9')
  28. #define hexdigitp(a) (digitp (a) \
  29. || (*(a) >= 'A' && *(a) <= 'F') \
  30. || (*(a) >= 'a' && *(a) <= 'f'))
  31. #define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
  32. *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
  33. #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
  34. #define DIM(x) (sizeof (x) / sizeof (x[0]))
  35. /* Copy a string into its location, with blank character padding. */
  36. static inline void
  37. scute_copy_string (char *dest, char *src, int max_len)
  38. {
  39. int i;
  40. for (i = 0; (i < max_len) && (*src != '\0'); i++)
  41. *(dest++) = *(src++);
  42. while (i++ < max_len)
  43. *(dest++) = ' ';
  44. }
  45. #ifndef HAVE_STPCPY
  46. #include "stpcpy.h"
  47. #endif
  48. /*-- Simple replacement functions. */
  49. #ifndef HAVE_TTYNAME
  50. /* Systems without ttyname (W32) will merely return NULL. */
  51. static inline char *
  52. ttyname (int fd)
  53. {
  54. return NULL;
  55. }
  56. #endif /* !HAVE_TTYNAME */
  57. const char *get_gpgsm_path (void);
  58. const char *get_gpg_agent_path (void);
  59. /* Set up the default home directory. The usual --homedir option
  60. should be parsed later. */
  61. const char *default_homedir (void);
  62. /* Construct a filename from the NULL terminated list of parts. Tilde
  63. expansion is done here. */
  64. char *make_filename (const char *first_part, ...);
  65. #endif /* !SUPPORT_H */