Browse Source

Add asprintf replacement module

tags/v0.2.1^2
Damien Goutte-Gattat 7 years ago
parent
commit
b0fb1fa9b3
6 changed files with 103 additions and 13 deletions
  1. +3
    -3
      configure.ac
  2. +1
    -1
      lib/Makefile.am
  3. +61
    -0
      lib/asprintf.c
  4. +37
    -8
      lib/compat.h
  5. +0
    -0
      lib/err.compat.h
  6. +1
    -1
      src/Makefile.am

+ 3
- 3
configure.ac View File

@@ -33,8 +33,8 @@ if test "x$enable_default_keyfile" != xno ; then
fi

dnl Check for BSD-style error reporting functions
AC_CHECK_HEADERS([err.h], [], [AC_CONFIG_LINKS([err.h:lib/err.h])])
AC_REPLACE_FUNCS([err])
AC_CHECK_HEADERS([err.h], [], [AC_CONFIG_LINKS([err.h:lib/err.compat.h])])
AC_REPLACE_FUNCS([err asprintf])

dnl Check for a mean to store program name
AC_CHECK_DECLS([program_invocation_short_name], [],
@@ -42,7 +42,7 @@ AC_CHECK_DECLS([program_invocation_short_name], [],
[AC_LIBOBJ([progname])])],
[#include <errno.h>
])
AH_BOTTOM([#include <lib/progname.h>
AH_BOTTOM([#include <compat.h>
])

dnl Output files


+ 1
- 1
lib/Makefile.am View File

@@ -1,6 +1,6 @@
noinst_LIBRARIES = libadfgvx.a

libadfgvx_a_SOURCES = dummy.c err.h progname.h
libadfgvx_a_SOURCES = dummy.c err.compat.h compat.h

libadfgvx_a_LIBADD = $(LIBOBJS)



+ 61
- 0
lib/asprintf.c View File

@@ -0,0 +1,61 @@
/*
* asprintf - Incenp.org Notch Library: (v)asprintf replacement
* Copyright (C) 2011 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>

int
vasprintf(char **strp, const char *fmt, va_list ap)
{
int n;
va_list aq;

if ( ! strp ) {
errno = EINVAL;
return -1;
}

n = vsnprintf(NULL, 0, fmt, ap) + 1;
if ( ! (*strp = malloc(n)) )
return -1;

va_copy(ap, aq);
n = vsnprintf(*strp, n, fmt, aq);
va_end(aq);

return n;
}

int
asprintf(char **strp, const char *fmt, ...)
{
int n;
va_list ap;

va_start(ap, fmt);
n = vasprintf(strp, fmt, ap);
va_end(ap);

return n;
}

lib/progname.h → lib/compat.h View File

@@ -1,6 +1,6 @@
/*
* adfgvx - ADFGVX ciphering tool
* Copyright (C) 2009 Damien Goutte-Gattat
* compat - Incenp.org Notch Library: header for missing functions
* Copyright (C) 2011 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,15 +16,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ICP20091023_PROGNAME_H
#define ICP20091023_PROGNAME_H
#ifndef ICP20110203_COMPAT_H
#define ICP20110203_COMPAT_H

#ifdef __cplusplus
#ifdef __cpluscplus
extern "C" {
#endif


#ifndef HAVE_ASPRINTF

#include <stdarg.h>

int
asprintf(char **, const char *, ...);

int
vasprintf(char **, const char *, va_list);

#endif /* ! HAVE_ASPRINTF */



#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME

/*
* The GNU C library, combined with the GNU linker, automatically
* stores the program name into the global variable
* `program_invocation_short_name'. So `setprogname()' can be defined
* to nothing and `getprogname()' can be aliased to that variable.
*/

#include <errno.h>

#define setprogname(a)
@@ -32,6 +54,12 @@ extern "C" {

#else

/*
* If the above-mentioned variable is not available, check for the
* BSD functions `getprogname()' and `setprogname()', and provide our
* own implementation if they are missing.
*/

#ifndef HAVE_SETPROGNAME
void
setprogname(const char *);
@@ -39,13 +67,14 @@ setprogname(const char *);

#ifndef HAVE_GETPROGNAME
const char *
getprogname(void);
setprogname(void);
#endif

#endif /* HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME */
#endif /* ! HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME */


#ifdef __cplusplus
}
#endif

#endif /* !ICP20091023_PROGNAME_H */
#endif /* !ICP20110203_COMPAT_H */

lib/err.h → lib/err.compat.h View File


+ 1
- 1
src/Makefile.am View File

@@ -6,7 +6,7 @@ adfgvx_SOURCES = adfgvx.c \
cipher.c cipher.h

localedir = $(datadir)/locale
adfgvx_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -I$(top_srcdir)
adfgvx_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -I$(top_srcdir)/lib

adfgvx_LDFLAGS = -L$(top_builddir)/lib
adfgvx_LDADD = -ladfgvx @LIBINTL@

Loading…
Cancel
Save