Code changes to make external python work in windows. Changes credit to WiSo
[vuplus_xbmc] / lib / libXBMS / ccutil.c
1 // Place the code and data below here into the LIBXBMS section.
2 #ifndef __GNUC__
3 #pragma code_seg( "LIBXBMS" )
4 #pragma data_seg( "LIBXBMS_RW" )
5 #pragma bss_seg( "LIBXBMS_RW" )
6 #pragma const_seg( "LIBXBMS_RD" )
7 #pragma comment(linker, "/merge:LIBXBMS_RW=LIBXBMS")
8 #pragma comment(linker, "/merge:LIBXBMS_RD=LIBXBMS")
9 #endif
10 /*   -*- c -*-
11  * 
12  *  ----------------------------------------------------------------------
13  *  Misc utilities.
14  *  ----------------------------------------------------------------------
15  *
16  *  Copyright (c) 2002-2003 by PuhPuh
17  *  
18  *  This code is copyrighted property of the author.  It can still
19  *  be used for any non-commercial purpose following conditions:
20  *  
21  *      1) This copyright notice is not removed.
22  *      2) Source code follows any distribution of the software
23  *         if possible.
24  *      3) Copyright notice above is found in the documentation
25  *         of the distributed software.
26  *  
27  *  Any express or implied warranties are disclaimed.  Author is
28  *  not liable for any direct or indirect damages caused by the use
29  *  of this software.
30  *
31  *  ----------------------------------------------------------------------
32  *
33  *  This code has been integrated into XBMC Media Center.  
34  *  As such it can me copied, redistributed and modified under
35  *  the same conditions as the XBMC itself.
36  *
37  */
38
39
40 #include "ccincludes.h"
41 #include "ccutil.h"
42
43 void cc_fatal(const char *m)
44 {
45 #if 0
46   fprintf(stderr, "FATAL ERROR%s%s\n", 
47           (m != NULL) ? ": " : "",
48           (m != NULL) ? m :  "");
49 #endif
50   exit(-1);
51 }
52
53 void *cc_xmalloc(size_t n)
54 {
55   void *r;
56
57   r = malloc(n);
58   if (r == NULL)
59     cc_fatal("Out of memory");
60   return r;
61 }
62
63 void *cc_xcalloc(size_t n, size_t s)
64 {
65   void *r;
66
67   r = calloc(n, s);
68   if (r == NULL)
69     cc_fatal("Out of memory");
70   return r;
71 }
72
73 void *cc_xrealloc(void *o, size_t n)
74 {
75   void *r;
76
77   r = realloc(o, n);
78   if (r == NULL)
79     cc_fatal("Out of memory");
80   return r;
81 }
82
83 void *cc_xstrdup(const char *s)
84 {
85   char *r;
86
87   r = strdup(s != NULL ? s : "");
88   if (r == NULL)
89     cc_fatal("Out of memory");
90   return r;
91 }
92
93 void *cc_xmemdup(const void *s, size_t len)
94 {
95   unsigned char *r;
96
97   r = cc_xmalloc(len + 1);
98   r[len] = '\0';
99   if (len > 0)
100     memcpy(r, s, len);
101   return (void *)r;
102 }
103
104 void cc_xfree(void *p)
105 {
106   if (p != NULL)
107     free(p);
108 }
109
110 /* eof (ccutil.c) */