Changeset View
Standalone View
lib/libcmb/cmb.h
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
svn:keywords | null | FreeBSD=%H \ No newline at end of property |
svn:mime-type | null | text/plain \ No newline at end of property |
/*- | |||||
* Copyright (c) 2002-2018 Devin Teske <dteske@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. | |||||
* | |||||
* $FrauBSD: pkgcenter/depend/libcmb/cmb.h 2018-03-29 15:27:50 -0700 freebsdfrau $ | |||||
* $FreeBSD$ | |||||
*/ | |||||
#ifndef _CMB_H_ | |||||
#define _CMB_H_ | |||||
#include <sys/param.h> | |||||
#include <sys/types.h> | |||||
#include <stddef.h> | |||||
#include <stdint.h> | |||||
#ifdef HAVE_CONFIG_H | |||||
#include "config.h" | |||||
adridg: If this is an installed header for consumption by other source in the base tree, won't this… | |||||
Done Inline ActionsNot an installed header but a header generated by the cmb-specific configure scripts [1] [2] for compiling on platforms other than FreeBSD. libcmb and cmb are compatible with Mac OS X and Linux with the correct compile flags. There is no conflict because HAVE_CONFIG_H is something you apply to localized CFLAGS when (and only when) you have a config.h file for compiling the software on some unknown (but POSIX compliant) platform. You wouldn't ever define HAVE_CONFIG_H globally and the reason you see it in infiniband/opensm is for the same reasons (compatibility with an autotools build system that is unused in FreeBSD base). If you grep globally for HAVE_CONFIG_H in the base, you'll find that it's largely just cross-platform compatible software that makes use of it (89.36% of which is in contrib/). Here we are largely:
Another option would be to move libcmb and cmb into contrib including the autotools files (configure, configure.in, GNUmakefile.in, and config.h.in). However, I figured it would be more FreeBSD-like to drop the autotools despite the fact that it too works on FreeBSD if, say, for some reason you wanted to use gmake outside of the normal build process. [1] https://github.com/FrauBSD/pkgcenter/blob/master/depend/libcmb/configure.in [2] https://github.com/FrauBSD/pkgcenter/blob/master/depend/cmb/configure.in dteske: Not an installed header but a header generated by the `cmb`-specific `configure` scripts [1]… | |||||
#elif defined(__FreeBSD_version) | |||||
#ifdef HAVE_LIBCRYPTO | |||||
#define HAVE_OPENSSL_BN_H 1 | |||||
#else | |||||
#undef HAVE_OPENSSL_BN_H | |||||
#endif | |||||
#endif | |||||
#ifdef HAVE_OPENSSL_BN_H | |||||
#include <openssl/bn.h> | |||||
#endif | |||||
#ifndef TRUE | |||||
#define TRUE 1 | |||||
#endif | |||||
#ifndef FALSE | |||||
#define FALSE 0 | |||||
#endif | |||||
static uint8_t cmb_print_nul = FALSE; | |||||
static const char *cmb_print_delimiter = " "; | |||||
static const char *cmb_print_prefix = NULL; | |||||
static const char *cmb_print_suffix = NULL; | |||||
Done Inline ActionsThese are (static, internal) variables for cmb.c, right? They should live there, not in the header. adridg: These are (static, internal) variables for `cmb.c`, right? They should live there, not in the… | |||||
/* | |||||
* Anatomy of config option to pass as cmb*() config argument | |||||
*/ | |||||
struct cmb_config { | |||||
uint8_t nul_terminate; /* Terminate combinations with ASCII NUL */ | |||||
char *delimiter; /* Item separator (default is " ") */ | |||||
char *prefix; /* Prefix for each combination */ | |||||
char *suffix; /* Suffix for each combination */ | |||||
uint32_t range_min; /* Minimum number of elements in combination */ | |||||
uint32_t range_max; /* Maximum number of elements in combination */ | |||||
uint64_t count; /* Number of combinations */ | |||||
uint64_t start; /* Starting combination */ | |||||
#ifdef HAVE_OPENSSL_BN_H | |||||
BIGNUM *count_bn; /* bn(3) number of combinations */ | |||||
Done Inline ActionsIt looks like you want *either* the BN approach, or the uint64_t approach (e.g. in cmb.c only one of the two members is initialized). If you stick count and start in an #else you can avoid uninitialized fields in this struct. adridg: It looks like you want *either* the BN approach, or the `uint64_t` approach (e.g. in `cmb.c`… | |||||
Done Inline ActionsProviding both allows programs linking to the library to choose between 64-bit and bn(3) dteske: Providing both allows programs linking to the library to choose between 64-bit and bn(3) | |||||
BIGNUM *start_bn; /* bn(3) starting combination */ | |||||
#endif | |||||
/* | |||||
* Function pointer; action to perform for each combination (default is | |||||
* cmb_print()). If the return from action() is non-zero, cmb() will | |||||
* stop calculation. The cmb() return value is the first non-zero | |||||
* result from action(), zero otherwise. | |||||
*/ | |||||
int (*action)(uint32_t nitems, char *items[]); | |||||
}; | |||||
__BEGIN_DECLS | |||||
int cmb(struct cmb_config *_config, uint32_t _nitems, char *_items[]); | |||||
int cmb_print(uint32_t _nitems, char *_items[]); | |||||
uint64_t cmb_count(struct cmb_config *_config, uint32_t _nitems); | |||||
#ifdef HAVE_OPENSSL_BN_H | |||||
int cmb_bn(struct cmb_config *_config, uint32_t _nitems, char *_items[]); | |||||
BIGNUM * cmb_count_bn(struct cmb_config *_config, uint32_t _nitems); | |||||
#endif | |||||
__END_DECLS | |||||
#endif /* !_CMB_H_ */ |
If this is an installed header for consumption by other source in the base tree, won't this clash with other HAVE_CONFIG_H definitions? (infiniband/opensm seems to have one).