]> err.no Git - sope/blob - sope-gdl1/GDLAccess/common.h
renamed PostgreSQL72 to PostgreSQL, install in Library/GDLAdaptors-1.1
[sope] / sope-gdl1 / GDLAccess / common.h
1 /* 
2    EOAdaptorChannel.m
3
4    Copyright (C) 1996 Free Software Foundation, Inc.
5
6    Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
7    Date: October 1996
8
9    This file is part of the GNUstep Database Library.
10
11    This library is free software; you can redistribute it and/or
12    modify it under the terms of the GNU Library General Public
13    License as published by the Free Software Foundation; either
14    version 2 of the License, or (at your option) any later version.
15
16    This library is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    Library General Public License for more details.
20
21    You should have received a copy of the GNU Library General Public
22    License along with this library; see the file COPYING.LIB.
23    If not, write to the Free Software Foundation,
24    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26 // $Id: common.h 1 2004-08-20 10:38:46Z znek $
27
28 #ifndef __common_h__
29 #define __common_h__
30
31 #include <string.h>
32 #include <stdlib.h>
33
34 #ifndef __WIN32__
35 #  include <unistd.h>
36 #  include <pwd.h>
37 #endif
38
39 #include <sys/types.h>
40 #include <stdarg.h>
41 #include <ctype.h>
42
43 #import <Foundation/NSZone.h>
44 #import <Foundation/Foundation.h>
45 #import <Foundation/NSUtilities.h>
46 #import <Foundation/NSObjCRuntime.h>
47
48 #if NeXT_RUNTIME || APPLE_RUNTIME
49 #  define sel_eq(sela,selb) (sela==selb?YES:NO)
50 #endif
51
52 #if LIB_FOUNDATION_LIBRARY
53 #  import <Foundation/exceptions/GeneralExceptions.h>
54 #  import <extensions/objc-runtime.h>
55 #else
56 #  include <NGExtensions/NGObjectMacros.h>
57 #  include <NGExtensions/NSString+Ext.h>
58 #endif
59
60
61 // ******************** common functions ********************
62
63 static inline void *Malloc(int) __attribute__((unused));
64 static inline void *Calloc(int, int) __attribute__((unused));
65 static inline void *Realloc(void*, int) __attribute__((unused));
66 static inline void Free(void*) __attribute__((unused));
67
68 static inline int Strlen(const char*) __attribute__((unused));
69 static inline char* Strdup(const char*) __attribute__((unused));
70 static inline char* Strcpy (char*, const char*) __attribute__((unused));
71 static inline char* Strncpy (char*, const char*, unsigned)
72     __attribute__((unused));
73 static inline char* Strcat (char*, const char*) __attribute__((unused));
74 static inline char* Strncat (char*, const char*, unsigned)
75     __attribute__((unused));
76 static inline int Strcmp(const char*, const char*) __attribute__((unused));
77 static inline int Strncmp(const char*, const char*, unsigned)
78     __attribute__((unused));
79 static inline int Atoi(const char*) __attribute__((unused));
80 static inline long Atol(const char*) __attribute__((unused));
81
82 static inline void *Malloc(int size) {
83   return malloc(size);
84 }
85
86 static inline void *MallocAtomic(int size) {
87   return malloc(size);
88 }
89
90 static inline void Free(void* p) {
91   if (p) free(p);
92 }
93
94 static inline void *Calloc(int elem, int size) {
95   return calloc(elem, size);
96 }
97
98 static inline void *CallocAtomic(int elem, int size) {
99   return calloc(elem, size);
100 }
101
102 static inline void *Realloc(void* p, int size) {
103   return realloc(p, size);
104 }
105
106 static inline int Strlen(const char* s) {
107   return s ? strlen(s) : 0;
108 }
109
110 static inline char* Strdup(const char* s) {
111   return s ? strcpy(Malloc(strlen(s) + 1), s) : NULL;
112 }
113
114 static inline char* Strcpy (char* d, const char* s) {
115   return s && d ? strcpy(d, s) : d;
116 }
117
118 static inline char* Strncpy (char* d, const char* s, unsigned size) {
119   return s && d ? strncpy(d, s, size) : d;
120 }
121
122 static inline char* Strcat (char* d, const char* s) {
123   return s && d ? strcat(d, s) : d;
124 }
125
126 static inline char* Strncat (char* d, const char* s , unsigned size) {
127   return s && d ? strncat(d, s , size) : d;
128 }
129
130 static inline int Strcmp(const char* p, const char* q) {
131     if(!p) {
132         if(!q)
133             return 0;
134         else return -1;
135     }
136     else {
137         if(!q)
138             return 1;
139         else return strcmp(p, q);
140     }
141 }
142
143 static inline int Strncmp(const char* p, const char* q, unsigned size) {
144     if(!p) {
145         if(!q)
146             return 0;
147         else return -1;
148     }
149     else {
150         if(!q)
151             return 1;
152         else return strncmp(p, q, size);
153     }
154 }
155
156 static inline int Atoi(const char* str)
157 {
158     return str ? atoi(str) : 0;
159 }
160
161 static inline long Atol(const char *str)
162 {
163   return str ? atol(str) : 0;
164 }
165
166 #ifndef MAX
167 #define MAX(a, b) \
168     ({typedef _ta = (a), _tb = (b);   \
169         _ta _a = (a); _tb _b = (b);     \
170         _a > _b ? _a : _b; })
171 #endif
172
173 #ifndef MIN
174 #define MIN(a, b) \
175     ({typedef _ta = (a), _tb = (b);   \
176         _ta _a = (a); _tb _b = (b);     \
177         _a < _b ? _a : _b; })
178 #endif
179
180 #if !LIB_FOUNDATION_LIBRARY
181
182 #ifndef CREATE_AUTORELEASE_POOL
183 #define CREATE_AUTORELEASE_POOL(pool) \
184   id pool = [[NSAutoreleasePool alloc] init]
185 #endif
186
187 #endif /* ! LIB_FOUNDATION_LIBRARY */
188
189
190 #if !LIB_FOUNDATION_LIBRARY
191
192 static inline char *Ltoa(long nr, char *str, int base)
193 {
194     char buff[34], rest, is_negative;
195     int ptr;
196
197     ptr = 32;
198     buff[33] = '\0';
199     if(nr < 0) {
200         is_negative = 1;
201         nr = -nr;
202     }
203     else
204         is_negative = 0;
205
206     while(nr != 0) {
207         rest = nr % base;
208         if(rest > 9)
209             rest += 'A' - 10;
210         else
211             rest += '0';
212         buff[ptr--] = rest;
213         nr /= base;
214     }
215     if(ptr == 32)
216         buff[ptr--] = '0';
217     if(is_negative)
218         buff[ptr--] = '-';
219
220     Strcpy(str, &buff[ptr+1]);
221
222     return(str);
223 }
224 #endif
225
226 #if !LIB_FOUNDATION_LIBRARY
227
228 @interface NSObject(FoundationExtGDLAccess)
229 - (void)subclassResponsibility:(SEL)sel;
230 - (void)notImplemented:(SEL)sel;
231 @end
232
233 #endif
234
235 #if !GNU_RUNTIME
236 #  ifndef SEL_EQ
237 #    define SEL_EQ(__A__,__B__) (__A__==__B__ ? YES : NO)
238 #  endif
239 #else
240 #  ifndef SEL_EQ
241 #    include <objc/objc.h>
242 #    define SEL_EQ(__A__,__B__) sel_eq(__A__,__B__)
243 #  endif
244 #endif
245
246 #endif /* __common_h__ */