Nagios 4.5.4
Dev docs for Nagios core and neb-module hackers
Loading...
Searching...
No Matches
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)
 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.

Macro Definition Documentation

◆ alloc_nr

#define alloc_nr ( x)
Value:
(((x)+16)*3/2)

Macro for dynamically increasing vector lengths.

Function Documentation

◆ mkstr()

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

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]fmtThe format string
Returns
A pointer to the formatted string on success. Undefined on errors

◆ online_cpus()

int online_cpus ( void )
extern

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.

◆ real_online_cpus()

int real_online_cpus ( void )
extern

Get number of online cpus.

Returns
Active cpu cores detected on success. 0 on failure.

◆ tv_delta_f()

float tv_delta_f ( const struct timeval * start,
const struct timeval * stop )
extern

Get timeval delta as seconds.

Parameters
startThe start time
stopThe stop time
Returns
time difference in fractions of seconds

◆ tv_delta_msec()

const char int tv_delta_msec ( const struct timeval * start,
const struct timeval * stop )
extern

Calculate the millisecond delta between two timeval structs.

Parameters
[in]startThe start time
[in]stopThe stop time
Returns
The millisecond delta between the two structs