AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
snprintf.c File Reference

snprintf() and vsnprintf(): formatting into a buffer, with the formats printk() has: c, s, d and u (32-bit), ld and lu (64-bit), x and lx (hexadecimal), b (binary) and p. More...

#include <core/system.h>

Go to the source code of this file.

Functions

static int snputc (char *s, size_t n, char c)
 Writes one character, if there is room.
static int snputs (char *s, size_t n, char *str)
 Writes a string, as much of it as fits.
static int snputx (char *s, size_t n, uint32_t val)
 Writes a 32-bit number in hexadecimal, all 8 digits.
static int snputlx (char *s, size_t n, uint64_t val)
 Writes a 64-bit number in hexadecimal, all 16 digits.
static int snputud (char *s, size_t n, uint32_t val)
 Writes an unsigned 32-bit number in decimal.
static int snputul (char *s, size_t n, uint64_t val)
 Writes an unsigned 64-bit number in decimal.
static int snputb (char *s, size_t n, uint8_t val)
 Writes a byte in binary, all 8 digits.
int vsnprintf (char *s, size_t n, const char *fmt, va_list args)
 Formats a string into a buffer, with its arguments in a va_list.
int snprintf (char *s, size_t n, const char *fmt,...)
 Formats a string into a buffer.

Detailed Description

snprintf() and vsnprintf(): formatting into a buffer, with the formats printk() has: c, s, d and u (32-bit), ld and lu (64-bit), x and lx (hexadecimal), b (binary) and p.

The l formats take a 64-bit argument on every architecture. Each helper below writes at most n characters to s, and returns how many it wrote.

Definition in file snprintf.c.

Function Documentation

◆ snprintf()

int snprintf ( char * s,
size_t n,
const char * fmt,
... )

Formats a string into a buffer.

Parameters
sthe buffer
nits size: at most n - 1 characters are written, and a NUL after them (nothing at all if n is 0)
fmtthe format (see the top of this file for what it supports)
Returns
how many characters were written, not counting the NUL

Definition at line 226 of file snprintf.c.

References snprintf(), va_end, va_list, va_start, and vsnprintf().

Referenced by apic_describe(), arch_interrupts_info(), csi(), netif_register(), procfs_buddyinfo(), procfs_cmdline(), procfs_devices(), procfs_filesystems(), procfs_finddir(), procfs_kvmem(), procfs_meminfo(), procfs_mounts(), procfs_proc_maps(), procfs_proc_status(), procfs_proc_vmstats(), procfs_rdcmdline(), procfs_readdir(), procfs_uptime(), procfs_version(), pts_new(), pty_free(), and snprintf().

◆ snputb()

int snputb ( char * s,
size_t n,
uint8_t val )
static

Writes a byte in binary, all 8 digits.

Definition at line 104 of file snprintf.c.

References snputb(), and snputs().

Referenced by snputb(), and vsnprintf().

◆ snputc()

int snputc ( char * s,
size_t n,
char c )
static

Writes one character, if there is room.

Definition at line 13 of file snprintf.c.

References snputc().

Referenced by snputc(), snputud(), snputul(), and vsnprintf().

◆ snputlx()

int snputlx ( char * s,
size_t n,
uint64_t val )
static

Writes a 64-bit number in hexadecimal, all 16 digits.

Definition at line 53 of file snprintf.c.

References snputlx(), and snputs().

Referenced by snputlx(), and vsnprintf().

◆ snputs()

int snputs ( char * s,
size_t n,
char * str )
static

Writes a string, as much of it as fits.

Definition at line 24 of file snprintf.c.

References snputs().

Referenced by snputb(), snputlx(), snputs(), snputud(), snputul(), snputx(), and vsnprintf().

◆ snputud()

int snputud ( char * s,
size_t n,
uint32_t val )
static

Writes an unsigned 32-bit number in decimal.

Definition at line 67 of file snprintf.c.

References snputc(), snputs(), and snputud().

Referenced by snputud(), and vsnprintf().

◆ snputul()

int snputul ( char * s,
size_t n,
uint64_t val )
static

Writes an unsigned 64-bit number in decimal.

Definition at line 86 of file snprintf.c.

References snputc(), snputs(), and snputul().

Referenced by snputul(), and vsnprintf().

◆ snputx()

int snputx ( char * s,
size_t n,
uint32_t val )
static

Writes a 32-bit number in hexadecimal, all 8 digits.

Definition at line 37 of file snprintf.c.

References snputs(), and snputx().

Referenced by snputx(), and vsnprintf().

◆ vsnprintf()

int vsnprintf ( char * s,
size_t n,
const char * fmt,
va_list args )

Formats a string into a buffer, with its arguments in a va_list.

Parameters
sthe buffer
nits size: at most n - 1 characters are written, and a NUL after them (nothing at all if n is 0)
fmtthe format (see the top of this file for what it supports)
argsthe arguments
Returns
how many characters were written, not counting the NUL

Definition at line 128 of file snprintf.c.

References snputb(), snputc(), snputlx(), snputs(), snputud(), snputul(), snputx(), va_arg, va_list, and vsnprintf().

Referenced by snprintf(), and vsnprintf().