---
name: "libwget-mem"
section: "3"
platform: "linux"
package: "wget2-dev"
version: "2.2.0+ds-1+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/libwget-mem"
---

# libwget-mem(3)

Memory functions

## NAME

libwget-mem - Memory functions

## SYNOPSIS

### Functions

void \* **wget\_memdup** (const void \*m, size\_t n)\
 char \* **wget\_strdup** (const char \*s)\
 char \* **wget\_strmemdup** (const void \*m, size\_t n)\
 size\_t **wget\_strmemcpy** (char \*s, size\_t ssize, const void \*m, size\_t n)\
 void \* **wget\_strmemcpy\_a** (char \*s, size\_t ssize, const void \*m, size\_t n)\

## Detailed Description

This is a collections of short memory function not available in standard libraries.

## Function Documentation

### void \* wget\_memdup (const void \* m, size\_t n)

**Parameters**

*m* Memory to clone \
 *n* Length of memory

**Returns**

Cloned memory

Clone's the memory region `m` with length `n`. Returns NULL if `m` is NULL.

You should free() the returned pointer when not needed any more.

### char \* wget\_strdup (const char \* s)

**Parameters**

*s* String to clone

**Returns**

Cloned string

Clone's the string `s` like strdup() does. Returns NULL if `s` is NULL.

You should free() the returned string when not needed any more.

### char \* wget\_strmemdup (const void \* m, size\_t n)

**Parameters**

*m* Memory to convert into string \
 *n* Length of memory

**Returns**

Created string

Convert the given memory region `m` with length `n` into a C string. Returns NULL if `m` is NULL.

You should free() the returned string when not needed any more.

### size\_t wget\_strmemcpy (char \* s, size\_t ssize, const void \* m, size\_t n)

**Parameters**

*s* Buffer to hold the C string output \
 *ssize* Size of the output buffer \
 *m* Memory to read from \
 *n* Length of memory

**Returns**

Number of bytes copied, not counting the trailing 0 byte

Convert the given memory region `m` with length `n` into a C string at `s`. A max. of `ssize` - 1 is copied into `s`.

### void \* wget\_strmemcpy\_a (char \* s, size\_t ssize, const void \* m, size\_t n)

**Parameters**

*s* Buffer to hold the C string output \
 *ssize* Size of the output buffer \
 *m* Memory to read from \
 *n* Length of memory

**Returns**

Pointer to destination (either `s` or a freshly allocated buffer)

Convert the given memory region `m` with length `n` into a C string at `s` or at freshly allocated memory, if the space in `s` was not sufficient.

If `s` was too small to hold `n` + 1 bytes, the result must be free'd after use, e.g. if (res != s) wget\_free(res);

## Author

Generated automatically by Doxygen for wget2 from the source code.
