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
25 _shishi_escapeprint (const char *str
, int len
)
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);
36 printf ("\\x%02x", str
[i
] & 0xFF);
37 printf ("' (length %d bytes)\n", len
);
41 _shishi_hexprint (const char *str
, int len
)
46 for (i
= 0; i
< len
; i
++)
48 printf ("%02x ", str
[i
] & 0xFF);
51 if ((i
+ 1) % 16 == 0 && i
+ 1 < len
)
58 _shishi_binprint (const char *str
, int len
)
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);
75 if ((i
+ 1) % 6 == 0 && i
+ 1 < len
)
82 _shishi_bin7print (const char *str
, int len
)
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);
98 if ((i
+ 1) % 6 == 0 && i
+ 1 < len
)
110 if (now
== (time_t) - 1)
120 xgettimeofday (struct timeval
*tv
, struct timezone
*tz
)
124 rc
= gettimeofday (tv
, tz
);
127 perror ("gettimeofday");