util: virstring: Remove virStrncpy

The function is now unused and motivated users to write crazy parsers
which were hard to understand, had pointless error paths just to avoid
few memory allocations.

Remove the function as we're fine with g_strndup and virStrcpy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-03-02 14:26:24 +01:00
parent a7cb4dbca5
commit d380dd0efd
4 changed files with 0 additions and 60 deletions

View File

@ -714,19 +714,6 @@ does **not** guarantee a NULL-terminated buffer, which makes it
extremely dangerous to use. Instead, use one of the replacement
functions provided by libvirt:
::
virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
The first two arguments have the same meaning as for strncpy,
namely the destination and source of the copy operation. Unlike
strncpy, the function will always copy exactly the number of bytes
requested and make sure the destination is NULL-terminated, as the
source is required to be; sanity checks are performed to ensure
the size of the destination, as specified by the last argument, is
sufficient for the operation to succeed. On success, 0 is
returned; on failure, a value <0 is returned instead.
::
virStrcpy(char *dest, const char *src, size_t destbytes)

View File

@ -3266,7 +3266,6 @@ virStringStripIPv6Brackets;
virStringStripSuffix;
virStringToUpper;
virStringTrimOptionalNewline;
virStrncpy;
virStrToDouble;
virStrToLong_i;
virStrToLong_l;

View File

@ -452,50 +452,6 @@ virDoubleToStr(char **strp, double number)
}
/**
* virStrncpy:
*
* @dest: destination buffer
* @src: source buffer
* @n: number of bytes to copy
* @destbytes: number of bytes the destination can accommodate
*
* Copies the first @n bytes of @src to @dest.
*
* @src must be NULL-terminated; if successful, @dest is guaranteed to
* be NULL-terminated as well.
*
* @n must be a reasonable value, that is, it must not exceed either
* the length of @src or the size of @dest. For the latter constraint,
* the fact that @dest needs to accommodate a NULL byte in addition to
* the bytes copied from @src must be taken into account.
*
* If you want to copy *all* of @src to @dest, use virStrcpy() or
* virStrcpyStatic() instead.
*
* Returns: 0 on success, <0 on failure.
*/
int
virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
{
size_t src_len = strlen(src);
/* As a special case, -1 means "copy the entire string".
*
* This is to avoid calling strlen() twice, once in the virStrcpy()
* wrapper and once here for bound checking purposes. */
if (n == -1)
n = src_len;
if (n > src_len || n > (destbytes - 1))
return -1;
memcpy(dest, src, n);
dest[n] = '\0';
return 0;
}
/**
* virStrcpy:
*

View File

@ -97,8 +97,6 @@ void virSkipSpacesBackwards(const char *str, char **endp)
bool virStringIsEmpty(const char *str);
int virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
G_GNUC_WARN_UNUSED_RESULT;
int virStrcpy(char *dest, const char *src, size_t destbytes);
#define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest))