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__
27 #include <objc/Protocol.h>
29 #import <Foundation/Foundation.h>
30 #import <Foundation/NSObjCRuntime.h>
32 #if NeXT_RUNTIME || APPLE_RUNTIME
33 # define objc_free(__mem__) free(__mem__)
34 # define objc_malloc(__size__) malloc(__size__)
35 # define objc_calloc(__cnt__, __size__) calloc(__cnt__, __size__)
36 # define objc_realloc(__ptr__, __size__) realloc(__ptr__, __size__)
38 # define sel_eq(sela,selb) (sela==selb?YES:NO)
43 # define ASSIGN(object, value) \
44 ({id __object = (id)object; \
45 id __value = (id)value; \
46 if (__value != __object) { if (__value) [__value retain]; \
47 if (__object) [__object release]; \
51 # define ASSIGNCOPY(object, value) \
52 ({id __object = (id)object; \
53 id __value = (id)value; \
54 if (__value != __object) { if (__value) __value = [__value copy]; \
55 if (__object) [__object release]; \
59 // ******************** common functions ********************
61 static inline char* Strdup(const char*) __attribute__((unused));
62 static inline char* Strcpy (char*, const char*) __attribute__((unused));
63 static inline char* Strncpy (char*, const char*, unsigned)
64 __attribute__((unused));
65 static inline char* Strcat (char*, const char*) __attribute__((unused));
66 static inline char* Strncat (char*, const char*, unsigned)
67 __attribute__((unused));
68 static inline int Strcmp(const char*, const char*) __attribute__((unused));
69 static inline int Strncmp(const char*, const char*, unsigned)
70 __attribute__((unused));
71 static inline int Atoi(const char*) __attribute__((unused));
72 static inline long Atol(const char*) __attribute__((unused));
76 #define Realloc realloc
77 #define Free(__p__) if(__p__) { free(__p__); __p__ = NULL; }
79 #define Strlen(__s__) (__s__?strlen(__s__):0)
81 static inline char *Strdup(const char *s) {
82 return s ? strcpy(Malloc(strlen(s) + 1), s) : NULL;
84 static inline char* Strcpy (char *d, const char *s) {
85 return s && d ? strcpy(d, s) : d;
87 static inline char* Strncpy (char* d, const char* s, unsigned size) {
88 return s && d ? strncpy(d, s, size) : d;
90 static inline char* Strcat (char* d, const char* s) {
91 return s && d ? strcat(d, s) : d;
93 static inline char* Strncat (char* d, const char* s , unsigned size) {
94 return s && d ? strncat(d, s , size) : d;
97 static inline int Strcmp(const char* p, const char* q) {
106 else return strcmp(p, q);
110 static inline int Strncmp(const char* p, const char* q, unsigned size) {
119 else return strncmp(p, q, size);
123 static inline int Atoi(const char* str) {
124 return str ? atoi(str) : 0;
126 static inline long Atol(const char *str) {
127 return str ? atol(str) : 0;
132 ({typedef _ta = (a), _tb = (b); \
133 _ta _a = (a); _tb _b = (b); \
134 _a > _b ? _a : _b; })
139 ({typedef _ta = (a), _tb = (b); \
140 _ta _a = (a); _tb _b = (b); \
141 _a < _b ? _a : _b; })
144 static inline char *Ltoa(long nr, char *str, int base) {
145 char buff[34], rest, is_negative;
171 Strcpy(str, &buff[ptr+1]);
176 #endif /* __EOControl_COMMON_H__ */