1999-12-09 14:01:21 +01:00
|
|
|
/*
|
2024-05-10 17:15:56 +02:00
|
|
|
* lib_strbuf.c - init_lib() and library string storage
|
1999-12-09 14:01:21 +01:00
|
|
|
*/
|
2013-12-04 22:33:17 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
1999-12-09 14:01:21 +01:00
|
|
|
|
2024-05-10 17:15:56 +02:00
|
|
|
#include <isc/mutex.h>
|
2013-12-04 22:33:17 +01:00
|
|
|
#include <isc/net.h>
|
|
|
|
#include <isc/result.h>
|
2014-12-20 23:52:39 +01:00
|
|
|
|
|
|
|
#include "ntp_fp.h"
|
2001-08-29 16:35:15 +02:00
|
|
|
#include "ntp_stdlib.h"
|
1999-12-09 14:01:21 +01:00
|
|
|
#include "lib_strbuf.h"
|
|
|
|
|
2024-05-10 17:15:56 +02:00
|
|
|
#define LIB_NUMBUF 10
|
2014-12-20 23:52:39 +01:00
|
|
|
|
1999-12-09 14:01:21 +01:00
|
|
|
/*
|
|
|
|
* Storage declarations
|
|
|
|
*/
|
2024-05-10 17:15:56 +02:00
|
|
|
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;
|
1999-12-09 14:01:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* initialization routine. Might be needed if the code is ROMized.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
init_lib(void)
|
|
|
|
{
|
2024-05-10 17:15:56 +02:00
|
|
|
u_int u;
|
|
|
|
|
|
|
|
if (lib_inited) {
|
2014-12-20 23:52:39 +01:00
|
|
|
return;
|
2024-05-10 17:15:56 +02:00
|
|
|
}
|
2013-12-04 22:33:17 +01:00
|
|
|
ipv4_works = (ISC_R_SUCCESS == isc_net_probeipv4());
|
|
|
|
ipv6_works = (ISC_R_SUCCESS == isc_net_probeipv6());
|
2014-12-20 23:52:39 +01:00
|
|
|
init_systime();
|
2024-05-10 17:15:56 +02:00
|
|
|
/*
|
|
|
|
* 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);
|
2014-12-20 23:52:39 +01:00
|
|
|
lib_inited = TRUE;
|
1999-12-09 14:01:21 +01:00
|
|
|
}
|
2024-05-10 17:15:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|