aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2022-05-13 16:23:10 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-05-30 00:48:47 +0200
commitd4422354726405530957a23b56001e891998e867 (patch)
tree80a7d00f1b25513208a43e4222dc7df2bc2adeba
parenta70bd5508214e836dbabc8a0fb940e5df34ecb45 (diff)
downloadslirp-d4422354726405530957a23b56001e891998e867.zip
slirp-d4422354726405530957a23b56001e891998e867.tar.gz
slirp-d4422354726405530957a23b56001e891998e867.tar.bz2
vmstate: only enable when building under GNU C
To be able to use typeof. Fixes #60
-rw-r--r--src/libslirp.h2
-rw-r--r--src/state.c19
-rw-r--r--src/vmstate.c4
-rw-r--r--src/vmstate.h7
4 files changed, 29 insertions, 3 deletions
diff --git a/src/libslirp.h b/src/libslirp.h
index 4f156b6..63a9600 100644
--- a/src/libslirp.h
+++ b/src/libslirp.h
@@ -279,7 +279,7 @@ char *slirp_neighbor_info(Slirp *slirp);
/* Save the slirp state through the write_cb. The opaque pointer is passed as
* such to the write_cb. */
SLIRP_EXPORT
-void slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque);
+int slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque);
/* Returns the version of the slirp state, to be saved along the state */
SLIRP_EXPORT
diff --git a/src/state.c b/src/state.c
index 8708547..d5689ba 100644
--- a/src/state.c
+++ b/src/state.c
@@ -26,6 +26,8 @@
#include "vmstate.h"
#include "stream.h"
+#ifdef HAVE_VMSTATE
+
static int slirp_tcp_post_load(void *opaque, int version)
{
tcp_template((struct tcpcb *)opaque);
@@ -307,7 +309,7 @@ static const VMStateDescription vmstate_slirp = {
VMSTATE_END_OF_LIST() }
};
-void slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
+int slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
{
struct gfwd_list *ex_ptr;
SlirpOStream f = {
@@ -330,6 +332,8 @@ void slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
slirp_ostream_write_u8(&f, 0);
slirp_vmstate_save_state(&f, &vmstate_slirp, slirp);
+
+ return 0;
}
@@ -373,6 +377,19 @@ int slirp_state_load(Slirp *slirp, int version_id, SlirpReadCb read_cb,
return slirp_vmstate_load_state(&f, &vmstate_slirp, slirp, version_id);
}
+#else /* HAVE_VMSTATE */
+int slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
+{
+ return -ENOSYS;
+}
+
+int slirp_state_load(Slirp *slirp, int version_id, SlirpReadCb read_cb,
+ void *opaque)
+{
+ return -ENOSYS;
+}
+#endif /* HAVE_VMSTATE */
+
int slirp_state_version(void)
{
return 4;
diff --git a/src/vmstate.c b/src/vmstate.c
index 68cc172..c7fc5a3 100644
--- a/src/vmstate.c
+++ b/src/vmstate.c
@@ -45,6 +45,8 @@
#include "stream.h"
#include "vmstate.h"
+#ifdef HAVE_VMSTATE
+
static int get_nullptr(SlirpIStream *f, void *pv, size_t size,
const VMStateField *field)
{
@@ -442,3 +444,5 @@ int slirp_vmstate_load_state(SlirpIStream *f, const VMStateDescription *vmsd,
}
return ret;
}
+
+#endif /* HAVE_VMSTATE */
diff --git a/src/vmstate.h b/src/vmstate.h
index e3e2459..64dd256 100644
--- a/src/vmstate.h
+++ b/src/vmstate.h
@@ -39,6 +39,9 @@
#ifndef VMSTATE_H_
#define VMSTATE_H_
+#ifdef __GNUC__
+#define HAVE_VMSTATE 1
+
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
@@ -392,4 +395,6 @@ extern const VMStateInfo slirp_vmstate_info_tmp;
.flags = VMS_END, \
}
-#endif
+#endif /* __GNUC__ */
+
+#endif /* VMSTATE_H_ */