elemy-utils 1.0.0
Data Structures | Macros | Typedefs | Enumerations | Functions
el_utils.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <byteswap.h>
#include <unistd.h>
#include <time.h>
#include <malloc.h>
#include <linux/limits.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <json-c/json.h>
#include <stdarg.h>
#include <sys/syscall.h>
#include "elutils/pslist.h"
#include "elutils/psl_ndx.h"
#include "elutils/c_decls.h"
Include dependency graph for el_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  _sau_t
 
union  _sau_static_t
 
struct  _conn_param_t
 
struct  statm_t
 

Macros

#define _GNU_SOURCE
 STDERR_FILENO. More...
 
#define NAME_BUF_SZ_MAX   (NAME_MAX + 1)
 < NAME_MAX More...
 
#define UNUSED(x)   (void)(x)
 used for masquarade unuzed variables. in production must no be. More...
 
#define PUT_ERR(ERR, ERRN)   if (ERR) *ERR = ERRN
 used in funcs wich return error codes through parameter variable ptr More...
 
#define ERROR_FD   -1
 for close file More...
 
#define CLOSE_FD(FD)   close(FD); FD = ERROR_FD
 
#define EL_WRONG_PTR   (void*)(0)
 
#define NOERROR   (0)
 
#define ARRAY_SIZE(foo)   (sizeof(foo)/sizeof(foo[0]))
 
#define TENS_KILO   1000LL
 
#define TENS_MEGA   1000000LL
 
#define TENS_GIGA   1000000000LL
 
#define EL_DBG   1
 
#define MB_DBG(fmt, ...)
 
#define MB_DBG_IMM(fmt, ...)
 
#define MB_DUMP_BUF_SZ   120
 
#define MB_DUMP_BUF(DATA_PTR, DATA_SZ, fmt, ...)
 
#define MB_DEBUG(DBG_FLAG, FMT, ...)
 
#define NO_HAVE_STRLCPY
 
#define MALLOC_ARG(ARG_IS, ERR)   if (ARG_IS == NULL) {ARG_IS = malloc(sizeof(*ARG_IS)); if (ARG_IS == NULL) { if (ERR != NULL) { *ERR = errno; } return NULL; } }
 
#define SET_CD(FD, VAL)   set_serial_stat_ln(FD, TIOCM_CD, VAL)
 
#define SET_DTR(FD, VAL)   set_serial_stat_ln(FD, TIOCM_DTR, VAL)
 
#define SET_DSR(FD, VAL)   set_serial_stat_ln(FD, TIOCM_LE, VAL)
 
#define SET_RTS(FD, VAL)   set_serial_stat_ln(FD, TIOCM_RTS, VAL)
 
#define SET_CTS(FD, VAL)   set_serial_stat_ln(FD, TIOCM_CTS, VAL)
 
#define ARGP_KEY_ARG   0
 
#define ARGP_KEY_ARGS   0x1000006
 
#define ARGP_KEY_END   0x1000001
 
#define ARGP_KEY_NO_ARGS   0x1000002
 
#define ARGP_KEY_INIT   0x1000003
 
#define ARGP_KEY_FINI   0x1000007
 
#define ARGP_KEY_SUCCESS   0x1000004
 
#define ARGP_KEY_ERROR   0x1000005
 
#define DATA_STR_SZ   (64)
 
#define ARGP_FIRST_LONG_OPT   (0x100)
 key for first only long option More...
 
#define ARGP_PARAM_NOMEM(PCFG, VAR, MSG)
 
#define COMPARE_MEM_PREPARE(MEMAS)   el_compare_mem_prepare(MEMAS, sizeof(MEMAS))
 
#define COMPARE_MEM_DO(MEMAS, COPY)   el_compare_mem_do(MEMAS, sizeof(*MEMAS), COPY)
 
#define MB_MEMORY_STATUS()
 
#define CHECK_GET_OBJ_STRING(FROM, NAME, OBJ, TARGET, FIELD, EXIT)
 strdup string from json_type_object FROM by name NAME into FIELD of TARGET struct. on error goto EXIT label More...
 
#define CHECK_GET_OBJ_STRING_NULL(FROM, NAME, OBJ, TARGET, FIELD, EXIT)
 strdup string from json_type_object FROM by name NAME into FIELD of TARGET struct. on error goto EXIT label. Absent NAME is NOT ERROR More...
 
#define CHECK_GET_OBJ_INT(FROM, NAME, OBJ, TARGET, FIELD, EXIT)
 
#define BUILD_MSG_WITH_PREV(PREV, SHOW, FORMAT, ...)
 

Typedefs

typedef void(* el_ctrlc_call_t) (void *ar)
 
typedef enum _IP_TYPES_T IP_TYPES_T
 
typedef union _sau_t sau_t
 
typedef union _sau_static_t sau_static_t
 
typedef enum _CONN_ROLE_T CONN_ROLE_T
 configure connection parameters More...
 
typedef enum _CONN_TYPE_T CONN_TYPE_T
 
typedef struct _conn_param_t conn_params_t
 

Enumerations

enum  _IP_TYPES_T { IT_NOT_IP = AF_UNSPEC , IT_IPV4 = AF_INET , IT_IPV6 = AF_INET6 }
 
enum  _CONN_ROLE_T {
  CR_NOTHING = 0 , CR_MASTER , CR_SLAVE , CR_GATE ,
  CR_NODE
}
 configure connection parameters More...
 
enum  _CONN_TYPE_T { CT_TCP = 0 , CT_RTU }
 

Functions

static uint64_t timespec_diff (struct timespec *ts1, struct timespec *ts2)
 
static uint64_t get_time_nano (void)
 
size_t strlcpy (char *dst, const char *src, size_t dstSize)
 
pthread_rwlockattr_t * el_get_rw_shared_attr (void)
 
int set_stdin_nowait_cr (int nowait)
 
void set_restore_stdin_cr (void)
 
void el_set_ctrlc_exit (int ex)
 if parameter != 0 set var to TRUE: on Ctrl-C exit. if == 0 dsont exit. More...
 
void el_set_ctrlc_param (void *arg)
 
void el_set_ctrlc_call (el_ctrlc_call_t arg)
 
void termination_handler (int signum)
 
void termination_sigaction (int signum, siginfo_t *siginfo, void *param)
 
void set_termination_action (void)
 
int get_serial_stat (int fd)
 
void set_serial_stat (int fd, int serial)
 
int get_serial_dtr (int fd)
 
char * get_serial_dtr_s (int fd)
 
int get_serial_dsr (int fd)
 
char * get_serial_dsr_s (int fd)
 
int get_serial_rts (int fd)
 
char * get_serial_rts_s (int fd)
 
int get_serial_cts (int fd)
 
char * get_serial_cts_s (int fd)
 
void show_serial_stat (int fd)
 
void set_serial_stat_ln (int fd, int ln_bt, int val)
 
char ** split_string (char *str, char delem, int *number)
 split string into words by delimeter, heading/trailing WhiteSpaces prohibited, possible empty words s = " ss,bb,cc,zz,,qq\0" ps_split_str(s, ',', 5, &cnt); ->{"ss", "bb", "cc", "zz", "", 0} ",ss," -> {"", "ss", "", 0} More...
 
int cnt_splited_strings (char **ss)
 
void dbg_string_list (char **string_list)
 show NULL terminated list (array) of strings More...
 
char * get_family_name (int family)
 return name of IPvX family More...
 
char * get_sock_type_name (int sock_type)
 
int validate_ip_addr (const char *ip_addr)
 check is string is IPv4 or IPv6 or smth else More...
 
int test_connect (struct addrinfo *ai_ptr, int *err)
 
int test_bind (struct addrinfo *ai_ptr, int *err)
 
void show_sa (struct sockaddr *sa, char *buf, int buf_sz)
 
void show_ai_list (struct addrinfo *ai_list)
 
struct addrinfo * tcp_get_addr_info (char *addr, char *service, int family, int slave, int *err)
 
int max_sockadddr_sz (void)
 
int conn_nonb (int fd, struct sockaddr *sa, int sa_len, uint64_t timeout, int *err)
 
int check_rs_speed (int sp)
 
conn_params_tparse_conn_params (char *params)
 parch string with connection parameters and fill struct conn_param_t More...
 
void free_conn_param (conn_params_t *c_p)
 
int fill_sockaddr_sinx (conn_params_t *c_p, int *err)
 
const char * argp_std_key_name (int par)
 
int wait_read_fd (int fd, uint64_t timeout, int *err)
 wait ready for read More...
 
int wait_write_fd (int fd, uint64_t timeout, int *err)
 
int bytes_of_bits (int bits)
 
char * conn_role_name (int cr)
 
void setnonblocking (int sock)
 
void set_fd_cloexec (int fd)
 
int set_reuseaddr (int fd)
 
char * time64_to_str (uint64_t tm, char *buf)
 
const char * ps_error_text (int error)
 
int press_enter (char *msg, char *cmp_str)
 
int file_check_exist (char *fl_name)
 check file More...
 
int64_t file_fd_size (int fd)
 
int64_t file_size (const char *filename)
 
int parse_array (void *dst, void *src, int cnt, int sz)
 parse array of strings values into array of 'sz' size elements More...
 
int pid_exist (pid_t pid)
 check existance process(thread) with pid More...
 
void * el_compare_mem_prepare (void *mem, int mem_sz)
 
int el_compare_mem_do (void *mem, int mem_sz, void *copy)
 
long ps_pagesize (void)
 
void read_off_memory_status (statm_t *result)
 
uint16_t modbus_crc16 (uint8_t *buffer, uint16_t buffer_length)
 
int ps_put_mem (char *file_name, void *mem_ptr, int mem_sz)
 put memory to file More...
 
char * get_n_bytes (const char *str, int pos, int cnt)
 malloc buf of cnt+1 bytes and cope there bytes from str+pos AS IS More...
 
char * find_free_name_num (char *name)
 
char * mk_indent (int level)
 
void free_array (void **arr, int cnt)
 
char * build_msg_with_prev (const char *prev_msg, const char *format,...)
 

Detailed Description

Include standart uintXX_t Define declaration decorators Decleare time measer define debug messanger and data dumper

Created on: 11 мар. 2023 г. Author: ps

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

STDERR_FILENO.

uint*_t for 'bool' type bswap_16(x);bswap_32(x);bswap_64(x);

◆ ARGP_FIRST_LONG_OPT

#define ARGP_FIRST_LONG_OPT   (0x100)

key for first only long option

For argp

◆ ARGP_KEY_ARG

#define ARGP_KEY_ARG   0

◆ ARGP_KEY_ARGS

#define ARGP_KEY_ARGS   0x1000006

◆ ARGP_KEY_END

#define ARGP_KEY_END   0x1000001

◆ ARGP_KEY_ERROR

#define ARGP_KEY_ERROR   0x1000005

◆ ARGP_KEY_FINI

#define ARGP_KEY_FINI   0x1000007

◆ ARGP_KEY_INIT

#define ARGP_KEY_INIT   0x1000003

◆ ARGP_KEY_NO_ARGS

#define ARGP_KEY_NO_ARGS   0x1000002

◆ ARGP_KEY_SUCCESS

#define ARGP_KEY_SUCCESS   0x1000004

◆ ARGP_PARAM_NOMEM

#define ARGP_PARAM_NOMEM (   PCFG,
  VAR,
  MSG 
)
Value:
do { if (VAR == NULL) { \
MB_DBG(" param error: " MSG); \
PCFG->err = 1; \
return ARGP_ERR_UNKNOWN; \
}} while (0)

for use in parsers. check var (usually arg_val or malloced var) on NULL if NULL - set in PCFG config struct err = 1 and return ARGP_ERR_UKNOWN as dont understand argument

◆ ARRAY_SIZE

#define ARRAY_SIZE (   foo)    (sizeof(foo)/sizeof(foo[0]))

◆ BUILD_MSG_WITH_PREV

#define BUILD_MSG_WITH_PREV (   PREV,
  SHOW,
  FORMAT,
  ... 
)
Value:
do { \
char *t_str = NULL; \
t_str = build_msg_with_prev(PREV, FORMAT, ## __VA_ARGS__); \
if (SHOW) { \
MB_DBG("%s\n", t_str); \
} \
if (PREV) free(PREV); \
if (err_msg) { \
*err_msg = t_str; \
} \
else { \
free(t_str); \
} \
} while (0)
char * build_msg_with_prev(const char *prev_msg, const char *format,...)
Definition: el_utils.c:1956

◆ CHECK_GET_OBJ_INT

#define CHECK_GET_OBJ_INT (   FROM,
  NAME,
  OBJ,
  TARGET,
  FIELD,
  EXIT 
)
Value:
{ \
struct json_object *OBJ; \
if (!json_object_object_get_ex(FROM, NAME, &OBJ)) { \
MB_DBG("Cannot get '%s' object\n", NAME); \
goto EXIT; \
} \
if (json_object_get_type(OBJ) != json_type_int) { \
MB_DBG("Bad type of object '%s': '%s'\n", NAME, json_object_to_json_string(OBJ)); \
goto EXIT; \
} \
TARGET->FIELD = json_object_get_int(OBJ); \
}

◆ CHECK_GET_OBJ_STRING

#define CHECK_GET_OBJ_STRING (   FROM,
  NAME,
  OBJ,
  TARGET,
  FIELD,
  EXIT 
)
Value:
{ \
struct json_object *OBJ; \
if (!json_object_object_get_ex(FROM, NAME, &OBJ)) { \
MB_DBG("Cannot get '%s' object\n", NAME); \
goto EXIT; \
} \
if (json_object_get_type(OBJ) != json_type_string) { \
MB_DBG("Bad type of object '%s': '%s'\n", NAME, json_object_to_json_string(OBJ)); \
goto EXIT; \
} \
TARGET->FIELD = strdup(json_object_get_string(OBJ)); \
if (TARGET->FIELD == NULL) { \
goto EXIT; \
} \
}

strdup string from json_type_object FROM by name NAME into FIELD of TARGET struct. on error goto EXIT label

Parameters
FROMptr to json_type_object
NAMEname of object field
OBJname for temporary json object

◆ CHECK_GET_OBJ_STRING_NULL

#define CHECK_GET_OBJ_STRING_NULL (   FROM,
  NAME,
  OBJ,
  TARGET,
  FIELD,
  EXIT 
)
Value:
{ \
TARGET->FIELD = NULL; \
struct json_object *OBJ; \
if (json_object_object_get_ex(FROM, NAME, &OBJ)) { \
if (json_object_get_type(OBJ) != json_type_string) { \
MB_DBG("Bad type of object '%s': '%s'\n", NAME, json_object_to_json_string(OBJ)); \
goto EXIT; \
} \
const char *t_str = json_object_get_string(OBJ); \
if (t_str == NULL) { \
TARGET->FIELD = NULL; \
} \
else { \
TARGET->FIELD = strdup(t_str); \
if (TARGET->FIELD == NULL) { \
MB_DBG("Can't dup '%s'\n", NAME); \
goto EXIT; \
} \
} \
} \
}

strdup string from json_type_object FROM by name NAME into FIELD of TARGET struct. on error goto EXIT label. Absent NAME is NOT ERROR

Parameters
FROMptr to json_type_object
NAMEname of object field
OBJname for temporary json object

ERROR is if NAME exists, but his type isn't json_type_string or can't dup getted string (string value == NULL isn't error);

◆ CLOSE_FD

#define CLOSE_FD (   FD)    close(FD); FD = ERROR_FD

◆ COMPARE_MEM_DO

#define COMPARE_MEM_DO (   MEMAS,
  COPY 
)    el_compare_mem_do(MEMAS, sizeof(*MEMAS), COPY)

◆ COMPARE_MEM_PREPARE

#define COMPARE_MEM_PREPARE (   MEMAS)    el_compare_mem_prepare(MEMAS, sizeof(MEMAS))

◆ DATA_STR_SZ

#define DATA_STR_SZ   (64)

◆ EL_DBG

#define EL_DBG   1

◆ EL_WRONG_PTR

#define EL_WRONG_PTR   (void*)(0)

◆ ERROR_FD

#define ERROR_FD   -1

for close file

◆ MALLOC_ARG

#define MALLOC_ARG (   ARG_IS,
  ERR 
)    if (ARG_IS == NULL) {ARG_IS = malloc(sizeof(*ARG_IS)); if (ARG_IS == NULL) { if (ERR != NULL) { *ERR = errno; } return NULL; } }

◆ MB_DBG

#define MB_DBG (   fmt,
  ... 
)
Value:
do { \
struct timespec DBG_ts; \
clock_gettime(CLOCK_REALTIME, &DBG_ts); \
struct tm DBG_loc_time; \
\
localtime_r(&DBG_ts.tv_sec, &DBG_loc_time); \
char DBG_dt_str[16]; \
strftime(DBG_dt_str, 16, "%Y%m%d_%H%M%S", &DBG_loc_time); \
dprintf(STDERR_FILENO, "%s.%09lu [%i]%s(%s):%u:\t" fmt, DBG_dt_str, DBG_ts.tv_nsec, gettid(), __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
} while (0)

◆ MB_DBG_IMM

#define MB_DBG_IMM (   fmt,
  ... 
)
Value:
do { \
struct timespec DBG_IMM_ts; \
clock_gettime(CLOCK_REALTIME, &DBG_IMM_ts); \
struct tm DBG_IMM_loc_time; \
\
localtime_r(&DBG_IMM_ts.tv_sec, &DBG_IMM_loc_time); \
char DBG_IMM_dt_str[16]; \
strftime(DBG_IMM_dt_str, 16, "%Y%m%d_%H%M%S", &DBG_IMM_loc_time); \
int DBG_IMM_def_tty = open("/dev/tty", O_RDWR); \
dprintf(DBG_IMM_def_tty, "%s.%09lu [%i]%s(%s):%u:\t" fmt, DBG_IMM_dt_str, DBG_IMM_ts.tv_nsec, gettid(), __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
close(DBG_IMM_def_tty); \
} while (0)

◆ MB_DEBUG

#define MB_DEBUG (   DBG_FLAG,
  FMT,
  ... 
)
Value:
if (DBG_FLAG) { \
MB_DBG(FMT, ## __VA_ARGS__); \
}

◆ MB_DUMP_BUF

#define MB_DUMP_BUF (   DATA_PTR,
  DATA_SZ,
  fmt,
  ... 
)

◆ MB_DUMP_BUF_SZ

#define MB_DUMP_BUF_SZ   120

◆ MB_MEMORY_STATUS

#define MB_MEMORY_STATUS ( )
Value:
do { statm_t stm = { 0 }; read_off_memory_status(&stm); \
MB_DBG("MemStat: virt %lu(%luk), resident %lu(%luk), share %lu(%luk), text %lu(%luk), lib %lu(%luk), data %lu(%luk), dt %lu(%luk)\n", \
stm.size, stm.size/1024, stm.resident, stm.resident/1024, stm.share, stm.share/1024, stm.text, stm.text/1024, \
stm.lib, stm.lib/1024, stm.data, stm.data/1024, stm.dt, stm.dt/1024); \
} while (0)
void read_off_memory_status(statm_t *result)
Definition: el_utils.c:1755
Definition: el_utils.h:424
unsigned long size
Definition: el_utils.h:425
unsigned long dt
Definition: el_utils.h:425
unsigned long resident
Definition: el_utils.h:425
unsigned long lib
Definition: el_utils.h:425
unsigned long share
Definition: el_utils.h:425
unsigned long data
Definition: el_utils.h:425
unsigned long text
Definition: el_utils.h:425

◆ NAME_BUF_SZ_MAX

#define NAME_BUF_SZ_MAX   (NAME_MAX + 1)

< NAME_MAX

prepared for possible using in build for MIPS __BEGIN_DECLS/__END_DECLS define in sys/cdefs.h but on MIPSEL24KC it absent. thats why I remove including it. But put defining here. NAME_MAX (255) + 1 (zero). for allocate buffers for filename (static/dynamic)

◆ NO_HAVE_STRLCPY

#define NO_HAVE_STRLCPY

◆ NOERROR

#define NOERROR   (0)

◆ PUT_ERR

#define PUT_ERR (   ERR,
  ERRN 
)    if (ERR) *ERR = ERRN

used in funcs wich return error codes through parameter variable ptr

◆ SET_CD

#define SET_CD (   FD,
  VAL 
)    set_serial_stat_ln(FD, TIOCM_CD, VAL)

◆ SET_CTS

#define SET_CTS (   FD,
  VAL 
)    set_serial_stat_ln(FD, TIOCM_CTS, VAL)

◆ SET_DSR

#define SET_DSR (   FD,
  VAL 
)    set_serial_stat_ln(FD, TIOCM_LE, VAL)

◆ SET_DTR

#define SET_DTR (   FD,
  VAL 
)    set_serial_stat_ln(FD, TIOCM_DTR, VAL)

◆ SET_RTS

#define SET_RTS (   FD,
  VAL 
)    set_serial_stat_ln(FD, TIOCM_RTS, VAL)

◆ TENS_GIGA

#define TENS_GIGA   1000000000LL

◆ TENS_KILO

#define TENS_KILO   1000LL

◆ TENS_MEGA

#define TENS_MEGA   1000000LL

◆ UNUSED

#define UNUSED (   x)    (void)(x)

used for masquarade unuzed variables. in production must no be.

Typedef Documentation

◆ conn_params_t

typedef struct _conn_param_t conn_params_t

◆ CONN_ROLE_T

typedef enum _CONN_ROLE_T CONN_ROLE_T

configure connection parameters

id,master,tcp.1.2.3.4,1331 id,slave,slave_id,tcp,::1,1331 id,master,rs,/dev/ttyUSB1,57600[,CD,DTR,DSR,CTS,RTS]

◆ CONN_TYPE_T

typedef enum _CONN_TYPE_T CONN_TYPE_T

◆ el_ctrlc_call_t

typedef void(* el_ctrlc_call_t) (void *ar)

◆ IP_TYPES_T

typedef enum _IP_TYPES_T IP_TYPES_T

◆ sau_static_t

typedef union _sau_static_t sau_static_t

◆ sau_t

typedef union _sau_t sau_t

Enumeration Type Documentation

◆ _CONN_ROLE_T

configure connection parameters

id,master,tcp.1.2.3.4,1331 id,slave,slave_id,tcp,::1,1331 id,master,rs,/dev/ttyUSB1,57600[,CD,DTR,DSR,CTS,RTS]

Enumerator
CR_NOTHING 
CR_MASTER 
CR_SLAVE 
CR_GATE 
CR_NODE 

◆ _CONN_TYPE_T

Enumerator
CT_TCP 
CT_RTU 

◆ _IP_TYPES_T

Enumerator
IT_NOT_IP 
IT_IPV4 
IT_IPV6 

Function Documentation

◆ argp_std_key_name()

const char * argp_std_key_name ( int  par)

◆ build_msg_with_prev()

char * build_msg_with_prev ( const char *  prev_msg,
const char *  format,
  ... 
)

◆ bytes_of_bits()

int bytes_of_bits ( int  bits)

◆ check_rs_speed()

int check_rs_speed ( int  sp)

check speed in available

Parameters
sptesting speed
Returns
-1 if wrong speed else speed.

◆ cnt_splited_strings()

int cnt_splited_strings ( char **  ss)

◆ conn_nonb()

int conn_nonb ( int  fd,
struct sockaddr *  sa,
int  sa_len,
uint64_t  timeout,
int *  err 
)
Here is the caller graph for this function:

◆ conn_role_name()

char * conn_role_name ( int  cr)

◆ dbg_string_list()

void dbg_string_list ( char **  string_list)

show NULL terminated list (array) of strings

◆ el_compare_mem_do()

int el_compare_mem_do ( void *  mem,
int  mem_sz,
void *  copy 
)

◆ el_compare_mem_prepare()

void * el_compare_mem_prepare ( void *  mem,
int  mem_sz 
)

funcs detect side effect after activity

used to detect side effect after any activity with memoty block. Using: at first copy memory into malloced block. then do smth. at end compare to blocks.

pthread_rwlockattr_t *ppp = el_get_rw_shared_attr();
void *zzz = COMPARE_MEM_PREPARE(ppp);
pthread_rwlock_init(&main_shmem->shm_rwl, ppp)
COMPARE_MEM_DO(ppp, zzz);
pthread_rwlockattr_t * el_get_rw_shared_attr(void)
Definition: el_utils.c:63
#define COMPARE_MEM_PREPARE(MEMAS)
Definition: el_utils.h:418
#define COMPARE_MEM_DO(MEMAS, COPY)
Definition: el_utils.h:419

first ''el_compare_mem_prepare'' return malloced block or NULL on error (ENOMEM) second ''el_compare_mem_do'' compare blocks end return 1 if differ, 0 if not or prepare bad (really impossible).

◆ el_get_rw_shared_attr()

pthread_rwlockattr_t * el_get_rw_shared_attr ( void  )

◆ el_set_ctrlc_call()

void el_set_ctrlc_call ( el_ctrlc_call_t  arg)

◆ el_set_ctrlc_exit()

void el_set_ctrlc_exit ( int  ex)

if parameter != 0 set var to TRUE: on Ctrl-C exit. if == 0 dsont exit.

◆ el_set_ctrlc_param()

void el_set_ctrlc_param ( void *  arg)

◆ file_check_exist()

int file_check_exist ( char *  fl_name)

check file

Parameters
fl_namefile name
Returns
1 - exist 0 - not exist (ENOENT) removed -1 - error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_fd_size()

int64_t file_fd_size ( int  fd)
Returns
file size from descriptor or -1 on error
Here is the call graph for this function:

◆ file_size()

int64_t file_size ( const char *  filename)

◆ fill_sockaddr_sinx()

int fill_sockaddr_sinx ( conn_params_t c_p,
int *  err 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_free_name_num()

char * find_free_name_num ( char *  name)

\grief search fist free name for mask <name>_NNNN

Parameters
namemasndastory part of file name
Returns
ptr to malloced free file name

on parameter give file name like "[[/]path_to_file/]this_is_filer_name" return first (no more then 999) free file name like "this_is_filer_name_25"

Here is the call graph for this function:

◆ free_array()

void free_array ( void **  arr,
int  cnt 
)

◆ free_conn_param()

void free_conn_param ( conn_params_t c_p)
Here is the caller graph for this function:

◆ get_family_name()

char * get_family_name ( int  family)

return name of IPvX family

Parameters
familyas in socket(), getaddrinfo()
Here is the caller graph for this function:

◆ get_n_bytes()

char * get_n_bytes ( const char *  str,
int  pos,
int  cnt 
)

malloc buf of cnt+1 bytes and cope there bytes from str+pos AS IS

Parameters
strstring for work
posstart of substring
cntnumber of bytes to copy return ptr to created buffer with substring else NULL on error

return string MUST BE FREED

◆ get_serial_cts()

int get_serial_cts ( int  fd)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_serial_cts_s()

char * get_serial_cts_s ( int  fd)
Here is the call graph for this function:

◆ get_serial_dsr()

int get_serial_dsr ( int  fd)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_serial_dsr_s()

char * get_serial_dsr_s ( int  fd)
Here is the call graph for this function:

◆ get_serial_dtr()

int get_serial_dtr ( int  fd)

get fd return 0/1 status of signal/line dtr,rts,cts...

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_serial_dtr_s()

char * get_serial_dtr_s ( int  fd)
Here is the call graph for this function:

◆ get_serial_rts()

int get_serial_rts ( int  fd)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_serial_rts_s()

char * get_serial_rts_s ( int  fd)
Here is the call graph for this function:

◆ get_serial_stat()

int get_serial_stat ( int  fd)
Here is the caller graph for this function:

◆ get_sock_type_name()

char * get_sock_type_name ( int  sock_type)
Here is the caller graph for this function:

◆ get_time_nano()

static uint64_t get_time_nano ( void  )
inlinestatic

◆ max_sockadddr_sz()

int max_sockadddr_sz ( void  )
Returns
max size of sockaddr

◆ mk_indent()

char * mk_indent ( int  level)

◆ modbus_crc16()

uint16_t modbus_crc16 ( uint8_t *  buffer,
uint16_t  buffer_length 
)

◆ parse_array()

int parse_array ( void *  dst,
void *  src,
int  cnt,
int  sz 
)

parse array of strings values into array of 'sz' size elements

◆ parse_conn_params()

conn_params_t * parse_conn_params ( char *  params)

parch string with connection parameters and fill struct conn_param_t

configure connection parameters id,slave,slave_id,tcp,pes70.ru,1331 id,master,tcp,1.2.3.4,1331 id,slave,slave_id,tcp,::1,1331 id,master,rs,/dev/ttyUSB1,57600[,CD,DTR,DSR,CTS,RTS]

Returns
ptr to allocated parameters. or NULL in error (ENOMEM or bardak in params)
Here is the call graph for this function:

◆ pid_exist()

int pid_exist ( pid_t  pid)

check existance process(thread) with pid

Parameters
pidprocess/thread ID as getpid/gettid
Returns
1 - exist, 0 - absent,
Here is the call graph for this function:

◆ press_enter()

int press_enter ( char *  msg,
char *  cmp_str 
)

◆ ps_error_text()

const char * ps_error_text ( int  error)
Here is the caller graph for this function:

◆ ps_pagesize()

long ps_pagesize ( void  )
Here is the caller graph for this function:

◆ ps_put_mem()

int ps_put_mem ( char *  file_name,
void *  mem_ptr,
int  mem_sz 
)

put memory to file

Parameters
f_nptr to file name
memptr to memory area
mem_szarea size return 0 success -1 error

◆ read_off_memory_status()

void read_off_memory_status ( statm_t result)
Here is the call graph for this function:

◆ set_fd_cloexec()

void set_fd_cloexec ( int  fd)

◆ set_restore_stdin_cr()

void set_restore_stdin_cr ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_reuseaddr()

int set_reuseaddr ( int  fd)

◆ set_serial_stat()

void set_serial_stat ( int  fd,
int  serial 
)

◆ set_serial_stat_ln()

void set_serial_stat_ln ( int  fd,
int  ln_bt,
int  val 
)

◆ set_stdin_nowait_cr()

int set_stdin_nowait_cr ( int  nowait)

toggle wariants IF nowait THEN toggled disable wait cr ELSE restore original settings

IF nowait THEN disable wait 'CR' ELSE restore old settings

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_termination_action()

void set_termination_action ( void  )
Here is the call graph for this function:

◆ setnonblocking()

void setnonblocking ( int  sock)

◆ show_ai_list()

void show_ai_list ( struct addrinfo *  ai_list)
Here is the call graph for this function:

◆ show_sa()

void show_sa ( struct sockaddr *  sa,
char *  buf,
int  buf_sz 
)
Parameters
saptr to sockaddr
bufmust be enough for addr:port for IPv4/IPv6
buf_szsize of buf

◆ show_serial_stat()

void show_serial_stat ( int  fd)
Here is the call graph for this function:

◆ split_string()

char ** split_string ( char *  str,
char  delim,
int *  number 
)

split string into words by delimeter, heading/trailing WhiteSpaces prohibited, possible empty words s = " ss,bb,cc,zz,,qq\0" ps_split_str(s, ',', 5, &cnt); ->{"ss", "bb", "cc", "zz", "", 0} ",ss," -> {"", "ss", "", 0}

Returns
ptr to slovar, NULL on error. Malloced place for array for ALL fields. Return pts (and change string) no more then *number fields if *number != 0. SLOVAR )-TERMINALTED ARRAY OG STREING PTRS

function change str caller MUST free return ptr

Here is the caller graph for this function:

◆ strlcpy()

size_t strlcpy ( char *  dst,
const char *  src,
size_t  dstSize 
)

◆ tcp_get_addr_info()

struct addrinfo * tcp_get_addr_info ( char *  addr,
char *  service,
int  family,
int  slave,
int *  err 
)

as default use port 502

Here is the caller graph for this function:

◆ termination_handler()

void termination_handler ( int  signum)
Here is the call graph for this function:

◆ termination_sigaction()

void termination_sigaction ( int  signum,
siginfo_t *  siginfo,
void *  param 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_bind()

int test_bind ( struct addrinfo *  ai_ptr,
int *  err 
)
Here is the caller graph for this function:

◆ test_connect()

int test_connect ( struct addrinfo *  ai_ptr,
int *  err 
)
Returns
-1 error, system error in *err ; error from socket and connect 0 all right
Here is the call graph for this function:
Here is the caller graph for this function:

◆ time64_to_str()

char * time64_to_str ( uint64_t  tm,
char *  buf 
)

convert uint64_t timestump to time string

Parameters
tmIN - timestump in nanosec
bufIN - buffer for date string, If NULL - malloc it
Returns
ptr to buf

◆ timespec_diff()

static uint64_t timespec_diff ( struct timespec *  ts1,
struct timespec *  ts2 
)
inlinestatic

◆ validate_ip_addr()

int validate_ip_addr ( const char *  ip_addr)

check is string is IPv4 or IPv6 or smth else

Get string with IP address

Returns
IT_NOT_IP, IT_IPV4, IT_IPV6

◆ wait_read_fd()

int wait_read_fd ( int  fd,
uint64_t  timeout,
int *  err 
)

wait ready for read

Returns
-1: error (*err - errorcode), 0 - timeout, 1 - ready this fd

◆ wait_write_fd()

int wait_write_fd ( int  fd,
uint64_t  timeout,
int *  err 
)