String/number conversion utilities.
More...
|
| int | ft_atoi (const char *str) |
| | Converts a string to an integer.
|
| |
| long | ft_atol (const char *str) |
| | Converts a string to a long integer.
|
| |
| pid_t | ft_atopid (const char *str) |
| | Converts a string to a pid_t.
|
| |
| size_t | ft_atozu (const char *str) |
| | Converts a string to a size_t.
|
| |
| char * | ft_itoa (int n) |
| | Converts an integer to a string.
|
| |
| char * | ft_utoa (unsigned int n) |
| | Converts an unsigned integer to a string.
|
| |
| char * | ft_zutoa (size_t n) |
| | Converts a size_t to a string.
|
| |
| char * | ft_ltoa (long n) |
| | Converts a long integer to a string.
|
| |
| char * | ft_pidtoa (pid_t n) |
| | Converts a pid_t to a string.
|
| |
| char * | ft_ultoa_base (unsigned long n, const char *base) |
| | Converts an unsigned long to a string in a given base.
|
| |
| bool | parse_int (char *s, int *out) |
| | Parses a string to an integer with overflow detection.
|
| |
| bool | parse_long (char *s, long *out) |
| | Parses a string to a long with overflow detection.
|
| |
String/number conversion utilities.
Functions to convert between strings and numeric types.
◆ ft_atoi()
| int ft_atoi |
( |
const char * |
str | ) |
|
Converts a string to an integer.
- Parameters
-
- Returns
- The converted integer value.
◆ ft_atol()
| long ft_atol |
( |
const char * |
str | ) |
|
Converts a string to a long integer.
- Parameters
-
- Returns
- The converted long value.
◆ ft_atopid()
| pid_t ft_atopid |
( |
const char * |
str | ) |
|
Converts a string to a pid_t.
- Parameters
-
- Returns
- The converted pid_t value.
◆ ft_atozu()
| size_t ft_atozu |
( |
const char * |
str | ) |
|
Converts a string to a size_t.
- Note
- Skips leading whitespace and accepts an optional leading '+'.
- Warning
- Returns SIZE_MAX on overflow.
- Parameters
-
- Returns
- The converted size_t value.
◆ ft_itoa()
Converts an integer to a string.
- Note
- Caller owns the returned string and must free it.
- Parameters
-
- Returns
- Newly allocated string (owned), or NULL on failure.
◆ ft_ltoa()
Converts a long integer to a string.
- Note
- Caller owns the returned string and must free it.
- Parameters
-
| n | Long integer to convert. |
- Returns
- Newly allocated string (owned), or NULL on failure.
◆ ft_pidtoa()
| char * ft_pidtoa |
( |
pid_t |
n | ) |
|
Converts a pid_t to a string.
- Note
- Caller owns the returned string and must free it.
- Parameters
-
- Returns
- Newly allocated string (owned), or NULL on failure.
◆ ft_ultoa_base()
| char * ft_ultoa_base |
( |
unsigned long |
n, |
|
|
const char * |
base |
|
) |
| |
Converts an unsigned long to a string in a given base.
- Note
- Caller owns the returned string and must free it.
- Parameters
-
| n | Number to convert. |
| base | String representing the base characters (borrowed, >= 2 chars). |
- Returns
- Newly allocated string (owned), or NULL on failure.
◆ ft_utoa()
| char * ft_utoa |
( |
unsigned int |
n | ) |
|
Converts an unsigned integer to a string.
- Note
- Caller owns the returned string and must free it.
- Parameters
-
| n | Unsigned integer to convert. |
- Returns
- Newly allocated string (owned), or NULL on failure.
◆ ft_zutoa()
| char * ft_zutoa |
( |
size_t |
n | ) |
|
Converts a size_t to a string.
- Note
- Caller owns the returned string and must free it.
- Parameters
-
- Returns
- Newly allocated string (owned), or NULL on failure.
◆ parse_int()
| bool parse_int |
( |
char * |
s, |
|
|
int * |
out |
|
) |
| |
Parses a string to an integer with overflow detection.
Accepts an optional leading '+' or '-' sign followed by digits. Returns false if the string is empty, contains non-digit characters, or the value would overflow an int.
- Parameters
-
| s | String to parse (borrowed). |
| out | Pointer to store the parsed integer (modified on success). |
- Returns
- true on success, false if parsing failed or value out of range.
◆ parse_long()
| bool parse_long |
( |
char * |
s, |
|
|
long * |
out |
|
) |
| |
Parses a string to a long with overflow detection.
Accepts an optional leading '+' or '-' sign followed by digits. Returns false if the string is empty, contains non-digit characters, or the value would overflow a long.
- Parameters
-
| s | String to parse (borrowed). |
| out | Pointer to store the parsed long (modified on success). |
- Returns
- true on success, false if parsing failed or value out of range.