mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 08:16:59 +00:00
build-sys: add gnulib
This will mean better portability, and a good reason to get rid of various portability autotools directives which where part of this project. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
b5e518cd5e
commit
ab699e71ad
18 changed files with 1309 additions and 256 deletions
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
bin_PROGRAMS = dhcpd-pools
|
||||
AC_PROG_RANLIB = resolv
|
||||
AM_CPPFLAGS = -I. -I..
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_builddir)/lib
|
||||
|
||||
dhcpd_pools_LDADD = $(top_builddir)/lib/libdhcpd_pools.la
|
||||
|
||||
dhcpd_pools_SOURCES = \
|
||||
analyze.c \
|
||||
|
|
|
|||
|
|
@ -34,19 +34,8 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
extern char *malloc();
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
|
|
@ -54,8 +43,11 @@ extern char *malloc();
|
|||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "close-stream.h"
|
||||
#include "closeout.h"
|
||||
#include "defaults.h"
|
||||
#include "dhcpd-pools.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
|
@ -88,9 +80,9 @@ int main(int argc, char **argv)
|
|||
atexit(close_stdout);
|
||||
|
||||
/* FIXME: make these allocations dynamic up on need. */
|
||||
config.dhcpdconf_file = safe_malloc(sizeof(char) * MAXLEN);
|
||||
config.dhcpdlease_file = safe_malloc(sizeof(char) * MAXLEN);
|
||||
config.output_file = safe_malloc(sizeof(char) * MAXLEN);
|
||||
config.dhcpdconf_file = xmalloc(sizeof(char) * MAXLEN);
|
||||
config.dhcpdlease_file = xmalloc(sizeof(char) * MAXLEN);
|
||||
config.output_file = xmalloc(sizeof(char) * MAXLEN);
|
||||
|
||||
/* Make sure string has zero lenght if there is no
|
||||
* command line option */
|
||||
|
|
@ -228,7 +220,7 @@ int main(int argc, char **argv)
|
|||
parse_leases();
|
||||
prepare_data();
|
||||
do_counting();
|
||||
tmp_ranges = safe_malloc(sizeof(struct range_t) * num_ranges);
|
||||
tmp_ranges = xmalloc(sizeof(struct range_t) * num_ranges);
|
||||
if (sorts != 0) {
|
||||
mergesort_ranges(ranges, num_ranges, tmp_ranges);
|
||||
}
|
||||
|
|
@ -248,13 +240,13 @@ int prepare_memory(void)
|
|||
RANGES = 64;
|
||||
num_ranges = num_shared_networks = 0;
|
||||
shared_networks =
|
||||
safe_malloc(sizeof(struct shared_network_t) * SHARED_NETWORKS);
|
||||
xmalloc(sizeof(struct shared_network_t) * SHARED_NETWORKS);
|
||||
|
||||
ranges = safe_malloc(sizeof(struct range_t) * RANGES);
|
||||
ranges = xmalloc(sizeof(struct range_t) * RANGES);
|
||||
macaddr = NULL;
|
||||
|
||||
/* First shared network entry is all networks */
|
||||
shared_networks->name = safe_strdup("All networks");
|
||||
shared_networks->name = xstrdup("All networks");
|
||||
shared_networks->used = 0;
|
||||
shared_networks->touched = 0;
|
||||
shared_networks->backups = 0;
|
||||
|
|
|
|||
|
|
@ -168,20 +168,8 @@ int do_counting(void);
|
|||
void flip_ranges(struct range_t *__restrict ranges, struct range_t *__restrict tmp_ranges)
|
||||
__attribute__ ((nonnull(1, 2)));
|
||||
/* support functions */
|
||||
void *safe_malloc(const size_t size)
|
||||
#if __GNUC__ >= 3
|
||||
__attribute__ ((__malloc__))
|
||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
__attribute__ ((__alloc_size__((1))))
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
void *safe_realloc(void *__restrict ptr, const size_t size);
|
||||
char *safe_strdup(const char *__restrict str) __attribute__ ((nonnull(1)));
|
||||
int xstrstr(char *__restrict a, const char *__restrict b, int len);
|
||||
double strtod_or_err(const char *__restrict str, const char *__restrict errmesg);
|
||||
int close_stream(FILE * stream);
|
||||
void close_stdout(void);
|
||||
void print_version(void) __attribute__ ((noreturn));
|
||||
void usage(int status) __attribute__ ((noreturn));
|
||||
/* qsort required functions... */
|
||||
|
|
|
|||
|
|
@ -35,14 +35,6 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#else /* Not STDC_HEADERS */
|
||||
extern char *malloc();
|
||||
#define EXIT_FAILURE 1 /* Failing exit status. */
|
||||
#define EXIT_SUCCESS 0 /* Successful exit status. */
|
||||
#endif /* STDC_HEADERS */
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
|
@ -54,13 +46,12 @@ extern char *malloc();
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#include "defaults.h"
|
||||
#include "dhcpd-pools.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
/* Parse dhcpd.leases file. All performance boosts for this function are
|
||||
* wellcome */
|
||||
|
|
@ -105,11 +96,11 @@ int parse_leases(void)
|
|||
err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file);
|
||||
}
|
||||
|
||||
line = safe_malloc(sizeof(char) * MAXLEN);
|
||||
ipstring = safe_malloc(sizeof(char) * MAXLEN);
|
||||
line = xmalloc(sizeof(char) * MAXLEN);
|
||||
ipstring = xmalloc(sizeof(char) * MAXLEN);
|
||||
if (config.output_format[0] == 'X') {
|
||||
macstring = safe_malloc(sizeof(char) * 18);
|
||||
macaddr = safe_malloc(sizeof(struct macaddr_t));
|
||||
macstring = xmalloc(sizeof(char) * 18);
|
||||
macaddr = xmalloc(sizeof(struct macaddr_t));
|
||||
macaddr_p = macaddr;
|
||||
macaddr_p->next = NULL;
|
||||
}
|
||||
|
|
@ -154,10 +145,10 @@ int parse_leases(void)
|
|||
nth_field(3, macstring, line);
|
||||
if (macstring) {
|
||||
macstring[17] = '\0';
|
||||
macaddr_p->ethernet = safe_strdup(macstring);
|
||||
macaddr_p->ip = safe_strdup(ipstring);
|
||||
macaddr_p->ethernet = xstrdup(macstring);
|
||||
macaddr_p->ip = xstrdup(ipstring);
|
||||
macaddr_p->next =
|
||||
safe_malloc(sizeof(struct macaddr_t));
|
||||
xmalloc(sizeof(struct macaddr_t));
|
||||
macaddr_p = macaddr_p->next;
|
||||
macaddr_p->next = NULL;
|
||||
}
|
||||
|
|
@ -229,7 +220,7 @@ void parse_config(int is_include, const char *restrict config_file,
|
|||
struct in_addr inp;
|
||||
struct range_t *range_p;
|
||||
|
||||
word = safe_malloc(sizeof(char) * MAXLEN);
|
||||
word = xmalloc(sizeof(char) * MAXLEN);
|
||||
|
||||
if (is_include) {
|
||||
/* Default place holder for ranges "All networks". */
|
||||
|
|
@ -389,7 +380,7 @@ void parse_config(int is_include, const char *restrict config_file,
|
|||
if (RANGES < num_ranges + 1) {
|
||||
RANGES *= 2;
|
||||
ranges =
|
||||
safe_realloc(ranges,
|
||||
xrealloc(ranges,
|
||||
sizeof(struct
|
||||
range_t) *
|
||||
RANGES);
|
||||
|
|
@ -413,7 +404,7 @@ void parse_config(int is_include, const char *restrict config_file,
|
|||
num_shared_networks++;
|
||||
shared_p =
|
||||
shared_networks + num_shared_networks;
|
||||
shared_p->name = safe_strdup(word);
|
||||
shared_p->name = xstrdup(word);
|
||||
shared_p->available = 0;
|
||||
shared_p->used = 0;
|
||||
shared_p->touched = 0;
|
||||
|
|
|
|||
|
|
@ -34,11 +34,12 @@
|
|||
*/
|
||||
|
||||
#include "dhcpd-pools.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
void add_lease(int ip, enum ltype type)
|
||||
{
|
||||
struct leases_t *l;
|
||||
l = safe_malloc(sizeof(struct leases_t));
|
||||
l = xmalloc(sizeof(struct leases_t));
|
||||
l->ip = ip;
|
||||
l->type = type;
|
||||
HASH_ADD_INT(leases, ip, l);
|
||||
|
|
|
|||
94
src/other.c
94
src/other.c
|
|
@ -37,69 +37,15 @@
|
|||
|
||||
#include "dhcpd-pools.h"
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
extern void exit();
|
||||
extern char *malloc();
|
||||
extern void _exit();
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_ERROR_H
|
||||
#include <error.h>
|
||||
#endif
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STDIO_EXT_H
|
||||
#include <stdio_ext.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef HAVE_ERROR
|
||||
#ifdef __FreeBSD__
|
||||
#define error errc
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE___FPENDING
|
||||
static size_t __fpending(FILE *fp)
|
||||
{
|
||||
return (fp->_p - fp->_bf._base);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Simple memory allocation wrapper */
|
||||
void *safe_malloc(const size_t size)
|
||||
{
|
||||
void *ret = malloc(size);
|
||||
if (ret == NULL) {
|
||||
err(EXIT_FAILURE,
|
||||
"safe_malloc: cannot allocate %lu bytes: ", size);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Simple memory reallocation wrapper */
|
||||
void *safe_realloc(void *ptr, const size_t size)
|
||||
{
|
||||
void *ret = realloc(ptr, size);
|
||||
|
||||
if (!ret && size)
|
||||
err(EXIT_FAILURE,
|
||||
"safe_realloc: cannot allocate %lu bytes", size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
__attribute__ ((hot))
|
||||
|
|
@ -126,16 +72,6 @@ int
|
|||
return true;
|
||||
}
|
||||
|
||||
/* Simple strdup wrapper */
|
||||
char *safe_strdup(const char *restrict str)
|
||||
{
|
||||
char *ret = strdup(str);
|
||||
|
||||
if (!ret && str)
|
||||
err(EXIT_FAILURE, "cannot duplicate string");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Return percentage value */
|
||||
double strtod_or_err(const char *restrict str, const char *restrict errmesg)
|
||||
{
|
||||
|
|
@ -192,32 +128,6 @@ void clean_up(void)
|
|||
free(shared_networks);
|
||||
}
|
||||
|
||||
int close_stream(FILE *stream)
|
||||
{
|
||||
const int some_pending = (__fpending(stream) != 0);
|
||||
const int prev_fail = (ferror(stream) != 0);
|
||||
const int fclose_fail = (fclose(stream) != 0);
|
||||
if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) {
|
||||
if (!fclose_fail)
|
||||
errno = 0;
|
||||
return EOF;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Use atexit(); */
|
||||
void close_stdout(void)
|
||||
{
|
||||
if (close_stream(stdout) != 0 && !(errno == EPIPE)) {
|
||||
char const *write_error = "write error";
|
||||
error(0, errno, "%s", write_error);
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (close_stream(stderr) != 0)
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void __attribute__ ((__noreturn__)) print_version(void)
|
||||
{
|
||||
fprintf(stdout, "%s\n"
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <langinfo.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -45,10 +46,9 @@
|
|||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "close-stream.h"
|
||||
#include "dhcpd-pools.h"
|
||||
#include "strftime.h"
|
||||
|
||||
int output_txt(void)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue