|
Packit Service |
cbade1 |
/*
|
|
Packit Service |
cbade1 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
cbade1 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
cbade1 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
cbade1 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
cbade1 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
cbade1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
cbade1 |
* GNU General Public License for more details.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
cbade1 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
cbade1 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
cbade1 |
* 02110-1301, USA.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/vdoStringUtils.h#1 $
|
|
Packit Service |
cbade1 |
*/
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
#ifndef VDO_STRING_UTILS_H
|
|
Packit Service |
cbade1 |
#define VDO_STRING_UTILS_H
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
#include <stdarg.h>
|
|
Packit Service |
cbade1 |
#include <linux/types.h>
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Helper to append a string to a buffer.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param buffer the place at which to append the string
|
|
Packit Service |
cbade1 |
* @param bufEnd pointer to the end of the buffer
|
|
Packit Service |
cbade1 |
* @param fmt a printf format string
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return the updated buffer position after the append
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* if insufficient space is available, the contents are silently truncated
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
char *appendToBuffer(char *buffer, char *bufEnd, const char *fmt, ...);
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Variable-arglist helper to append a string to a buffer.
|
|
Packit Service |
cbade1 |
* If insufficient space is available, the contents are silently truncated.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param buffer the place at which to append the string
|
|
Packit Service |
cbade1 |
* @param bufEnd pointer to the end of the buffer
|
|
Packit Service |
cbade1 |
* @param fmt a printf format string
|
|
Packit Service |
cbade1 |
* @param args printf arguments
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return the updated buffer position after the append
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
char *vAppendToBuffer(char *buffer,
|
|
Packit Service |
cbade1 |
char *bufEnd,
|
|
Packit Service |
cbade1 |
const char *fmt,
|
|
Packit Service |
cbade1 |
va_list args);
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Split the input string into substrings, separated at occurrences of
|
|
Packit Service |
cbade1 |
* the indicated character, returning a null-terminated list of string
|
|
Packit Service |
cbade1 |
* pointers.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* The string pointers and the pointer array itself should both be
|
|
Packit Service |
cbade1 |
* freed with FREE() when no longer needed. This can be done with
|
|
Packit Service |
cbade1 |
* freeStringArray (below) if the pointers in the array are not
|
|
Packit Service |
cbade1 |
* changed. Since the array and copied strings are allocated by this
|
|
Packit Service |
cbade1 |
* function, it may only be used in contexts where allocation is
|
|
Packit Service |
cbade1 |
* permitted.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* Empty substrings are not ignored; that is, returned substrings may
|
|
Packit Service |
cbade1 |
* be empty strings if the separator occurs twice in a row.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param [in] string The input string to be broken apart
|
|
Packit Service |
cbade1 |
* @param [in] separator The separator character
|
|
Packit Service |
cbade1 |
* @param [out] substringArrayPtr The NULL-terminated substring array
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return UDS_SUCCESS or -ENOMEM
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
int splitString(const char *string, char separator, char ***substringArrayPtr)
|
|
Packit Service |
cbade1 |
__attribute__((warn_unused_result));
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Join the input substrings into one string, joined with the indicated
|
|
Packit Service |
cbade1 |
* character, returning a string.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param [in] substringArray The NULL-terminated substring array
|
|
Packit Service |
cbade1 |
* @param [in] arrayLength A bound on the number of valid elements
|
|
Packit Service |
cbade1 |
* in substringArray, in case it is not
|
|
Packit Service |
cbade1 |
* NULL-terminated.
|
|
Packit Service |
cbade1 |
* @param [in] separator The separator character
|
|
Packit Service |
cbade1 |
* @param [out] stringPtr A pointer to hold the joined string
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
int joinStrings(char **substringArray,
|
|
Packit Service |
cbade1 |
size_t arrayLength,
|
|
Packit Service |
cbade1 |
char separator,
|
|
Packit Service |
cbade1 |
char **stringPtr)
|
|
Packit Service |
cbade1 |
__attribute__((warn_unused_result));
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Free a list of non-NULL string pointers, and then the list itself.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param stringArray The string list
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
void freeStringArray(char **stringArray);
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Parse a string as an "unsigned int" value, yielding the value.
|
|
Packit Service |
cbade1 |
* On overflow, -ERANGE is returned. On invalid number, -EINVAL is
|
|
Packit Service |
cbade1 |
* returned.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param [in] input The string to be processed
|
|
Packit Service |
cbade1 |
* @param [out] valuePtr The value of the number read
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return UDS_SUCCESS or -EINVAL or -ERANGE.
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
int stringToUInt(const char *input, unsigned int *valuePtr)
|
|
Packit Service |
cbade1 |
__attribute__((warn_unused_result));
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
#endif /* VDO_STRING_UTILS_H */
|