(_shishi_crypto_init): Fix prototype, from Nicolas Pouvesle
[shishi.git] / lib / utils.c
blobabac60da40e404b1fcfbdf163ff93b0202be5539
1 /* util.c auxilliary help functions.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi 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 * Shishi 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 Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "internal.h"
24 void
25 _shishi_escapeprint (const char *str, int len)
27 int i;
29 printf ("\t ;; `");
30 for (i = 0; i < len; i++)
31 if ((str[i] >= 'A' && str[i] <= 'Z') ||
32 (str[i] >= 'a' && str[i] <= 'z') ||
33 (str[i] >= '0' && str[i] <= '9') || str[i] == '.')
34 printf ("%c", str[i] & 0xFF);
35 else
36 printf ("\\x%02x", str[i] & 0xFF);
37 printf ("' (length %d bytes)\n", len);
40 void
41 _shishi_hexprint (const char *str, int len)
43 int i;
45 printf ("\t ;; ");
46 for (i = 0; i < len; i++)
48 printf ("%02x ", str[i] & 0xFF);
49 if ((i + 1) % 8 == 0)
50 printf (" ");
51 if ((i + 1) % 16 == 0 && i + 1 < len)
52 printf ("\n\t ;; ");
54 puts ("");
57 void
58 _shishi_binprint (const char *str, int len)
60 int i;
62 printf ("\t ;; ");
63 for (i = 0; i < len; i++)
65 printf ("%d%d%d%d%d%d%d%d ",
66 str[i] & 0x80 ? 1 : 0,
67 str[i] & 0x40 ? 1 : 0,
68 str[i] & 0x20 ? 1 : 0,
69 str[i] & 0x10 ? 1 : 0,
70 str[i] & 0x08 ? 1 : 0,
71 str[i] & 0x04 ? 1 : 0,
72 str[i] & 0x02 ? 1 : 0, str[i] & 0x01 ? 1 : 0);
73 if ((i + 1) % 3 == 0)
74 printf (" ");
75 if ((i + 1) % 6 == 0 && i + 1 < len)
76 printf ("\n\t ;; ");
78 puts ("");
81 void
82 _shishi_bin7print (const char *str, int len)
84 int i;
86 printf ("\t ;; ");
87 for (i = 0; i < len; i++)
89 printf ("%d%d%d%d%d%d%d ",
90 str[i] & 0x40 ? 1 : 0,
91 str[i] & 0x20 ? 1 : 0,
92 str[i] & 0x10 ? 1 : 0,
93 str[i] & 0x08 ? 1 : 0,
94 str[i] & 0x04 ? 1 : 0,
95 str[i] & 0x02 ? 1 : 0, str[i] & 0x01 ? 1 : 0);
96 if ((i + 1) % 3 == 0)
97 printf (" ");
98 if ((i + 1) % 6 == 0 && i + 1 < len)
99 printf ("\n\t ;; ");
101 puts ("");
104 time_t
105 xtime (time_t * t)
107 time_t now;
109 now = time (t);
110 if (now == (time_t) - 1)
112 perror ("time");
113 abort ();
116 return now;
120 xgettimeofday (struct timeval *tv, struct timezone *tz)
122 int rc;
124 rc = gettimeofday (tv, tz);
125 if (rc != 0)
127 perror ("gettimeofday");
128 abort ();
131 return rc;