From: ppisa Date: Tue, 13 Feb 2007 11:29:42 +0000 (+0000) Subject: uLUt library updated from other projects. X-Git-Tag: ul_drv-0.8.0-release~38 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/ulut.git/commitdiff_plain/b2534e8c42d54ab438c6b631d4e2a3c7737518e6 uLUt library updated from other projects. Added support for cyclic variables comparison ul_cyclic_gt ul_cyclic_ge This is usable mainly to compare time counters and other variables which are expected to overflow and support overflow arithmetics. --- diff --git a/ulut/ul_dbuff.h b/ulut/ul_dbuff.h index 3f0a16d..de9fda4 100644 --- a/ulut/ul_dbuff.h +++ b/ulut/ul_dbuff.h @@ -69,6 +69,7 @@ int ul_dbuff_pos(const ul_dbuff_t *buf, unsigned char what, unsigned char quote) int ul_dbuff_strcpy(ul_dbuff_t *buf, const char *str); int ul_dbuff_strcat(ul_dbuff_t *buf, const char *str); int ul_dbuff_append_byte(ul_dbuff_t *buf, unsigned char b); +int ul_dbuff_export(ul_dbuff_t *srcdb, void *dest, int maxlen); void ul_dbuff_cut_pos(ul_dbuff_t *fromdb, ul_dbuff_t *todb, int n); void ul_dbuff_cut_delimited(ul_dbuff_t *fromdb, ul_dbuff_t *todb, char delimiter, char quote); diff --git a/ulut/ul_dbufmore.c b/ulut/ul_dbufmore.c index cb0ecb2..34b8fc9 100644 --- a/ulut/ul_dbufmore.c +++ b/ulut/ul_dbufmore.c @@ -448,3 +448,20 @@ void ul_dbuff_cut_token(ul_dbuff_t *fromdb, ul_dbuff_t *todb) ul_dbuff_cut_pos(fromdb, todb, pos); ul_dbuff_trim(todb); } + +/** + * ul_dbuff_export - Copies data from %srcdb to the buffer %dest. + * @srcdb: source dbuff + * @dest: destination buffer + * @maxlen: maximum number of bytes to copy + * + * Returns: the number of bytes copied. + */ +int ul_dbuff_export(ul_dbuff_t *srcdb, void *dest, int maxlen) +{ + int len; + if (!dest) return 0; + len = srcdb->len < maxlen ? srcdb->len : maxlen; + memcpy(dest, srcdb->data, len); + return len; +} diff --git a/ulut/ul_gsacust.c b/ulut/ul_gsacust.c index 5b178d6..2a18a5c 100644 --- a/ulut/ul_gsacust.c +++ b/ulut/ul_gsacust.c @@ -101,7 +101,7 @@ gsa_cust_delete_at(gsa_array_field_t *array, unsigned indx) return 0; } -void +void gsa_cust_delete_all(gsa_array_field_t *array) { if(array->items && array->alloc_count) diff --git a/ulut/ul_log.h b/ulut/ul_log.h index 5aa5fba..7bf54a4 100644 --- a/ulut/ul_log.h +++ b/ulut/ul_log.h @@ -97,4 +97,15 @@ void ul_logdeb(const char *format, ...) \ va_start(ap, format); \ ul_vloglev(UL_LOGL_DEB, format, ap); \ va_end(ap); \ +}\ +\ +static inline \ +void ul_logtrash(const char *format, ...) UL_ATTR_PRINTF (1, 2);\ +static inline \ +void ul_logtrash(const char *format, ...) \ +{ \ + va_list ap; \ + va_start(ap, format); \ + ul_vloglev(UL_LOGL_TRASH, format, ap); \ + va_end(ap); \ } diff --git a/ulut/ul_utdefs.h b/ulut/ul_utdefs.h index 2eab33a..3cf4b27 100644 --- a/ulut/ul_utdefs.h +++ b/ulut/ul_utdefs.h @@ -34,6 +34,30 @@ extern "C" { #endif /*__GNUC__*/ #endif /*UL_CONTAINEROF*/ +#ifndef ul_cyclic_gt +#define ul_cyclic_gt(x,y) \ + ((sizeof(x)>=sizeof(long long))&&(sizeof(y)>=sizeof(long long))? \ + (long long)((long long)(x)-(long long)(y))>0: \ + (sizeof(x)>=sizeof(long))&&(sizeof(y)>=sizeof(long))? \ + (long)((long)(x)-(long)(y))>0: /* x,y casts to suppress warnings only*/ \ + (sizeof(x)>=sizeof(int))&&(sizeof(y)>=sizeof(int))?(int)((x)-(y))>0: \ + (sizeof(x)>=sizeof(short))&&(sizeof(y)>=sizeof(short))?(short)((x)-(y))>0: \ + (signed char)((x)-(y))>0 \ + ) +#endif /*ul_cyclic_gt*/ + +#ifndef ul_cyclic_ge +#define ul_cyclic_ge(x,y) \ + ((sizeof(x)>=sizeof(long long))&&(sizeof(y)>=sizeof(long long))? \ + (long long)((long long)(x)-(long long)(y))>=0: \ + (sizeof(x)>=sizeof(long))&&(sizeof(y)>=sizeof(long))? \ + (long)((long)(x)-(long)(y))>=0: /* x,y casts to suppress warnings only*/ \ + (sizeof(x)>=sizeof(int))&&(sizeof(y)>=sizeof(int))?(int)((x)-(y))>=0: \ + (sizeof(x)>=sizeof(short))&&(sizeof(y)>=sizeof(short))?(short)((x)-(y))>=0: \ + (signed char)((x)-(y))>=0 \ + ) +#endif /*ul_cyclic_ge*/ + /* GNUC neat features */ #ifdef __GNUC__