libmsngr  1.1
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups
Utility Functions

Functions

char * msngr_copy_string (const char *string)
 Create a dynamically allocated copy of a string.
char * msngr_create_string (const char *format,...)
 Create a new text string.
char * msngr_format_time (time_t secs1970, char *string)
 Convert seconds since 1970 to a formatted time string.
char * msngr_format_va_list (const char *format, va_list args)
 Create a text string from a format string and va_list.
time_t msngr_get_process_start_time (pid_t pid)
 Get the start time of a process.
int msngr_make_path (const char *path, mode_t mode, size_t errlen, char *errstr)
 Make the full path to a directory.
int msngr_vprintf (const char *format, va_list args)
 Wrapper to vprintf that preserves the argument list.
int msngr_vfprintf (FILE *stream, const char *format, va_list args)
 Wrapper to vfprintf that preserves the argument list.
int msngr_vsprintf (char *string, const char *format, va_list args)
 Wrapper to vsprintf that preserves the argument list.
int msngr_vsnprintf (char *string, size_t nbytes, const char *format, va_list args)
 Wrapper to vsnprintf that preserves the argument list.

Detailed Description


Function Documentation

char* msngr_copy_string ( const char *  string)

Create a dynamically allocated copy of a string.

The memory used by the returned string is dynamically allocated. It is the responsibility of the calling process to free this memory when it is no longer needed.

Parameters:
string- pointer to the string to copy
Returns:
  • pointer to the dynamically allocated copy of the string
  • NULL if a memory allocation error occurred

Definition at line 65 of file msngr_utils.c.

char* msngr_create_string ( const char *  format,
  ... 
)

Create a new text string.

This functions creates a new text string under the control of the format argument.

The memory used by the returned string is dynamically allocated. It is the responsibility of the calling process to free this memory when it is no longer needed.

Parameters:
format- format string (see printf)
...- arguments for the format string
Returns:
  • pointer to the dynamically allocated text string
  • NULL if a memory allocation error occurred

Definition at line 94 of file msngr_utils.c.

char* msngr_format_time ( time_t  secs1970,
char *  string 
)

Convert seconds since 1970 to a formatted time string.

This function will create a time string of the form:

'YYYY-MM-DD hh:mm:ss'.

The string argument must be large enough to hold at least 20 characters (19 plus the null terminator).

If an error occurs in this function, the message 'FORMATTING ERROR' will be copied into the text string.

Parameters:
secs1970- seconds since 1970
string- time string to store the result in
Returns:
pointer to the string argument

Definition at line 124 of file msngr_utils.c.

char* msngr_format_va_list ( const char *  format,
va_list  args 
)

Create a text string from a format string and va_list.

The memory used by the returned string is dynamically allocated. It is the responsibility of the calling process to free this memory when it is no longer needed.

Parameters:
format- format string (see printf)
args- arguments for the format string
Returns:
  • pointer to the dynamically allocated text string
  • NULL if a memory allocation error occurred

Definition at line 161 of file msngr_utils.c.

time_t msngr_get_process_start_time ( pid_t  pid)

Get the start time of a process.

Parameters:
pid- process ID
Returns:
  • process start time in seconds since 1970
  • 0 if the process does not exist

Definition at line 193 of file msngr_utils.c.

int msngr_make_path ( const char *  path,
mode_t  mode,
size_t  errlen,
char *  errstr 
)

Make the full path to a directory.

This function will create the specified path if it does not already exist.

The space pointed to by errstr should be large enough to hold MAX_LOG_ERROR bytes. Any less than that and the error message could be truncated.

If errlen is 0 then no error message is written to errstr and errstr can be NULL.

Parameters:
path- directory path to create
mode- mode of the new directory
errlen- length of the error message buffer
errstr- output: error message
Returns:
  • 1 if the path exists or was created
  • 0 if an error occurred

Definition at line 229 of file msngr_utils.c.

int msngr_vfprintf ( FILE *  stream,
const char *  format,
va_list  args 
)

Wrapper to vfprintf that preserves the argument list.

Parameters:
stream- pointer to the output stream
format- format string
args- arguments for the format string
Returns:
the number of bytes written to the output stream

Definition at line 314 of file msngr_utils.c.

int msngr_vprintf ( const char *  format,
va_list  args 
)

Wrapper to vprintf that preserves the argument list.

Parameters:
format- format string
args- arguments for the format string
Returns:
the number of bytes written to stdout

Definition at line 293 of file msngr_utils.c.

int msngr_vsnprintf ( char *  string,
size_t  nbytes,
const char *  format,
va_list  args 
)

Wrapper to vsnprintf that preserves the argument list.

Parameters:
string- output string
nbytes- the length of the output string
format- format string
args- arguments for the format string
Returns:
the number of bytes that would have been written to the output string if its length had been sufficiently large (excluding the terminating null byte.)

Definition at line 360 of file msngr_utils.c.

int msngr_vsprintf ( char *  string,
const char *  format,
va_list  args 
)

Wrapper to vsprintf that preserves the argument list.

Parameters:
string- output string
format- format string
args- arguments for the format string
Returns:
the number of bytes written to the output string (excluding the terminating null byte)

Definition at line 336 of file msngr_utils.c.