aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-02-10 18:28:54 +0100
committerMattias Andrée <m@maandree.se>2025-02-10 18:28:54 +0100
commit69e7fdc8f7ed2782e2c73b632c2a7ee7e6b641d5 (patch)
tree55b05baf81f3b78e80df594f1c082735a03dc654 /common.h
parentMinor code improvements and split into multiple c files (diff)
downloadlibcoopgamma-2d3cc3ec4effcdd2c210d91d067a0c6c7a687c59.tar.gz
libcoopgamma-2d3cc3ec4effcdd2c210d91d067a0c6c7a687c59.tar.bz2
libcoopgamma-2d3cc3ec4effcdd2c210d91d067a0c6c7a687c59.tar.xz
Fix portability issuesHEAD1.2.4master
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'common.h')
-rw-r--r--common.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/common.h b/common.h
index 2d87b85..2c54f0d 100644
--- a/common.h
+++ b/common.h
@@ -62,19 +62,31 @@ extern const char *argv0;
#define UNMARSHAL_EPILOGUE\
return *np = off, LIBCOOPGAMMA_SUCCESS
-#define marshal_prim(datum, type)\
- ((buf != NULL ? *(type *)&buf[off] = (datum) : 0), off += sizeof(type))
+#define marshal_prim(datum)\
+ do {\
+ char *buf__ = (buf);\
+ size_t off__ = ((off) += sizeof(datum)) - sizeof(datum);\
+ if (buf__)\
+ memcpy(&buf__[off__], &(datum), sizeof(datum));\
+ } while (0)
-#define unmarshal_prim(datum, type)\
- ((datum) = *(const type *)&buf[off], off += sizeof(type))
+#define unmarshal_prim(datum)\
+ do {\
+ const char *buf__ = (buf);\
+ size_t off__ = ((off) += sizeof(datum)) - sizeof(datum);\
+ memcpy(&(datum), &buf__[off__], sizeof(datum));\
+ } while (0)
#define marshal_version(version)\
- marshal_prim(version, int)
+ do {\
+ int version__ = (version);\
+ marshal_prim(version__);\
+ } while (0)
#define unmarshal_version(version)\
do {\
int version__;\
- unmarshal_prim(version__, int);\
+ unmarshal_prim(version__);\
if (version__ < (version))\
return LIBCOOPGAMMA_INCOMPATIBLE_DOWNGRADE;\
if (version__ > (version))\
@@ -94,13 +106,17 @@ extern const char *argv0;
} while (0)
#define marshal_string(datum)\
- (!(datum) ? marshal_prim(0, char) :\
- (marshal_prim(1, char), marshal_buffer((datum), strlen(datum) + 1U)))
+ do {\
+ char nonnull__ = (char)!!(datum);\
+ marshal_prim(nonnull__);\
+ if (nonnull__)\
+ marshal_buffer((datum), strlen(datum) + 1U);\
+ } while (0)
#define unmarshal_string(datum)\
do {\
char nonnull__;\
- unmarshal_prim(nonnull__, char);\
+ unmarshal_prim(nonnull__);\
if (nonnull__)\
unmarshal_buffer((datum), strlen(&buf[off]) + 1U);\
else\