Skip to content

Commit

Permalink
osx: Support strnlen in nbcompat and fix various.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Perkin committed Dec 18, 2017
1 parent d651038 commit 20e52a1
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 4 deletions.
1 change: 1 addition & 0 deletions audio/lame/Makefile
Expand Up @@ -11,6 +11,7 @@ COMMENT= Fast, high quality MP3 encoder
LICENSE= lame-license

GNU_CONFIGURE= yes
USE_FEATURES+= strnlen
USE_TOOLS+= gmake
USE_LIBTOOL= yes
USE_LANGUAGES= c c++
Expand Down
1 change: 1 addition & 0 deletions devel/picopb/Makefile
Expand Up @@ -11,6 +11,7 @@ COMMENT= Small implementation of Google protocol buffers in C
LICENSE= 2-clause-bsd

GNU_CONFIGURE= yes
USE_FEATURES+= strnlen
USE_LIBTOOL= yes
USE_TOOLS+= yacc

Expand Down
1 change: 1 addition & 0 deletions lang/ocaml/Makefile.common
Expand Up @@ -13,6 +13,7 @@ COMMENT= The latest implementation of the Caml dialect of ML
LICENSE= gnu-gpl-v2

USE_TOOLS+= gmake
USE_FEATURES+= strnlen
HAS_CONFIGURE= yes
CONFIGURE_ENV+= BDB_LIBS=${BDB_LINK:Q}
CONFIGURE_ENV+= BDB_BUILTIN=${USE_BUILTIN.${BDB_TYPE}:Q}
Expand Down
15 changes: 14 additions & 1 deletion mk/features/features-vars.mk
Expand Up @@ -46,6 +46,7 @@
# * glob
# * regcomp
# * snprintf, vsnprintf
# * strnlen
# * utimes
# * nbcompat: All of the above.
#
Expand All @@ -61,7 +62,7 @@
# Keywords: feature features asprintf vasprintf cdefs err errx warn warnx
# Keywords: fts fts_open fts_read fts_set fts_close getopt_long
# Keywords: getprogname setprogname glob regcomp setenv snprintf vsnprintf
# Keywords: utimes libnbcompat nbcompat
# Keywords: strnlen utimes libnbcompat nbcompat

_VARGROUPS+= features
_USER_VARS.features= # none
Expand Down Expand Up @@ -182,6 +183,18 @@ MISSING_FEATURES+= ${_feature_}
. endif
.endfor

#
# Features that are configured via mk/platform files. Features are assumed
# to exist unless explicitly set to "no".
#
.for _feature_ in strnlen
. if !empty(USE_FEATURES:M${_feature_})
. if ${_OPSYS_HAS_FEATURE.${_feature_}:Uyes:tl} == "no"
MISSING_FEATURES+= ${_feature_}
. endif
. endif
.endfor

.for _feature_ in utimes
. if !empty(USE_FEATURES:M${_feature_})
. if ${OPSYS} == "Interix"
Expand Down
2 changes: 1 addition & 1 deletion mk/features/features.mk
Expand Up @@ -36,7 +36,7 @@ LIBS+= ${FEATURE_LIBS}
# libnbcompat provides many of the current features.
#
_FEATURE_USE_NBCOMPAT?= no
. for f in asprintf cdefs err fts_close fts_open fts_read fts_set getopt_long glob nbcompat regcomp setenv snprintf utimes vsnprintf warn
. for f in asprintf cdefs err fts_close fts_open fts_read fts_set getopt_long glob nbcompat regcomp setenv snprintf strnlen utimes vsnprintf warn
. if !empty(MISSING_FEATURES:M${f})
_FEATURE_USE_NBCOMPAT= yes
. endif
Expand Down
7 changes: 7 additions & 0 deletions mk/platform/Darwin.mk
Expand Up @@ -127,6 +127,13 @@ _PATCH_CAN_BACKUP= yes # native patch(1) can make backups
_PATCH_BACKUP_ARG?= -V simple -b -z # switch to patch(1) for backup suffix
_USE_RPATH= no # don't add rpath to LDFLAGS

#
# Unsupported features for libnbcompat.
#
.if ${OS_VERSION:R} < 11
_OPSYS_HAS_FEATURE.strnlen= no # >= __MAC_10_7
.endif

# Comes with a native mit-krb5 implementation
KRB5_DEFAULT?= mit-krb5

Expand Down
13 changes: 13 additions & 0 deletions pkgtools/libnbcompat/files/configure
Expand Up @@ -6964,6 +6964,19 @@ esac
fi
ac_fn_c_check_func "$LINENO" "strnlen" "ac_cv_func_strnlen"
if test "x$ac_cv_func_strnlen" = xyes; then :
$as_echo "#define HAVE_STRNLEN 1" >>confdefs.h
else
case " $LIBOBJS " in
*" strnlen.$ac_objext "* ) ;;
*) LIBOBJS="$LIBOBJS strnlen.$ac_objext"
;;
esac
fi
ac_fn_c_check_func "$LINENO" "strsep" "ac_cv_func_strsep"
if test "x$ac_cv_func_strsep" = xyes; then :
$as_echo "#define HAVE_STRSEP 1" >>confdefs.h
Expand Down
4 changes: 2 additions & 2 deletions pkgtools/libnbcompat/files/configure.ac
Expand Up @@ -308,8 +308,8 @@ AC_CHECK_DECLS([isblank(int)], [], [AC_LIBOBJ(isblank)], [#include <ctype.h>])
AC_REPLACE_FUNCS([err fgetln fnmatch fparseln getdelim getenv \
getline lchflags lchmod lchown lutimes mkdtemp mkstemp setenv \
setgroupent setpassent setprogname shquote statvfs \
strerror strlcat strlcpy strmode strsep strtoll unsetenv usleep \
utimes warn
strerror strlcat strlcpy strmode strnlen strsep strtoll unsetenv \
usleep utimes warn
])

AC_SEARCH_LIBS(socket, [socket network])
Expand Down
3 changes: 3 additions & 0 deletions pkgtools/libnbcompat/files/nbcompat/config.h.in
Expand Up @@ -348,6 +348,9 @@
/* Define to 1 if you have the `strmode' function. */
#undef HAVE_STRMODE

/* Define to 1 if you have the `strnlen' function. */
#undef HAVE_STRNLEN

/* Define to 1 if you have the `strsep' function. */
#undef HAVE_STRSEP

Expand Down
4 changes: 4 additions & 0 deletions pkgtools/libnbcompat/files/nbcompat/string.h
Expand Up @@ -56,6 +56,10 @@ size_t strlcat(char *, const char *, size_t);
size_t strlcpy(char *, const char *, size_t);
#endif

#if !HAVE_STRNLEN
size_t strnlen(const char *, size_t);
#endif

#if !HAVE_STRSEP
char *strsep(char **stringp, const char *delim);
#endif
Expand Down
44 changes: 44 additions & 0 deletions pkgtools/libnbcompat/files/strnlen.c
@@ -0,0 +1,44 @@
/*-
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif

#include <nbcompat.h>
#include <nbcompat/string.h>

size_t
strnlen(const char *s, size_t maxlen)
{
size_t len;

for (len = 0; len < maxlen; len++, s++) {
if (!*s)
break;
}
return (len);
}
1 change: 1 addition & 0 deletions security/yara/Makefile
Expand Up @@ -7,6 +7,7 @@ MASTER_SITES= ${MASTER_SITE_GITHUB:=VirusTotal/}
COMMENT= Pattern matching swiss knife for malware researchers

USE_TOOLS+= pkg-config automake autoreconf
USE_FEATURES+= strnlen
USE_LIBTOOL= yes
GNU_CONFIGURE= yes

Expand Down
1 change: 1 addition & 0 deletions sysutils/syslog-ng/Makefile.common
Expand Up @@ -18,6 +18,7 @@ DISTINFO_FILE= ${.CURDIR}/../../sysutils/syslog-ng/distinfo

USE_LANGUAGES= c c99
USE_TOOLS+= flex pkg-config gmake awk:run
USE_FEATURES+= strnlen
USE_LIBTOOL= yes
GNU_CONFIGURE= yes

Expand Down

0 comments on commit 20e52a1

Please sign in to comment.