summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2019-06-10 18:46:15 +0000
committerOri Bernstein <ori@eigenstate.org>2019-06-10 18:46:15 +0000
commit45d3a85db61e11dd8f1fb641d8cc07bc3515265b (patch)
tree8c0209e246a9bf62b74672b1c771f19ec94e6190
parent57a0bd85416ede86191dd2aed1b18e3899eb7323 (diff)
downloadlibwapcaplet-45d3a85db61e11dd8f1fb641d8cc07bc3515265b.tar.gz
Add ifdefs around gnuisms, fixes compile on 9front.
-rw-r--r--include/libwapcaplet/libwapcaplet.h60
1 files changed, 45 insertions, 15 deletions
diff --git a/include/libwapcaplet/libwapcaplet.h b/include/libwapcaplet/libwapcaplet.h
index d8cc841..e48d9b0 100644
--- a/include/libwapcaplet/libwapcaplet.h
+++ b/include/libwapcaplet/libwapcaplet.h
@@ -117,6 +117,20 @@ extern lwc_error lwc_intern_substring(lwc_string *str,
extern lwc_error lwc_string_tolower(lwc_string *str, lwc_string **ret);
/**
+ * Intern a caseless copy of the passed string.
+ *
+ * @param str The string to intern the caseless copy of.
+ *
+ * @return lwc_error_ok if successful, otherwise the
+ * error code describing the issue.,
+ *
+ * @note This is for "internal" use by the caseless comparison
+ * macro and not for users.
+ */
+extern lwc_error
+lwc__intern_caseless_string(lwc_string *str);
+
+/**
* Increment the reference count on an lwc_string.
*
* This increases the reference count on the given string. You should
@@ -133,8 +147,11 @@ extern lwc_error lwc_string_tolower(lwc_string *str, lwc_string **ret);
* @note Use this if copying the string and intending both sides to retain
* ownership.
*/
+#ifdef __GNUC__
#define lwc_string_ref(str) ({lwc_string *__lwc_s = (str); assert(__lwc_s != NULL); __lwc_s->refcnt++; __lwc_s;})
-
+#else
+#define lwc_string_ref(str) ((str)->refcnt++, (str));
+#endif
/**
* Release a reference on an lwc_string.
*
@@ -185,6 +202,7 @@ extern void lwc_string_destroy(lwc_string *str);
* @return Result of operation, if not ok then value pointed to by \a ret will
* not be valid.
*/
+#ifdef __GNUC__
#define lwc_string_caseless_isequal(_str1,_str2,_ret) ({ \
lwc_error __lwc_err = lwc_error_ok; \
lwc_string *__lwc_str1 = (_str1); \
@@ -201,20 +219,21 @@ extern void lwc_string_destroy(lwc_string *str);
*__lwc_ret = (__lwc_str1->insensitive == __lwc_str2->insensitive); \
__lwc_err; \
})
+#else
+static inline lwc_error
+lwc_string_caseless_isequal(lwc_string *s1, lwc_string *s2, bool *ret)
+{
+ lwc_error e = lwc_error_ok;
-/**
- * Intern a caseless copy of the passed string.
- *
- * @param str The string to intern the caseless copy of.
- *
- * @return lwc_error_ok if successful, otherwise the
- * error code describing the issue.,
- *
- * @note This is for "internal" use by the caseless comparison
- * macro and not for users.
- */
-extern lwc_error
-lwc__intern_caseless_string(lwc_string *str);
+ if (s1->insensitive == NULL)
+ e = lwc__intern_caseless_string(s1);
+ if (e == lwc_error_ok && s2->insensitive == NULL)
+ e = lwc__intern_caseless_string(s2);
+ if (e == lwc_error_ok)
+ *ret = (s1->insensitive == s2->insensitive);
+ return e;
+}
+#endif
/**
* Retrieve the data pointer for an interned string.
@@ -228,7 +247,11 @@ lwc__intern_caseless_string(lwc_string *str);
* in future. Any code relying on it currently should be
* modified to use ::lwc_string_length if possible.
*/
+#ifdef __GNUC__
#define lwc_string_data(str) ({assert(str != NULL); (const char *)((str)+1);})
+#else
+#define lwc_string_data(str) ((const char *)((str)+1))
+#endif
/**
* Retrieve the data length for an interned string.
@@ -236,7 +259,11 @@ lwc__intern_caseless_string(lwc_string *str);
* @param str The string to retrieve the length of.
* @return The length of \a str.
*/
+#ifdef __GNUC__
#define lwc_string_length(str) ({assert(str != NULL); (str)->len;})
+#else
+#define lwc_string_length(str) ((str)->len)
+#endif
/**
* Retrieve (or compute if unavailable) a hash value for the content of the string.
@@ -250,8 +277,11 @@ lwc__intern_caseless_string(lwc_string *str);
* to be stable between invocations of the program. Never use the hash
* value as a way to directly identify the value of the string.
*/
+#ifdef __GNUC__
#define lwc_string_hash_value(str) ({assert(str != NULL); (str)->hash;})
-
+#else
+#define lwc_string_length(str) ((str)->len)
+#endif
/**
* Retrieve a hash value for the caseless content of the string.
*