ft_printf
Functions
ft_printf() family

Replicate behaviour of printf(3) functions. More...

Functions

int ft_printf (const char *format,...)
 Replicates behaviour of printf(3). More...
 
int ft_dprintf (int fd, const char *format,...)
 Replicates behaviour of dprintf(3). More...
 
int ft_vprintf (const char *format, va_list ap)
 Replicates behaviour of vprintf(3). More...
 
int ft_vdprintf (int fd, const char *format, va_list ap)
 Replicates behaviour of vdprintf(3). More...
 
int ft_sprintf (char *str, const char *format,...)
 Replicates behaviour of sprintf(3). More...
 
int ft_vsprintf (char *str, const char *format, va_list ap)
 Replicates behaviour of vsprintf(3). More...
 
int ft_snprintf (char *str, size_t size, const char *format,...)
 Replicates behaviour of snprintf(3). More...
 
int ft_vsnprintf (char *str, size_t size, const char *format, va_list ap)
 Replicates behaviour of vsnprintf(3). More...
 
int ft_asprintf (char **ret, const char *format,...)
 Replicates behaviour of asprintf(3). More...
 
int ft_vasprintf (char **ret, const char *format, va_list ap)
 Replicates behaviour of vasprintf(3). More...
 

Detailed Description

Replicate behaviour of printf(3) functions.

Support standard field values and combination thereof (where applicable):

Custom specifications:

To print in color
ft_printf("{red}Color-print. {eoc}Normal print.");
See also
https://en.wikipedia.org/wiki/Printf_format_string
https://linux.die.net/man/3/printf

Function Documentation

◆ ft_asprintf()

int ft_asprintf ( char **  ret,
const char *  format,
  ... 
)

Replicates behaviour of asprintf(3).

Parameters
[out]retPointer that will be set to a buffer sufficiently large to hold the formatted string. This pointer should be passed to free(3) to release the allocated storage when it is no longer needed.
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]...Variadic arguments
Returns
Number of characters printed or -1 if an error occurs. Additionaly, in case of an error, *ret is set to be NULL and errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported).

References ft_vasprintf().

+ Here is the call graph for this function:

◆ ft_dprintf()

int ft_dprintf ( int  fd,
const char *  format,
  ... 
)

Replicates behaviour of dprintf(3).

Parameters
[in]fdFile descriptor where to print output.
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]...Variadic arguments
Returns
Number of characters printed or -1 if an error occurs. Additionaly, in case of an error, errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported).

References ft_vdprintf().

+ Here is the call graph for this function:

◆ ft_printf()

int ft_printf ( const char *  format,
  ... 
)

Replicates behaviour of printf(3).

Parameters
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]...Variadic arguments
Returns
Number of characters printed or -1 if an error occurs. Additionaly, in case of an error, errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported) or other values set by write(2).

References ft_vprintf().

+ Here is the call graph for this function:

◆ ft_snprintf()

int ft_snprintf ( char *  str,
size_t  size,
const char *  format,
  ... 
)

Replicates behaviour of snprintf(3).

Parameters
[in]strString where to print output.
[in]sizeSize of the string (at most size - 1 characters are printed and, unless size is 0, the string is always null-terminated).
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]...Variadic arguments
Returns
Number of characters printed if size were unlimited (not including the final \0) or -1 if an error occurs. Additionaly, in case of an error, errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported).

References ft_vsnprintf().

+ Here is the call graph for this function:

◆ ft_sprintf()

int ft_sprintf ( char *  str,
const char *  format,
  ... 
)

Replicates behaviour of sprintf(3).

Parameters
[in]strString where to print output.
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]...Variadic arguments
Returns
Number of characters printed or -1 if an error occurs. Additionaly, in case of an error, errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported).

References ft_vsnprintf().

+ Here is the call graph for this function:

◆ ft_vasprintf()

int ft_vasprintf ( char **  ret,
const char *  format,
va_list  ap 
)

Replicates behaviour of vasprintf(3).

Parameters
[out]retPointer that will be set to a buffer sufficiently large to hold the formatted string. This pointer should be passed to free(3) to release the allocated storage when it is no longer needed.
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]apA variable used by stdarg(3) to step through a list of variadic arguments.
Returns
Number of characters printed or -1 if an error occurs. Additionaly, in case of an error, *ret is set to be NULL and errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported).

References ft_vsnprintf(), and ft_vsprintf().

+ Here is the call graph for this function:

◆ ft_vdprintf()

int ft_vdprintf ( int  fd,
const char *  format,
va_list  ap 
)

Replicates behaviour of vdprintf(3).

Parameters
[in]fdFile descriptor where to print output
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]apA variable used by stdarg(3) to step through a list of variadic arguments.
Returns
Number of characters printed or -1 if an error occurs. Additionaly, in case of an error, errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported) or other values set by write(2) (e.g. due to an invalid file descriiptor).

References ft_vprintf().

+ Here is the call graph for this function:

◆ ft_vprintf()

int ft_vprintf ( const char *  format,
va_list  ap 
)

Replicates behaviour of vprintf(3).

Parameters
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]apA variable used by stdarg(3) to step through a list of variadic arguments.
Returns
Number of characters printed or -1 if an error occurs. Additionaly, in case of an error, errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported) or other values set by write(2) (e.g. due to an invalid file descriiptor).

◆ ft_vsnprintf()

int ft_vsnprintf ( char *  str,
size_t  size,
const char *  format,
va_list  ap 
)

Replicates behaviour of vsnprintf(3).

Parameters
[in]strString where to print output.
[in]sizeSize of the string (at most size - 1 characters are printed and, unless size is 0, the string is always null-terminated).
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]apA variable used by stdarg(3) to step through a list of variadic arguments.
Returns
Number of characters printed if size were unlimited (not including the final \0) or -1 if an error occurs. Additionaly, in case of an error, errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported).

References ft_vprintf().

+ Here is the call graph for this function:

◆ ft_vsprintf()

int ft_vsprintf ( char *  str,
const char *  format,
va_list  ap 
)

Replicates behaviour of vsprintf(3).

Parameters
[in]strString where to print output.
[in]formatFormat string that specifies how subsequent arguments are converted for output
[in]apA variable used by stdarg(3) to step through a list of variadic arguments.
Returns
Number of characters printed or -1 if an error occurs. Additionaly, in case of an error, errno is set to ENOMEM (memory allocation error), EINVAL (invalid format placeholder specification), ENOTSUP (type field value not supported).

References ft_vprintf().

+ Here is the call graph for this function: