naev 0.12.5
nstring.c File Reference

Some string routines for naev. More...

#include "nstring.h"
#include "log.h"
Include dependency graph for nstring.c:

Go to the source code of this file.

Functions

char * strnstr (const char *haystack, const char *needle, size_t size)
 A bounded version of strstr. Conforms to BSD semantics.
char * strndup (const char *s, size_t n)
 Return a pointer to a new string, which is a duplicate of the string s (or, if necessary, which contains the first nn bytes of s plus a terminating null).
int strsort (const void *p1, const void *p2)
 Sort function for sorting strings with qsort().
int strsort_reverse (const void *p1, const void *p2)
 Order-reversed version of strsort().
int scnprintf (char *text, size_t maxlen, const char *fmt,...)
 Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer. This makes it possible to chain these calls to concatenate into a buffer without introducing a potential bug every time. This call was first added to the Linux kernel by Juergen Quade.
int num2str (char dest[NUM2STRLEN], double n, int decimals)
 Converts a numeric value to a string.
const char * num2strU (double n, int decimals)
 Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value.
void print_with_line_numbers (const char *str)
 Prints to stderr with line numbers.

Detailed Description

Some string routines for naev.

Definition in file nstring.c.

Function Documentation

◆ num2str()

int num2str ( char dest[NUM2STRLEN],
double n,
int decimals )

Converts a numeric value to a string.

Parameters
[out]destString to write to.
nNumber to write.
decimalsNumber of decimals to write.

Definition at line 123 of file nstring.c.

◆ num2strU()

const char * num2strU ( double n,
int decimals )

Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value.

Parameters
nNumber to write.
decimalsNumber of decimals to write.
Returns
Fancy string number.

Definition at line 163 of file nstring.c.

◆ print_with_line_numbers()

void print_with_line_numbers ( const char * str)

Prints to stderr with line numbers.

Parameters
strString to print.

Definition at line 175 of file nstring.c.

◆ scnprintf()

int scnprintf ( char * text,
size_t maxlen,
const char * fmt,
... )

Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer. This makes it possible to chain these calls to concatenate into a buffer without introducing a potential bug every time. This call was first added to the Linux kernel by Juergen Quade.

Definition at line 102 of file nstring.c.

◆ strndup()

char * strndup ( const char * s,
size_t n )

Return a pointer to a new string, which is a duplicate of the string s (or, if necessary, which contains the first nn bytes of s plus a terminating null).

Taken from glibc. Conforms to POSIX.1-2008.

Definition at line 69 of file nstring.c.

◆ strnstr()

char * strnstr ( const char * haystack,
const char * needle,
size_t size )

A bounded version of strstr. Conforms to BSD semantics.

Parameters
haystackThe string to search in
sizeThe size of haystack
needleThe string to search for
Returns
A pointer to the first occurrence of needle in haystack, or NULL

Definition at line 26 of file nstring.c.

◆ strsort()

int strsort ( const void * p1,
const void * p2 )

Sort function for sorting strings with qsort().

Definition at line 83 of file nstring.c.

◆ strsort_reverse()

int strsort_reverse ( const void * p1,
const void * p2 )

Order-reversed version of strsort().

Definition at line 91 of file nstring.c.