4 Copyright (C) 1996 Free Software Foundation, Inc.
6 Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
9 This file is part of the GNUstep Database Library.
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.
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.
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.
26 // $Id: common.h 1 2004-08-20 10:38:46Z znek $
39 #include <sys/types.h>
43 #import <Foundation/NSZone.h>
44 #import <Foundation/Foundation.h>
45 #import <Foundation/NSUtilities.h>
46 #import <Foundation/NSObjCRuntime.h>
48 #if NeXT_RUNTIME || APPLE_RUNTIME
49 # define sel_eq(sela,selb) (sela==selb?YES:NO)
52 #if LIB_FOUNDATION_LIBRARY
53 # import <Foundation/exceptions/GeneralExceptions.h>
54 # import <extensions/objc-runtime.h>
56 # include <NGExtensions/NGObjectMacros.h>
57 # include <NGExtensions/NSString+Ext.h>
61 // ******************** common functions ********************
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));
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));
82 static inline void *Malloc(int size) {
86 static inline void *MallocAtomic(int size) {
90 static inline void Free(void* p) {
94 static inline void *Calloc(int elem, int size) {
95 return calloc(elem, size);
98 static inline void *CallocAtomic(int elem, int size) {
99 return calloc(elem, size);
102 static inline void *Realloc(void* p, int size) {
103 return realloc(p, size);
106 static inline int Strlen(const char* s) {
107 return s ? strlen(s) : 0;
110 static inline char* Strdup(const char* s) {
111 return s ? strcpy(Malloc(strlen(s) + 1), s) : NULL;
114 static inline char* Strcpy (char* d, const char* s) {
115 return s && d ? strcpy(d, s) : d;
118 static inline char* Strncpy (char* d, const char* s, unsigned size) {
119 return s && d ? strncpy(d, s, size) : d;
122 static inline char* Strcat (char* d, const char* s) {
123 return s && d ? strcat(d, s) : d;
126 static inline char* Strncat (char* d, const char* s , unsigned size) {
127 return s && d ? strncat(d, s , size) : d;
130 static inline int Strcmp(const char* p, const char* q) {
139 else return strcmp(p, q);
143 static inline int Strncmp(const char* p, const char* q, unsigned size) {
152 else return strncmp(p, q, size);
156 static inline int Atoi(const char* str)
158 return str ? atoi(str) : 0;
161 static inline long Atol(const char *str)
163 return str ? atol(str) : 0;
168 ({typedef _ta = (a), _tb = (b); \
169 _ta _a = (a); _tb _b = (b); \
170 _a > _b ? _a : _b; })
175 ({typedef _ta = (a), _tb = (b); \
176 _ta _a = (a); _tb _b = (b); \
177 _a < _b ? _a : _b; })
180 #if !LIB_FOUNDATION_LIBRARY
182 #ifndef CREATE_AUTORELEASE_POOL
183 #define CREATE_AUTORELEASE_POOL(pool) \
184 id pool = [[NSAutoreleasePool alloc] init]
187 #endif /* ! LIB_FOUNDATION_LIBRARY */
190 #if !LIB_FOUNDATION_LIBRARY
192 static inline char *Ltoa(long nr, char *str, int base)
194 char buff[34], rest, is_negative;
220 Strcpy(str, &buff[ptr+1]);
226 #if !LIB_FOUNDATION_LIBRARY
228 @interface NSObject(FoundationExtGDLAccess)
229 - (void)subclassResponsibility:(SEL)sel;
230 - (void)notImplemented:(SEL)sel;
237 # define SEL_EQ(__A__,__B__) (__A__==__B__ ? YES : NO)
241 # include <objc/objc.h>
242 # define SEL_EQ(__A__,__B__) sel_eq(__A__,__B__)
246 #endif /* __common_h__ */