2012-11-30 15:21:02 +00:00
|
|
|
/*
|
2014-04-30 20:11:09 -06:00
|
|
|
* Copyright (C) 2007-2014 Red Hat, Inc.
|
2012-11-30 15:21:02 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-18 11:13:02 -05:00
|
|
|
#pragma once
|
2012-11-30 15:21:02 +00:00
|
|
|
|
2019-06-18 11:13:02 -05:00
|
|
|
#include "internal.h"
|
2018-07-13 23:24:41 +05:30
|
|
|
|
2020-01-14 13:30:07 +00:00
|
|
|
#define VIR_INT64_STR_BUFLEN 21
|
|
|
|
|
2013-04-03 12:36:23 +02:00
|
|
|
int virStrToLong_i(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
int *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2013-04-03 12:36:23 +02:00
|
|
|
|
|
|
|
int virStrToLong_ui(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
unsigned int *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2014-04-30 20:11:09 -06:00
|
|
|
int virStrToLong_uip(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
unsigned int *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2013-04-03 12:36:23 +02:00
|
|
|
int virStrToLong_l(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
long *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2013-04-03 12:36:23 +02:00
|
|
|
int virStrToLong_ul(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
unsigned long *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2014-04-30 20:11:09 -06:00
|
|
|
int virStrToLong_ulp(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
unsigned long *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2013-04-03 12:36:23 +02:00
|
|
|
int virStrToLong_ll(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
long long *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2013-04-03 12:36:23 +02:00
|
|
|
int virStrToLong_ull(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
unsigned long long *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2014-04-30 20:11:09 -06:00
|
|
|
int virStrToLong_ullp(char const *s,
|
|
|
|
char **end_ptr,
|
|
|
|
int base,
|
2014-07-21 10:17:02 +02:00
|
|
|
unsigned long long *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2013-04-03 12:36:23 +02:00
|
|
|
int virStrToDouble(char const *s,
|
|
|
|
char **end_ptr,
|
2014-07-21 10:17:02 +02:00
|
|
|
double *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2013-04-03 12:36:23 +02:00
|
|
|
|
2017-06-21 14:08:28 -03:00
|
|
|
int virDoubleToStr(char **strp, double number)
|
2019-10-22 15:26:14 +02:00
|
|
|
ATTRIBUTE_NONNULL(1);
|
2017-06-21 14:08:28 -03:00
|
|
|
|
2013-04-03 12:36:23 +02:00
|
|
|
void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
|
|
|
|
void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);
|
2021-01-07 19:55:43 -05:00
|
|
|
void virSkipToDigit(const char **str) ATTRIBUTE_NONNULL(1);
|
2013-04-03 12:36:23 +02:00
|
|
|
void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1);
|
|
|
|
void virSkipSpacesBackwards(const char *str, char **endp)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
2014-10-22 10:26:42 +02:00
|
|
|
bool virStringIsEmpty(const char *str);
|
|
|
|
|
2021-03-02 11:00:23 +01:00
|
|
|
int virStrcpy(char *dest, const char *src, size_t destbytes);
|
2019-06-18 11:13:02 -05:00
|
|
|
#define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest))
|
2013-04-03 14:51:20 +02:00
|
|
|
|
2013-11-28 11:14:59 +00:00
|
|
|
int virStringSortCompare(const void *a, const void *b);
|
|
|
|
int virStringSortRevCompare(const void *a, const void *b);
|
2015-06-15 18:53:58 +02:00
|
|
|
int virStringToUpper(char **dst, const char *src);
|
2013-11-28 11:14:59 +00:00
|
|
|
|
2014-01-23 10:28:29 +01:00
|
|
|
ssize_t virStringSearch(const char *str,
|
|
|
|
const char *regexp,
|
|
|
|
size_t max_results,
|
|
|
|
char ***matches)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
|
|
|
|
|
2017-05-11 17:16:13 +02:00
|
|
|
bool virStringMatch(const char *str,
|
|
|
|
const char *regexp);
|
|
|
|
|
2014-02-19 20:30:46 +00:00
|
|
|
char *virStringReplace(const char *haystack,
|
|
|
|
const char *oldneedle,
|
|
|
|
const char *newneedle)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
|
|
|
|
2019-03-06 17:05:03 +01:00
|
|
|
bool virStringHasSuffix(const char *str,
|
|
|
|
const char *suffix);
|
2019-03-07 10:17:19 +01:00
|
|
|
bool virStringHasCaseSuffix(const char *str,
|
|
|
|
const char *suffix);
|
2019-03-07 10:18:38 +01:00
|
|
|
bool virStringStripSuffix(char *str,
|
2019-10-14 14:25:14 +02:00
|
|
|
const char *suffix) G_GNUC_WARN_UNUSED_RESULT;
|
2019-03-07 10:18:58 +01:00
|
|
|
bool virStringMatchesNameSuffix(const char *file,
|
|
|
|
const char *name,
|
|
|
|
const char *suffix);
|
2019-03-06 15:07:26 +01:00
|
|
|
|
2014-10-07 17:27:40 +02:00
|
|
|
void virStringStripIPv6Brackets(char *str);
|
2017-04-26 16:26:53 +02:00
|
|
|
bool virStringHasChars(const char *str,
|
|
|
|
const char *chars);
|
2015-04-14 12:30:16 +02:00
|
|
|
bool virStringHasControlChars(const char *str);
|
|
|
|
void virStringStripControlChars(char *str);
|
2017-12-18 15:46:53 +01:00
|
|
|
void virStringFilterChars(char *str, const char *valid);
|
2014-10-07 17:27:40 +02:00
|
|
|
|
2016-04-11 13:35:25 +02:00
|
|
|
bool virStringIsPrintable(const char *str);
|
2016-05-12 11:43:39 -04:00
|
|
|
bool virStringBufferIsPrintable(const uint8_t *buf, size_t buflen);
|
2016-04-11 13:35:25 +02:00
|
|
|
|
2017-05-10 09:16:11 +01:00
|
|
|
void virStringTrimOptionalNewline(char *str);
|
2017-03-29 13:48:22 +02:00
|
|
|
|
2017-07-13 15:31:50 +02:00
|
|
|
int virStringParsePort(const char *str,
|
2017-07-20 12:42:53 +02:00
|
|
|
unsigned int *port)
|
2019-10-14 14:25:14 +02:00
|
|
|
ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2017-07-13 15:31:50 +02:00
|
|
|
|
2019-03-13 15:30:10 +09:00
|
|
|
int virStringParseYesNo(const char *str,
|
|
|
|
bool *result)
|
2019-10-14 14:25:14 +02:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2020-02-24 00:44:01 +01:00
|
|
|
|
2020-02-24 00:47:18 +01:00
|
|
|
int virStringParseVersion(unsigned long *version,
|
|
|
|
const char *str,
|
2020-02-24 00:44:01 +01:00
|
|
|
bool allowMissing);
|