SCTC
the soundcloud.com terminal client
Macros | Functions
helper.h File Reference

Several basic helper functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INVALID_TIME   ((unsigned int) ~0)
 value indicating an invalid time More...
 
#define lmalloc(S)   _lmalloc (__FILE__, __LINE__, __func__, S)
 Logging wrapper for malloc(). More...
 
#define lcalloc(N, S)   _lcalloc (__FILE__, __LINE__, __func__, N, S)
 Logging wrapper for calloc(). More...
 
#define lrealloc(P, S)   _lrealloc(__FILE__, __LINE__, __func__, P, S)
 Logging wrapper for realloc(). More...
 
#define lstrdup(S)   _lstrdup(__FILE__, __LINE__, __func__, S)
 Logging wrapper for strdup(). More...
 

Functions

char * smprintf (char *fmt,...)
 printf style function with automated allocation of buffer. More...
 
int snprint_ftime (char *buffer, size_t buffer_size, int time_secs)
 Write a formated version of time_secs to buffer. More...
 
void strcrep (char *str, char s, char r)
 replace a char with another char in a given string More...
 
char * strstrp (char *str)
 
bool yank (char *text)
 Yank the provided text. More...
 
unsigned int parse_time_to_sec (char *str)
 Parse a string to seconds. More...
 
void * _lmalloc (char *srcfile, int srcline, const char *srcfunc, size_t size)
 
void * _lcalloc (char *srcfile, int srcline, const char *srcfunc, size_t nmemb, size_t size)
 
void * _lrealloc (char *srcfile, int srcline, const char *srcfunc, void *ptr, size_t size)
 
char * _lstrdup (char *srcfile, int srcline, const char *srcfunc, const char *s)
 

Detailed Description

Several basic helper functions.

Macro Definition Documentation

#define INVALID_TIME   ((unsigned int) ~0)

value indicating an invalid time

#define lcalloc (   N,
 
)    _lcalloc (__FILE__, __LINE__, __func__, N, S)

Logging wrapper for calloc().

Behaves like calloc(), but writes a message to the logfile in case of an error. lcalloc() does not terminate the execution.

Always use this macro instead of directly calling _lrealloc().

#define lmalloc (   S)    _lmalloc (__FILE__, __LINE__, __func__, S)

Logging wrapper for malloc().

Behaves like malloc(), but writes a message to the logfile in case of an error. lmalloc() does not terminate the execution.

Always use this macro instead of directly calling _lmalloc().

#define lrealloc (   P,
 
)    _lrealloc(__FILE__, __LINE__, __func__, P, S)

Logging wrapper for realloc().

Behaves like realloc(), but writes a message to the logfile in case of an error. lrealloc() does not terminate the execution.

Always use this macro instead of directly calling _lrealloc().

#define lstrdup (   S)    _lstrdup(__FILE__, __LINE__, __func__, S)

Logging wrapper for strdup().

Behaves like strdup(), but writes a message to the logfile in case of an error. lstrdup() does not terminate the execution.

Always use this macro instead of directly calling _lstrdup().

Function Documentation

void* _lcalloc ( char *  srcfile,
int  srcline,
const char *  srcfunc,
size_t  nmemb,
size_t  size 
)

The internal implementation for lcalloc.

Warning: This function is not intended to be called directly by the user. Use lcalloc() instead, as this macro inserts the correct position of the call to _lcalloc().

Parameters
srcfileThe file executing the call to _lcalloc(); filled by macro lcalloc(), do not use "by hand"
srclineThe line in the file executing the call to _lcalloc(); filled by macro lcalloc(), do not use "by hand"
srcfuncThe function calling _lcallocg(); filled by macro lcalloc(), do not use "by hand"
nmembThe number of elements to be allocated
sizeThe size of each single element to be allocated

Here is the call graph for this function:

void* _lmalloc ( char *  srcfile,
int  srcline,
const char *  srcfunc,
size_t  size 
)

The internal implementation for lmalloc.

Warning: This function is not intended to be called directly by the user. Use lmalloc() instead, as this macro inserts the correct position of the call to _lmalloc().

Parameters
srcfileThe file executing the call to _lmalloc(); filled by macro lmalloc(), do not use "by hand"
srclineThe line in the file executing the call to _lmalloc(); filled by macro lmalloc(), do not use "by hand"
srcfuncThe function calling _lmalloc(); filled by macro lmalloc(), do not use "by hand"
sizeThe number of bytes to be allocated

Here is the call graph for this function:

void* _lrealloc ( char *  srcfile,
int  srcline,
const char *  srcfunc,
void *  ptr,
size_t  size 
)

The internal implementation for lrealloc.

Warning: This function is not intended to be called directly by the user. Use lrealloc() instead, as this macro inserts the correct position of the call to _lrealloc().

Parameters
srcfileThe file executing the call to _lrealloc(); filled by macro lrealloc(), do not use "by hand"
srclineThe line in the file executing the call to _lrealloc(); filled by macro lrealloc(), do not use "by hand"
srcfuncThe function calling _lrealloc(); filled by macro lrealloc(), do not use "by hand"
ptrPointer to the memory to resize
sizeThe number of bytes to be reallocated

Here is the call graph for this function:

char* _lstrdup ( char *  srcfile,
int  srcline,
const char *  srcfunc,
const char *  s 
)

The internal implementation for lstrdup.

Warning: This function is not intended to be called directly by the user. Use lstrdup() instead, as this macro inserts the correct position of the call to _lstrdup().

Parameters
srcfileThe file executing the call to _lstrdup(); filled by macro lstrdup), do not use "by hand"
srclineThe line in the file executing the call to _lstrdup(); filled by macro lstrdup(), do not use "by hand"
srcfuncThe function calling _lstrdup(); filled by macro lstrdup(), do not use "by hand"
sThe string to be duplicated

Here is the call graph for this function:

unsigned int parse_time_to_sec ( char *  str)

Parse a string to seconds.

Parses a string in format hour:min:sec, min:sec or sec to a number of seconds. If str does not match any of the formats shown above INVALID_TIME is returned.

Parameters
strThe string to be parsed
Returns
The corresponding number of seconds or INVALID_TIME in case of invalid format

Here is the caller graph for this function:

char* smprintf ( char *  fmt,
  ... 
)

printf style function with automated allocation of buffer.

Parameters
fmtThe formatstring, as known from printf, see man 3 printf
Returns
Pointer to allocated memory (needs to be free'd) or NULL if malloc failed

Here is the caller graph for this function:

int snprint_ftime ( char *  buffer,
size_t  buffer_size,
int  time_secs 
)

Write a formated version of time_secs to buffer.

If time_secs is above one hour the format "%d:%02d:%02d" is used, otherwise "%02d:%02d" is used.
At most buffer_size bytes are written to buffer. If buffer_size - 1 is returned your output is most likely truncated and thus the used buffer should be resized.

Parameters
bufferThe buffer receiving the formated time.
buffer_sizeThe size of the buffer.
time_secsThe seconds to be formated.
Returns
The number of bytes written to buffer (excluding the terminating '\0')

Here is the caller graph for this function:

void strcrep ( char *  str,
char  s,
char  r 
)

replace a char with another char in a given string

Parameters
strThe string to search in, points to a buffer that will be modified
sThe char to search for
rThe char to replace with

Here is the caller graph for this function:

char* strstrp ( char *  str)

Here is the caller graph for this function:

bool yank ( char *  text)

Yank the provided text.

Parameters
textThe text to yank
Returns
true on success, false otherwise

Here is the caller graph for this function: