Dolda2000 GitWeb
/
ashd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added max and min macros.
[ashd.git]
/
lib
/
utils.h
diff --git
a/lib/utils.h
b/lib/utils.h
index
d74d09d
..
6b1df4e
100644
(file)
--- a/
lib/utils.h
+++ b/
lib/utils.h
@@
-1,10
+1,15
@@
#ifndef _UTILS_H
#define _UTILS_H
#ifndef _UTILS_H
#define _UTILS_H
+#include <stdarg.h>
+
+#define max(a, b) (((b) > (a))?(b):(a))
+#define min(a, b) (((b) < (a))?(b):(a))
+
#define smalloc(size) ({void *__result__; ((__result__ = malloc(size)) == NULL)?({exit(-1); (void *)0;}):__result__;})
#define srealloc(ptr, size) ({void *__result__; ((__result__ = realloc((ptr), (size))) == NULL)?({exit(-1); (void *)0;}):__result__;})
#define szmalloc(size) memset(smalloc(size), 0, size)
#define smalloc(size) ({void *__result__; ((__result__ = malloc(size)) == NULL)?({exit(-1); (void *)0;}):__result__;})
#define srealloc(ptr, size) ({void *__result__; ((__result__ = realloc((ptr), (size))) == NULL)?({exit(-1); (void *)0;}):__result__;})
#define szmalloc(size) memset(smalloc(size), 0, size)
-#define sstrdup(str) ({char *__strbuf__ = (str); strcpy(smalloc(strlen(__strbuf__) + 1), __strbuf__);})
+#define sstrdup(str) ({c
onst c
har *__strbuf__ = (str); strcpy(smalloc(strlen(__strbuf__) + 1), __strbuf__);})
#define omalloc(o) ((o) = szmalloc(sizeof(*(o))))
#define bufinit(buf) memset(&(buf), 0, sizeof(buf))
#define omalloc(o) ((o) = szmalloc(sizeof(*(o))))
#define bufinit(buf) memset(&(buf), 0, sizeof(buf))
@@
-23,12
+28,19
@@
do { \
memcpy((buf).b + (buf).d, (new), (__bufcat_size__) * sizeof(*((buf).b))); \
(buf).d += __bufcat_size__; \
} while(0)
memcpy((buf).b + (buf).d, (new), (__bufcat_size__) * sizeof(*((buf).b))); \
(buf).d += __bufcat_size__; \
} while(0)
-#define bufcatstr
2
(buf, str) \
+#define bufcatstr(buf, str) \
do { \
char *__buf__; \
__buf__ = (str); \
bufcat((buf), __buf__, strlen(__buf__)); \
} while(0)
do { \
char *__buf__; \
__buf__ = (str); \
bufcat((buf), __buf__, strlen(__buf__)); \
} while(0)
+#define bufcatstr2(buf, str) \
+do { \
+ char *__buf__; \
+ __buf__ = (str); \
+ bufcat((buf), __buf__, strlen(__buf__) + 1); \
+} while(0)
+#define bufeat(buf, len) memmove((buf).b, (buf).b + (len), (buf).d -= (len))
struct buffer {
void *b;
struct buffer {
void *b;
@@
-48,5
+60,10
@@
struct charvbuf {
};
void _sizebuf(struct buffer *buf, size_t wanted, size_t el);
};
void _sizebuf(struct buffer *buf, size_t wanted, size_t el);
+char *decstr(char **p, size_t *len);
+char *vsprintf2(char *format, va_list al);
+char *sprintf2(char *format, ...);
+char *sprintf3(char *format, ...);
+off_t atoo(char *n);
#endif
#endif