]> rtime.felk.cvut.cz Git - ulut.git/commitdiff
uLUt library updated from other projects.
authorppisa <ppisa>
Tue, 13 Feb 2007 11:29:42 +0000 (11:29 +0000)
committerppisa <ppisa>
Tue, 13 Feb 2007 11:29:42 +0000 (11:29 +0000)
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.

ulut/ul_dbuff.h
ulut/ul_dbufmore.c
ulut/ul_gsacust.c
ulut/ul_log.h
ulut/ul_utdefs.h

index 3f0a16dfe3c8c1b1116fade7dd4572701c03b0a9..de9fda461b7e5daf6630ae6f8259bb92542d36c4 100644 (file)
@@ -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);
index cb0ecb200252dddf8fc558565b214390285cfa20..34b8fc92e8f6c089cc05f6674b8ee4c6bd81f8b5 100644 (file)
@@ -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;
+}
index 5b178d60efb9f099914ba7eb14536ba3c5259fef..2a18a5c26e08a052a6620a64a5514c36a09110b5 100644 (file)
@@ -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)
index 5aa5fbac0b8698578ff95af8900f9e7e5eaf59ab..7bf54a4defd9d1a2b833963e5796c047bca3aefa 100644 (file)
@@ -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); \
 }
index 2eab33ab7799247e321306f245496298e8a34323..3cf4b27d0c8a9b275450425b42cede361543295a 100644 (file)
@@ -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__