~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-gdl1/GDLAccess/common.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

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