(Merged by Marcus Meissner <marcus@jet.franken.de>)
[wine/testsucceed.git] / tools / winebuild / utils.c
blob19b50bae1392549b681404927df8c324595e978b
1 /* small utility functions for winebuild */
3 #include <ctype.h>
4 #include <stdarg.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
10 #include "build.h"
12 void *xmalloc (size_t size)
14 void *res;
16 res = malloc (size ? size : 1);
17 if (res == NULL)
19 fprintf (stderr, "Virtual memory exhausted.\n");
20 exit (1);
22 return res;
25 void *xrealloc (void *ptr, size_t size)
27 void *res = realloc (ptr, size);
28 if (res == NULL)
30 fprintf (stderr, "Virtual memory exhausted.\n");
31 exit (1);
33 return res;
36 char *xstrdup( const char *str )
38 char *res = strdup( str );
39 if (!res)
41 fprintf (stderr, "Virtual memory exhausted.\n");
42 exit (1);
44 return res;
47 char *strupper(char *s)
49 char *p;
50 for (p = s; *p; p++) *p = toupper(*p);
51 return s;
54 void fatal_error( const char *msg, ... )
56 va_list valist;
57 va_start( valist, msg );
58 if (input_file_name && current_line)
59 fprintf( stderr, "%s:%d: ", input_file_name, current_line );
60 vfprintf( stderr, msg, valist );
61 va_end( valist );
62 exit(1);
65 /* dump a byte stream into the assembly code */
66 void dump_bytes( FILE *outfile, const unsigned char *data, int len, const char *label )
68 int i;
70 fprintf( outfile, "\nstatic unsigned char %s[] = \n{", label );
72 for (i = 0; i < len; i++)
74 if (!(i & 0x0f)) fprintf( outfile, "\n " );
75 fprintf( outfile, "%d", *data++ );
76 if (i < len - 1) fprintf( outfile, ", " );
78 fprintf( outfile, "\n};\n" );