aboutsummaryrefslogtreecommitdiff
path: root/contrib/ntp/libntp/lib_strbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/libntp/lib_strbuf.c')
-rw-r--r--contrib/ntp/libntp/lib_strbuf.c51
1 files changed, 42 insertions, 9 deletions
diff --git a/contrib/ntp/libntp/lib_strbuf.c b/contrib/ntp/libntp/lib_strbuf.c
index 76f70163de98..225c430f7e02 100644
--- a/contrib/ntp/libntp/lib_strbuf.c
+++ b/contrib/ntp/libntp/lib_strbuf.c
@@ -1,10 +1,11 @@
/*
- * lib_strbuf - library string storage
+ * lib_strbuf.c - init_lib() and library string storage
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <isc/mutex.h>
#include <isc/net.h>
#include <isc/result.h>
@@ -12,17 +13,18 @@
#include "ntp_stdlib.h"
#include "lib_strbuf.h"
+#define LIB_NUMBUF 10
/*
* Storage declarations
*/
-int debug;
-libbufstr lib_stringbuf[LIB_NUMBUF];
-int lib_nextbuf;
-int ipv4_works;
-int ipv6_works;
-int lib_inited;
-
+static char lib_stringbuf_storage[LIB_NUMBUF][LIB_BUFLENGTH];
+static char * lib_stringbuf[LIB_NUMBUF];
+int lib_inited;
+static isc_mutex_t lib_mutex;
+int ipv4_works;
+int ipv6_works;
+int debug;
/*
* initialization routine. Might be needed if the code is ROMized.
@@ -30,10 +32,41 @@ int lib_inited;
void
init_lib(void)
{
- if (lib_inited)
+ u_int u;
+
+ if (lib_inited) {
return;
+ }
ipv4_works = (ISC_R_SUCCESS == isc_net_probeipv4());
ipv6_works = (ISC_R_SUCCESS == isc_net_probeipv6());
init_systime();
+ /*
+ * Avoid -Wrestrict warnings by keeping a pointer to each buffer
+ * so the compiler can see copying from one buffer to another is
+ * not violating restrict qualifiers on, e.g. memcpy() args.
+ */
+ for (u = 0; u < COUNTOF(lib_stringbuf); u++) {
+ lib_stringbuf[u] = lib_stringbuf_storage[u];
+ }
+ isc_mutex_init(&lib_mutex);
lib_inited = TRUE;
}
+
+
+char *
+lib_getbuf(void)
+{
+ static int lib_nextbuf;
+ int mybuf;
+
+ if (!lib_inited) {
+ init_lib();
+ }
+ isc_mutex_lock(&lib_mutex);
+ mybuf = lib_nextbuf;
+ lib_nextbuf = (1 + mybuf) % COUNTOF(lib_stringbuf);
+ isc_mutex_unlock(&lib_mutex);
+ zero_mem(lib_stringbuf[mybuf], LIB_BUFLENGTH);
+
+ return lib_stringbuf[mybuf];
+} \ No newline at end of file