Imported Upstream version 2.7.4
This commit is contained in:
parent
fd413a3168
commit
c9cb2187ee
290 changed files with 7473 additions and 2607 deletions
|
@ -1,5 +1,5 @@
|
|||
dist_noinst_HEADERS = attribute.h common.h extstate.h parseconf.h proto.h \
|
||||
state.h timehead.h upsconf.h nut_stdint.h nut_platform.h
|
||||
state.h str.h timehead.h upsconf.h nut_stdint.h nut_platform.h
|
||||
|
||||
# http://www.gnu.org/software/automake/manual/automake.html#Clean
|
||||
BUILT_SOURCES = nut_version.h
|
||||
|
|
|
@ -203,6 +203,7 @@ LD = @LD@
|
|||
LDFLAGS = @LDFLAGS@
|
||||
LIBAVAHI_CFLAGS = @LIBAVAHI_CFLAGS@
|
||||
LIBAVAHI_LIBS = @LIBAVAHI_LIBS@
|
||||
LIBDIR = @LIBDIR@
|
||||
LIBGD_CFLAGS = @LIBGD_CFLAGS@
|
||||
LIBGD_LDFLAGS = @LIBGD_LDFLAGS@
|
||||
LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@
|
||||
|
@ -337,7 +338,7 @@ top_builddir = @top_builddir@
|
|||
top_srcdir = @top_srcdir@
|
||||
udevdir = @udevdir@
|
||||
dist_noinst_HEADERS = attribute.h common.h extstate.h parseconf.h proto.h \
|
||||
state.h timehead.h upsconf.h nut_stdint.h nut_platform.h
|
||||
state.h str.h timehead.h upsconf.h nut_stdint.h nut_platform.h
|
||||
|
||||
|
||||
# http://www.gnu.org/software/automake/manual/automake.html#Clean
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "timehead.h"
|
||||
#include "attribute.h"
|
||||
#include "proto.h"
|
||||
#include "str.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
|
@ -118,11 +119,6 @@ void *xcalloc(size_t number, size_t size);
|
|||
void *xrealloc(void *ptr, size_t size);
|
||||
char *xstrdup(const char *string);
|
||||
|
||||
char *rtrim(char *in, const char sep);
|
||||
char* ltrim(char *in, const char sep);
|
||||
char *rtrim_m(char *in, const char *seps);
|
||||
char* ltrim_m(char *in, const char *seps);
|
||||
|
||||
int select_read(const int fd, void *buf, const size_t buflen, const long d_sec, const long d_usec);
|
||||
int select_write(const int fd, const void *buf, const size_t buflen, const long d_sec, const long d_usec);
|
||||
|
||||
|
|
|
@ -206,6 +206,9 @@
|
|||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the <ssl.h> header file. */
|
||||
#undef HAVE_SSL_H
|
||||
|
||||
/* Define to 1 if you have the `SSL_library_init' function. */
|
||||
#undef HAVE_SSL_LIBRARY_INIT
|
||||
|
||||
|
@ -281,6 +284,9 @@
|
|||
/* Default path for HTML files */
|
||||
#undef HTMLPATH
|
||||
|
||||
/* Default path for system libraries */
|
||||
#undef LIBDIR
|
||||
|
||||
/* Desired syslog facility - see syslog(3) */
|
||||
#undef LOG_FACILITY
|
||||
|
||||
|
|
129
include/str.h
Normal file
129
include/str.h
Normal file
|
@ -0,0 +1,129 @@
|
|||
/* str.h - Common string-related functions
|
||||
*
|
||||
* Copyright (C)
|
||||
* 2000 Russell Kroll <rkroll@exploits.org>
|
||||
* 2015 Daniele Pezzini <hyouko@gmail.com>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STR_H
|
||||
#define STR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/* Remove all
|
||||
* - leading and trailing (str_trim[_m]())
|
||||
* - leading (str_ltrim[_m]())
|
||||
* - trailing (str_rtrim[_m]))
|
||||
* instances of
|
||||
* - *character* (plain versions)
|
||||
* - each character in *characters* ('_m' versions)
|
||||
* from a string.
|
||||
* - *string*: null-terminated byte string from which characters are to be removed;
|
||||
* - *character*: character that has to be removed from *string*;
|
||||
* - *characters*: null-terminated byte string of characters to be removed from string.
|
||||
* Return:
|
||||
* - NULL, if *string* is NULL, otherwise
|
||||
* - *string* without the specified characters (upto an empty string). */
|
||||
char *str_trim(char *string, const char character);
|
||||
char *str_trim_m(char *string, const char *characters);
|
||||
char *str_ltrim(char *string, const char character);
|
||||
char *str_ltrim_m(char *string, const char *characters);
|
||||
char *str_rtrim(char *string, const char character);
|
||||
char *str_rtrim_m(char *string, const char *characters);
|
||||
|
||||
/* Remove all
|
||||
* - leading and trailing (str_trim_space())
|
||||
* - leading (str_ltrim_space())
|
||||
* - trailing (str_rtrim_space())
|
||||
* spaces (as identified by isspace()) from a string.
|
||||
* - *string*: null-terminated byte string from which spaces are to be removed.
|
||||
* Return:
|
||||
* - NULL, if *string* is NULL, otherwise
|
||||
* - *string* without the specified spaces (upto an empty string). */
|
||||
char *str_trim_space(char *string);
|
||||
char *str_ltrim_space(char *string);
|
||||
char *str_rtrim_space(char *string);
|
||||
|
||||
/* Tell whether a string can be converted to a number of type str_is_<type>[_strict]().
|
||||
* - *string*: the null-terminated byte string to check;
|
||||
* - *base*: the base the string must conform to.
|
||||
* The same restrictions of the corresponding str_to_<type>[_strict]() functions apply.
|
||||
* If *string* can be converted to a valid number of type <type>, return 1.
|
||||
* Otherwise, return 0 with errno set to:
|
||||
* - ENOMEM, if available memory is insufficient;
|
||||
* - EINVAL, if the value of *base* is not supported or no conversion could be performed;
|
||||
* - ERANGE, if the converted value would be out of the acceptable range of <type>. */
|
||||
int str_is_short(const char *string, const int base);
|
||||
int str_is_short_strict(const char *string, const int base);
|
||||
int str_is_ushort(const char *string, const int base);
|
||||
int str_is_ushort_strict(const char *string, const int base);
|
||||
int str_is_int(const char *string, const int base);
|
||||
int str_is_int_strict(const char *string, const int base);
|
||||
int str_is_uint(const char *string, const int base);
|
||||
int str_is_uint_strict(const char *string, const int base);
|
||||
int str_is_long(const char *string, const int base);
|
||||
int str_is_long_strict(const char *string, const int base);
|
||||
int str_is_ulong(const char *string, const int base);
|
||||
int str_is_ulong_strict(const char *string, const int base);
|
||||
int str_is_double(const char *string, const int base);
|
||||
int str_is_double_strict(const char *string, const int base);
|
||||
|
||||
/* Convert a string to a number of type str_to_<type>[_strict]().
|
||||
* - *string*: the null-terminated byte string to convert,
|
||||
* 'strict' versions' strings shall not contain spaces (as identified by isspace()),
|
||||
* - short, int, long: strtol()'s restrictions apply,
|
||||
* - ushort, uint, ulong: strtoul()'s restrictions apply, plus:
|
||||
* - plus ('+') and minus ('-') signs (and hence negative values) are not supported,
|
||||
* - double: strtod()'s restrictions apply, plus:
|
||||
* - infinity and nan are not supported,
|
||||
* - radix character (decimal point character) must be a period ('.');
|
||||
* - *number*: a pointer to a <type> that will be filled upon execution;
|
||||
* - *base*: the base the string must conform to,
|
||||
* - short, ushort, int, uint, long, ulong: acceptable values as in strtol()/strtoul(),
|
||||
* - double: 0 for auto-select, 10 or 16.
|
||||
* On success, return 1 with *number* being the result of the conversion of *string*.
|
||||
* On failure, return 0 with *number* being 0 and errno set to:
|
||||
* - ENOMEM, if available memory is insufficient;
|
||||
* - EINVAL, if the value of *base* is not supported or no conversion can be performed;
|
||||
* - ERANGE, if the converted value is out of the acceptable range of <type>. */
|
||||
int str_to_short(const char *string, short *number, const int base);
|
||||
int str_to_short_strict(const char *string, short *number, const int base);
|
||||
int str_to_ushort(const char *string, unsigned short *number, const int base);
|
||||
int str_to_ushort_strict(const char *string, unsigned short *number, const int base);
|
||||
int str_to_int(const char *string, int *number, const int base);
|
||||
int str_to_int_strict(const char *string, int *number, const int base);
|
||||
int str_to_uint(const char *string, unsigned int *number, const int base);
|
||||
int str_to_uint_strict(const char *string, unsigned int *number, const int base);
|
||||
int str_to_long(const char *string, long *number, const int base);
|
||||
int str_to_long_strict(const char *string, long *number, const int base);
|
||||
int str_to_ulong(const char *string, unsigned long *number, const int base);
|
||||
int str_to_ulong_strict(const char *string, unsigned long *number, const int base);
|
||||
int str_to_double(const char *string, double *number, const int base);
|
||||
int str_to_double_strict(const char *string, double *number, const int base);
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
#endif /* STR_H */
|
Loading…
Add table
Add a link
Reference in a new issue