Use ./configure to detect arc4random and use it if present

This commit is contained in:
Renaud Allard
2015-09-03 16:11:12 +02:00
parent 047ecf672c
commit 6743d0e6b7
5 changed files with 4013 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
# -----------------------------------
CFLAGS+=-pthread -O2
CFLAGS+=@LIBS@
all: fiche

2
config.h.in Normal file
View File

@@ -0,0 +1,2 @@
#undef HAVE_ARC4RANDOM

3987
configure vendored Executable file

File diff suppressed because it is too large Load Diff

20
configure.in Normal file
View File

@@ -0,0 +1,20 @@
AC_INIT([fiche], [0.99])
AC_CONFIG_SRCDIR([fiche.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
# Function arc4random() is in BSD standard C or GNU systems -lbsd
AC_SEARCH_LIBS([arc4random], [bsd], [HAVE_ARC4RANDOM="yes"])
# Checks for library functions.
AC_CHECK_FUNCS([bzero arc4random])
AC_SUBST(HAVE_ARC4RANDOM)
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

View File

@@ -27,6 +27,7 @@ $ cat fiche.c | nc localhost 9999
*/
#include <sys/param.h>
#include "config.h"
#include "fiche.h"
int main(int argc, char **argv)
@@ -274,7 +275,7 @@ void generate_url(char *buffer, char *slug, size_t slug_length, struct client_da
for (i = 0; i <= SLUG_SIZE - 1; i++)
{
#if defined(BSD)
#if defined(HAVE_ARC4RANDOM)
int symbol_id = arc4random() % strlen(symbols);
#else
int symbol_id = rand_r(&time_seed) % strlen(symbols);
@@ -284,7 +285,7 @@ void generate_url(char *buffer, char *slug, size_t slug_length, struct client_da
while (create_directory(slug) == -1)
{
#if defined(BSD)
#if defined(HAVE_ARC4RANDOM)
int symbol_id = arc4random() % strlen(symbols);
#else
int symbol_id = rand_r(&time_seed) % strlen(symbols);