]> err.no Git - sope/blob - sope-gdl1/GDLAccess/common.h
added missing inline pathes
[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
27 #ifndef __common_h__
28 #define __common_h__
29
30 #include <string.h>
31 #include <stdlib.h>
32
33 #ifndef __WIN32__
34 #  include <unistd.h>
35 #  include <pwd.h>
36 #endif
37
38 #include <sys/types.h>
39 #include <stdarg.h>
40 #include <ctype.h>
41
42 #import <Foundation/NSZone.h>
43 #import <Foundation/Foundation.h>
44
45 #if !(COCOA_Foundation_LIBRARY || NeXT_Foundation_LIBRARY)
46 #  import <Foundation/NSUtilities.h>
47 #endif
48
49 #import <Foundation/NSObjCRuntime.h>
50
51 #if NeXT_RUNTIME || APPLE_RUNTIME
52 #  define sel_eq(sela,selb) (sela==selb?YES:NO)
53 #endif
54
55 #if LIB_FOUNDATION_LIBRARY
56 #  import <extensions/objc-runtime.h>
57 #else
58 #  include <NGExtensions/NGObjectMacros.h>
59 #  include <NGExtensions/NSString+Ext.h>
60 #endif
61
62
63 // ******************** common functions ********************
64
65 static inline void *Malloc(int) __attribute__((unused));
66 static inline void *Calloc(int, int) __attribute__((unused));
67 static inline void *Realloc(void*, int) __attribute__((unused));
68 static inline void Free(void*) __attribute__((unused));
69
70 static inline int Strlen(const char*) __attribute__((unused));
71 static inline char* Strdup(const char*) __attribute__((unused));
72 static inline char* Strcpy (char*, const char*) __attribute__((unused));
73 static inline char* Strncpy (char*, const char*, unsigned)
74     __attribute__((unused));
75 static inline char* Strcat (char*, const char*) __attribute__((unused));
76 static inline char* Strncat (char*, const char*, unsigned)
77     __attribute__((unused));
78 static inline int Strcmp(const char*, const char*) __attribute__((unused));
79 static inline int Strncmp(const char*, const char*, unsigned)
80     __attribute__((unused));
81 static inline int Atoi(const char*) __attribute__((unused));
82 static inline long Atol(const char*) __attribute__((unused));
83
84 static inline void *Malloc(int size) {
85   return malloc(size);
86 }
87
88 static inline void *MallocAtomic(int size) {
89   return malloc(size);
90 }
91
92 static inline void Free(void* p) {
93   if (p) free(p);
94 }
95
96 static inline void *Calloc(int elem, int size) {
97   return calloc(elem, size);
98 }
99
100 static inline void *CallocAtomic(int elem, int size) {
101   return calloc(elem, size);
102 }
103
104 static inline void *Realloc(void* p, int size) {
105   return realloc(p, size);
106 }
107
108 static inline int Strlen(const char* s) {
109   return s ? strlen(s) : 0;
110 }
111
112 static inline char* Strdup(const char* s) {
113   return s ? strcpy(Malloc(strlen(s) + 1), s) : NULL;
114 }
115
116 static inline char* Strcpy (char* d, const char* s) {
117   return s && d ? strcpy(d, s) : d;
118 }
119
120 static inline char* Strncpy (char* d, const char* s, unsigned size) {
121   return s && d ? strncpy(d, s, size) : d;
122 }
123
124 static inline char* Strcat (char* d, const char* s) {
125   return s && d ? strcat(d, s) : d;
126 }
127
128 static inline char* Strncat (char* d, const char* s , unsigned size) {
129   return s && d ? strncat(d, s , size) : d;
130 }
131
132 static inline int Strcmp(const char* p, const char* q) {
133     if(!p) {
134         if(!q)
135             return 0;
136         else return -1;
137     }
138     else {
139         if(!q)
140             return 1;
141         else return strcmp(p, q);
142     }
143 }
144
145 static inline int Strncmp(const char* p, const char* q, unsigned size) {
146     if(!p) {
147         if(!q)
148             return 0;
149         else return -1;
150     }
151     else {
152         if(!q)
153             return 1;
154         else return strncmp(p, q, size);
155     }
156 }
157
158 static inline int Atoi(const char* str)
159 {
160     return str ? atoi(str) : 0;
161 }
162
163 static inline long Atol(const char *str)
164 {
165   return str ? atol(str) : 0;
166 }
167
168 #ifndef MAX
169 #define MAX(a, b) \
170     ({typedef _ta = (a), _tb = (b);   \
171         _ta _a = (a); _tb _b = (b);     \
172         _a > _b ? _a : _b; })
173 #endif
174
175 #ifndef MIN
176 #define MIN(a, b) \
177     ({typedef _ta = (a), _tb = (b);   \
178         _ta _a = (a); _tb _b = (b);     \
179         _a < _b ? _a : _b; })
180 #endif
181
182 #if !LIB_FOUNDATION_LIBRARY
183
184 #ifndef CREATE_AUTORELEASE_POOL
185 #define CREATE_AUTORELEASE_POOL(pool) \
186   id pool = [[NSAutoreleasePool alloc] init]
187 #endif
188
189 #endif /* ! LIB_FOUNDATION_LIBRARY */
190
191
192 #if !LIB_FOUNDATION_LIBRARY
193
194 static inline char *Ltoa(long nr, char *str, int base)
195 {
196     char buff[34], rest, is_negative;
197     int ptr;
198
199     ptr = 32;
200     buff[33] = '\0';
201     if(nr < 0) {
202         is_negative = 1;
203         nr = -nr;
204     }
205     else
206         is_negative = 0;
207
208     while(nr != 0) {
209         rest = nr % base;
210         if(rest > 9)
211             rest += 'A' - 10;
212         else
213             rest += '0';
214         buff[ptr--] = rest;
215         nr /= base;
216     }
217     if(ptr == 32)
218         buff[ptr--] = '0';
219     if(is_negative)
220         buff[ptr--] = '-';
221
222     Strcpy(str, &buff[ptr+1]);
223
224     return(str);
225 }
226 #endif
227
228 #if !LIB_FOUNDATION_LIBRARY
229
230 @interface NSObject(FoundationExtGDLAccess)
231 - (void)subclassResponsibility:(SEL)sel;
232 - (void)notImplemented:(SEL)sel;
233 @end
234
235 #endif
236
237 #if !GNU_RUNTIME
238 #  ifndef SEL_EQ
239 #    define SEL_EQ(__A__,__B__) (__A__==__B__ ? YES : NO)
240 #  endif
241 #else
242 #  ifndef SEL_EQ
243 #    include <objc/objc.h>
244 #    define SEL_EQ(__A__,__B__) sel_eq(__A__,__B__)
245 #  endif
246 #endif
247
248 #endif /* __common_h__ */