chiark / gitweb /
Use memcpy helpers and FILLZERO
[secnet.git] / secnet.h
index ce01d24e31749e1bb8a00db3444f1c5cb449bcab..5eeb2132554f8cb8e971eb8075283d6cc45b5244 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -139,6 +139,7 @@ extern void *safe_malloc(size_t size, const char *message);
 extern void *safe_malloc_ary(size_t size, size_t count, const char *message);
 
 void setcloexec(int fd); /* cannot fail */
+void pipe_cloexec(int fd[2]); /* pipe(), setcloexec() twice; cannot fail */
 
 extern int sys_cmd(const char *file, const char *argc, ...);
 
@@ -550,4 +551,17 @@ extern void log_from_fd(int fd, cstring_t prefix, struct log_if *log);
 
 #define FILLZERO(obj) (memset(&(obj),0,sizeof((obj))))
 
+/*
+ * void COPY_OBJ(  OBJECT& dst, const OBJECT& src);
+ * void COPY_ARRAY(OBJECT *dst, const OBJECT *src, INTEGER count);
+ *   // Typesafe: we check that the type OBJECT is the same in both cases.
+ *   // It is OK to use COPY_OBJ on an array object, proviced it's
+ *   // _actually_ the whole array object and not decayed into a
+ *   // pointer (e.g. a formal parameter).
+ */
+#define COPY_OBJ(dst,src) \
+    (&(dst)==&(src), memcpy(&(dst),&(src),sizeof((dst))))
+#define COPY_ARRAY(dst,src,count) \
+    (&(dst)[0]==&(src)[0], memcpy((dst),(src),sizeof((dst)[0])*(count)))
+
 #endif /* secnet_h */