Skip to content

Commit

Permalink
Bugfix: compile error missing type
Browse files Browse the repository at this point in the history
== Problem
When the library was installed to the system and a user attempted
to compile against the library the compile would fail.

== Reason
The problem was due to some types not being defined in the public API
of the library.

== Solution
Changed the public API, header files, of the library so that a few
of the files are now auto-generated based on information discovered
by the configure script. The header files that are now auto-generated
are 'safe_lib_errno.h' and 'safe_types.h'.
  • Loading branch information
Jonathan Toppins authored and Jonathan Toppins committed May 9, 2013
1 parent 7380ddc commit 88a3bf7
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 116 deletions.
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Safe C Library

Copyright (C) 2012 Cisco Systems
Copyright (C) 2012, 2013 Cisco Systems
All rights reserved.

Permission is hereby granted, free of charge, to any person
Expand Down
2 changes: 1 addition & 1 deletion Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Aug 2012, Jonathan Toppins
#
# Copyright (c) 2005-2009 Cisco Systems
# Copyright (c) 2012 Cisco Systems
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person
Expand Down
42 changes: 32 additions & 10 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 2012, Jonathan Toppins <[email protected]>
#
# Copyright (c) 2012 Cisco Systems
# Copyright (c) 2012, 2013 Cisco Systems
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -37,17 +37,39 @@ ACLOCAL_AMFLAGS = -I m4 --install ${ACLOCAL_FLAGS}
SUBDIRS = src tests

# Library header files
pkginclude_HEADERS = include/safe_lib.h \
include/safe_mem_lib.h \
include/safe_str_lib.h
pkginclude_HEADERS = \
include/safe_lib.h \
include/safe_mem_lib.h \
include/safe_str_lib.h

# generated package headers that need to be generated every time
nodist_pkginclude_HEADERS = \
include/safe_types.h \
include/safe_lib_errno.h


# Support files
SAFEC_INFRA = \
${top_srcdir}/build-tools/autogen.sh \
$(top_srcdir)/build-tools/version-gen.sh \
$(top_srcdir)/doc \
$(top_srcdir)/scripts \
$(top_srcdir)/.version \
$(top_srcdir)/safec.pc.in

SAFEC_GENHEADERS = \
$(top_srcdir)/include/safe_types.h.in \
$(top_srcdir)/include/safe_lib_errno.h.in

SAFEC_SLKM = \
$(top_srcdir)/tests/test_slkm.c \
$(top_srcdir)/src/slkm \
$(top_srcdir)/Kbuild \
$(top_srcdir)/Makefile.kernel


# Additional things to distribute
EXTRA_DIST = \
$(top_srcdir)/safec.pc.in \
$(top_srcdir)/build-tools/version-gen.sh \
$(top_srcdir)/doc \
$(top_srcdir)/scripts \
$(top_srcdir)/.version
EXTRA_DIST = $(SAFEC_INFRA) $(SAFEC_GENHEADERS) $(SAFEC_SLKM)

BUILT_SOURCES = $(top_srcdir)/.version

Expand Down
2 changes: 1 addition & 1 deletion Makefile.kernel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Aug 2012, Jonathan Toppins
#
# Copyright (c) 2005-2009 Cisco Systems
# Copyright (c) 2012 Cisco Systems
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person
Expand Down
7 changes: 4 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,17 @@ build the kernel module.

.To build do the following:
----
prompt$ ./configure
prompt$ make -f Makefile.kernel
----

This assumes you are compiling on a Linux box and this makefile supports the
standard kernel build system infrastructure documented in:
<linux-kernel-src-tree>/Documentation/kbuild/modules.txt

NOTE: You do not need autotools support to build the kernel module and can
skip all steps related to autotools if you wish to just build the kernel
module.
NOTE: If you build the kernel module then wish to build the userspace library
or vice versa you will need to do a +make clean+ otherwise a +make check+
will fail to build.


=== Installing
Expand Down
2 changes: 1 addition & 1 deletion build-tools/autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# in a sane and repeatable way. It is really easy, but just so no one
# forgets...
#
# WARNING! You DON NOT want to run this when you have uncommitted changes!!
# WARNING! You DO NOT want to run this when you have uncommitted changes!!

require_clean_work_tree () {
git rev-parse --verify HEAD >/dev/null || exit 1
Expand Down
113 changes: 89 additions & 24 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 2012, Jonathan Toppins <[email protected]>
#
# Copyright (c) 2012 Cisco Systems
# Copyright (c) 2012, 2013 Cisco Systems
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -33,10 +33,10 @@ AC_PREREQ([2.60])

# information on the package
AC_INIT([Safe C Library],
m4_esyscmd([build-tools/version-gen.sh .tarball-version]),
[https://sourceforge.net/projects/safeclib/support],
[libsafec],
[http://sourceforge.net/projects/safeclib/])
m4_esyscmd([build-tools/version-gen.sh .tarball-version]),
[https://sourceforge.net/projects/safeclib/support],
[libsafec],
[http://sourceforge.net/projects/safeclib/])

# Configure the configure script
# ===============================================
Expand Down Expand Up @@ -112,8 +112,8 @@ AM_CFLAGS="-Wall"

AC_ARG_ENABLE(debug,
AS_HELP_STRING([--enable-debug],
[compile library w/ debugging symbols (-g)
@<:@default=no@:>@]),
[compile library w/ debugging symbols (-g)
@<:@default=no@:>@]),
[case "${enableval}" in
yes) enable_debug=true ;;
no) enable_debug=false ;;
Expand All @@ -133,9 +133,9 @@ if test "-g -O2" == "$CFLAGS"; then
CFLAGS="${DEBUG_CFLAGS}"
else
AC_MSG_WARN([CFLAGS is not empty, will attempt to apply optimization
flags to 'AM_CFLAGS' but depending on the contents of
CFLAGS these may be overridden.
CFLAGS = '$CFLAGS'])
flags to 'AM_CFLAGS' but depending on the contents of
CFLAGS these may be overridden.
CFLAGS = '$CFLAGS'])
AM_CFLAGS="${AM_CFLAGS} ${DEBUG_CFLAGS}"
fi
AM_CONDITIONAL(ENABLE_DEBUG, test "x$enable_debug" = "xtrue")
Expand Down Expand Up @@ -208,8 +208,8 @@ AM_CONDITIONAL(ENABLE_DEBUG, test "x$enable_debug" = "xtrue")
# Maintainer switches
AC_ARG_ENABLE(debug-build,
AS_HELP_STRING([--enable-debug-build],
[turn on build debugging, generally is not needed
unless you are the maintainer @<:@default=no@:>@]),
[turn on build debugging, generally is not needed
unless you are the maintainer @<:@default=no@:>@]),
[case "${enableval}" in
yes) enable_debug_build=true ;;
no) enable_debug_build=false ;;
Expand All @@ -221,8 +221,10 @@ AM_CONDITIONAL(ENABLE_DEBUG_BUILD, test "x$enable_debug_build" = "xtrue")
AC_MSG_NOTICE([Check programs])
# ===============================================
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AM_PROG_CC_C_O
AC_PROG_CC_C99

# Checks for libraries
# ===============================================
Expand All @@ -233,10 +235,62 @@ AC_MSG_NOTICE([Check header files])
AC_HEADER_STDC
AC_HEADER_STDBOOL
AC_HEADER_TIME
AC_CHECK_HEADERS([inttypes.h limits.h stddef.h stdlib.h string.h], [], [],
[[
#include <stdio.h>
]])
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_HEADERS([stdlib.h \
memory.h \
string.h \
limits.h \
sys/types.h \
inttypes.h \
stdint.h \
errno.h
])

INSERT_SYS_TYPES_H=""
if test "x$ac_cv_header_sys_types_h" = "xyes"; then
INSERT_SYS_TYPES_H="#include <sys/types.h>"
fi
AC_SUBST(INSERT_SYS_TYPES_H)

INSERT_INTTYPES_H=""
if test "x$ac_cv_header_inttypes_h" = "xyes"; then
INSERT_INTTYPES_H="#include <inttypes.h>"
fi
AC_SUBST(INSERT_INTTYPES_H)

INSERT_STDINT_H=""
if test "x$ac_cv_header_stdint_h" = "xyes"; then
INSERT_STDINT_H="#include <stdint.h>"
fi
AC_SUBST(INSERT_STDINT_H)

INSERT_ERRNO_H=""
if test "x$ac_cv_header_errno_h" = "xyes"; then
INSERT_ERRNO_H="#include <errno.h>"
fi
AC_SUBST(INSERT_ERRNO_H)

INSERT_BOOL_SUPPORT="#include <stdbool.h>"
if test "x$ac_cv_header_stdbool_h" = "xno"; then
INSERT_BOOL_SUPPORT="
# define bool _Bool
# define false 0
# define true 1
# define __bool_true_false_are_defined 1
"
if test "x$ac_cv_type__bool" = "xno"; then
INSERT_BOOL_SUPPORT="
#ifdef __cplusplus
typedef bool _Bool;
#else
# define _Bool unsigned char
#endif
$INSERT_BOOL_SUPPORT
"
fi
fi
AC_SUBST(INSERT_BOOL_SUPPORT)


AC_MSG_NOTICE([Check typedefs, structures, and compiler characteristics])
# ===============================================
Expand All @@ -249,14 +303,13 @@ AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINTPTR_T
AC_CHECK_TYPES([errno_t, boolean_t], [], [],
[[
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
]])
AC_CHECK_TYPE([errno_t], [], [], [[#include <errno.h>]])

FALLBACK_ERRNO_T=""
if test "x$ac_cv_type_errno_t" = "xno"; then
FALLBACK_ERRNO_T="typedef int errno_t;"
fi
AC_SUBST(FALLBACK_ERRNO_T)

AC_MSG_NOTICE([Check library functions])
# ===============================================
Expand All @@ -272,6 +325,16 @@ AC_CHECK_FUNCS([memset strcasecmp strcspn strpbrk strspn strstr])
# This section emits all variables that are expected/needed by other tools
# mainly automake.

AH_TOP([
#ifndef __SAFECLIB_CONF_H__
#define __SAFECLIB_CONF_H__
])

AH_BOTTOM([
#endif /* __SAFECLIB_CONF_H__ */
])


AC_SUBST([TARBALL_VERSION_FILE])

# Define these substations here to keep all version information in
Expand Down Expand Up @@ -307,6 +370,8 @@ AC_CONFIG_HEADERS([config.h])
# Override the template file name of the generated .pc file, so that there
# is no need to rename the template file when the API version changes.
AC_CONFIG_FILES([safec-${SAFEC_API_VERSION}.pc:safec.pc.in
include/safe_lib_errno.h
include/safe_types.h
Makefile
src/Makefile
tests/Makefile])
Expand Down
2 changes: 2 additions & 0 deletions include/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
safe_lib_errno.h
safe_types.h
5 changes: 4 additions & 1 deletion include/safe_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* October 2008, Bo Berry
* Modified 2012, Jonathan Toppins <[email protected]>
*
* Copyright (c) 2008-2012 by Cisco Systems, Inc
* Copyright (c) 2008-2013 by Cisco Systems, Inc
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -33,6 +33,9 @@
#ifndef __SAFE_LIB_H__
#define __SAFE_LIB_H__

#include "safe_types.h"
#include "safe_lib_errno.h"

/* C11 appendix K types - specific for bounds checking */
typedef size_t rsize_t;

Expand Down
9 changes: 3 additions & 6 deletions src/safeclib/safe_lib_errno.h → include/safe_lib_errno.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* October 2008, Bo Berry
* Modified 2012, Jonathan Toppins <[email protected]>
*
* Copyright (c) 2008-2012 by Cisco Systems, Inc
* Copyright (c) 2008-2013 by Cisco Systems, Inc
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -32,14 +32,11 @@

#ifndef __SAFE_LIB_ERRNO_H__
#define __SAFE_LIB_ERRNO_H__
/* NOTE: the config.h file must be included before this file! */

#ifdef __KERNEL__
#include <linux/errno.h>
# include <linux/errno.h>
#else
#ifdef STDC_HEADERS
#include <errno.h>
#endif
@INSERT_ERRNO_H@
#endif /* __KERNEL__ */

/*
Expand Down
Loading

0 comments on commit 88a3bf7

Please sign in to comment.