nsutils.h File Reference

Non-Standard (or Nagios) utility functions and macros. More...

#include <sys/types.h>
#include <sys/time.h>

Go to the source code of this file.



#define alloc_nr(x)   (((x)+16)*3/2)
 Macro for dynamically increasing vector lengths.
int real_online_cpus (void)
 Get number of online cpus.
int online_cpus (void)
 Wrapper for real_online_cpus(), returning 1 in case we can't detect any active cpus.
const char * mkstr (const char *fmt,...) __attribute__((__format__(__printf__
 Create a short-lived string in stack-allocated memory The number and size of strings is limited (currently to 256 strings of 32 bytes each), so beware and use this sensibly.
const char int tv_delta_msec (const struct timeval *start, const struct timeval *stop)
 Calculate the millisecond delta between two timeval structs.
float tv_delta_f (const struct timeval *start, const struct timeval *stop)
 Get timeval delta as seconds.

Detailed Description

Non-Standard (or Nagios) utility functions and macros.

This is where we house all helpers and macros that fall outside the "standard-ish" norm. The prefixes "nsu_" and NSU_ are reserved for this purpose, so we avoid clashing with other applications that may have similarly-acting functions with identical names.

The functions already here lack the nsu_ prefix for backwards compatibility reasons. It's possible we'll have to fix that some day, but let's leave that for later.


Function Documentation

const char* mkstr ( const char *  fmt,
  ... 
)

Create a short-lived string in stack-allocated memory The number and size of strings is limited (currently to 256 strings of 32 bytes each), so beware and use this sensibly.

Intended for number-to-string conversion and other short strings.

Note:
The returned string must *not* be free()'d!
Parameters:
[in] fmt The format string
Returns:
A pointer to the formatted string on success. Undefined on errors
int online_cpus ( void   ) 

Wrapper for real_online_cpus(), returning 1 in case we can't detect any active cpus.

Returns:
Number of active cpu cores on success. 1 on failure.
int real_online_cpus ( void   ) 

Get number of online cpus.

Returns:
Active cpu cores detected on success. 0 on failure.
float tv_delta_f ( const struct timeval *  start,
const struct timeval *  stop 
)

Get timeval delta as seconds.

Parameters:
start The start time
stop The stop time
Returns:
time difference in fractions of seconds
const char int tv_delta_msec ( const struct timeval *  start,
const struct timeval *  stop 
)

Calculate the millisecond delta between two timeval structs.

Parameters:
[in] start The start time
[in] stop The stop time
Returns:
The millisecond delta between the two structs
 All Data Structures Files Functions Variables Typedefs Defines

Generated on 17 Jan 2019 for Nagios by  doxygen 1.6.1