1 |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
3 |
Entrypoint and utility functions |
4 |
Copyright (C) Matthew Chapman 1999-2000 |
5 |
|
6 |
This program 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. |
10 |
|
11 |
This program 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. |
15 |
|
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., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
20 |
|
21 |
#include "includes.h" |
22 |
|
23 |
void *xmalloc(int size) |
24 |
{ |
25 |
void *mem = malloc(size); |
26 |
if (mem == NULL) |
27 |
{ |
28 |
fprintf(stderr, "xmalloc: Out of memory.\n"); |
29 |
exit(1); |
30 |
} |
31 |
return mem; |
32 |
} |
33 |
|
34 |
void *xrealloc(void *oldmem, int size) |
35 |
{ |
36 |
void *mem = realloc(oldmem, size); |
37 |
if (mem == NULL) |
38 |
{ |
39 |
fprintf(stderr, "xrealloc: Out of memory.\n"); |
40 |
exit(1); |
41 |
} |
42 |
return mem; |
43 |
} |
44 |
|
45 |
void dump_data(unsigned char *p, int len) |
46 |
{ |
47 |
unsigned char *line = p; |
48 |
int i, j; |
49 |
|
50 |
fprintf(stderr, "0000 "); |
51 |
|
52 |
for (i = 0; i < len; i++) |
53 |
{ |
54 |
if ((i & 15) == 0) |
55 |
{ |
56 |
if (i != 0) |
57 |
{ |
58 |
for (j = 0; j < 16; j++) |
59 |
fputc(isprint(line[j]) ? line[j] : '.', |
60 |
stderr); |
61 |
line = p + i; |
62 |
fprintf(stderr, "\n%04x ", line-p); |
63 |
} |
64 |
} |
65 |
|
66 |
fprintf(stderr, "%02X ", p[i]); |
67 |
} |
68 |
|
69 |
fputc('\n', stderr); |
70 |
} |