2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #ifndef __EOControl_COMMON_H__
23 #define __EOControl_COMMON_H__
26 #include <objc/Protocol.h>
28 #import <Foundation/Foundation.h>
29 #import <Foundation/NSObjCRuntime.h>
31 #if NeXT_RUNTIME || APPLE_RUNTIME
32 # define objc_free(__mem__) free(__mem__)
33 # define objc_malloc(__size__) malloc(__size__)
34 # define objc_calloc(__cnt__, __size__) calloc(__cnt__, __size__)
35 # define objc_realloc(__ptr__, __size__) realloc(__ptr__, __size__)
37 # define sel_eq(sela,selb) (sela==selb?YES:NO)
42 # define ASSIGN(object, value) \
43 ({id __object = (id)object; \
44 id __value = (id)value; \
45 if (__value != __object) { if (__value) [__value retain]; \
46 if (__object) [__object release]; \
50 # define ASSIGNCOPY(object, value) \
51 ({id __object = (id)object; \
52 id __value = (id)value; \
53 if (__value != __object) { if (__value) __value = [__value copy]; \
54 if (__object) [__object release]; \
58 // ******************** common functions ********************
60 static inline char* Strdup(const char*) __attribute__((unused));
61 static inline char* Strcpy (char*, const char*) __attribute__((unused));
62 static inline char* Strncpy (char*, const char*, unsigned)
63 __attribute__((unused));
64 static inline char* Strcat (char*, const char*) __attribute__((unused));
65 static inline char* Strncat (char*, const char*, unsigned)
66 __attribute__((unused));
67 static inline int Strcmp(const char*, const char*) __attribute__((unused));
68 static inline int Strncmp(const char*, const char*, unsigned)
69 __attribute__((unused));
70 static inline int Atoi(const char*) __attribute__((unused));
71 static inline long Atol(const char*) __attribute__((unused));
75 #define Realloc realloc
76 #define Free(__p__) if(__p__) { free(__p__); __p__ = NULL; }
78 #define Strlen(__s__) (__s__?strlen(__s__):0)
80 static inline char *Strdup(const char *s) {
81 return s ? strcpy(Malloc(strlen(s) + 1), s) : NULL;
83 static inline char* Strcpy (char *d, const char *s) {
84 return s && d ? strcpy(d, s) : d;
86 static inline char* Strncpy (char* d, const char* s, unsigned size) {
87 return s && d ? strncpy(d, s, size) : d;
89 static inline char* Strcat (char* d, const char* s) {
90 return s && d ? strcat(d, s) : d;
92 static inline char* Strncat (char* d, const char* s , unsigned size) {
93 return s && d ? strncat(d, s , size) : d;
96 static inline int Strcmp(const char* p, const char* q) {
105 else return strcmp(p, q);
109 static inline int Strncmp(const char* p, const char* q, unsigned size) {
118 else return strncmp(p, q, size);
122 static inline int Atoi(const char* str) {
123 return str ? atoi(str) : 0;
125 static inline long Atol(const char *str) {
126 return str ? atol(str) : 0;
131 ({typedef _ta = (a), _tb = (b); \
132 _ta _a = (a); _tb _b = (b); \
133 _a > _b ? _a : _b; })
138 ({typedef _ta = (a), _tb = (b); \
139 _ta _a = (a); _tb _b = (b); \
140 _a < _b ? _a : _b; })
143 static inline char *Ltoa(long nr, char *str, int base) {
144 char buff[34], rest, is_negative;
170 Strcpy(str, &buff[ptr+1]);
175 #endif /* __EOControl_COMMON_H__ */