MegaWiFi 1.5
MegaWiFi API documentation
util.h File Reference

General purpose utilities. More...

#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Macros

#define TRUE   1
 TRUE value for boolean comparisons. More...
 
#define FALSE   0
 TRUE value for boolean comparisons. More...
 
#define NULL   ((void*)0)
 NULL Pointer. More...
 
#define _STR(item)   #item
 Helper for STR macro, to ensure item is expanded. More...
 
#define STR(item)   _STR(item)
 Converts a statically defined item to string. More...
 
#define IN_RANGE(num, lower, upper)    (((number) >= (lower)) && ((number) <= (upper)))
 Returns TRUE if number is in the specified range. More...
 
#define container_of(ptr, type, member)
 The infamous container_of() macro directly the Linux kernel. More...
 
#define PACKED   __attribute__((__packed__))
 Macro for packing structures and enumerates. More...
 
#define SECTION(name)   __attribute__((section(#name)))
 
#define ROM_TEXT(name)   SECTION(.text.ro_text.name)
 Put next symbol in named section .text.ro_text.symbol. More...
 
#define ROM_DATA(name)   SECTION(.text.ro_data.name)
 Put next symbol in named section .text.ro_data.symbol. More...
 
#define ARRAY_ROWS(array_2d)   (sizeof(array_2d) / sizeof(array_2d[0]) / sizeof(array_2d[0][0]))
 Get number of rows of a 2D array. More...
 
#define ARRAY_COLS(array_2d)   (sizeof(array_2d[0]) / sizeof(array_2d[0][0]))
 Get number of columns of a 2D array. More...
 
#define UNUSED_PARAM(x)   (void)x
 Remove compiler warnings when not using a function parameter. More...
 
#define MAX(a, b)   ((a)>(b)?(a):(b))
 Returns the maximum of two numbers. More...
 
#define MIN(a, b)   ((a)<(b)?(a):(b))
 Returns the minimum of two numbers. More...
 
#define ByteSwapWord(w)   (uint16_t)((((uint16_t)(w))>>8) | (((uint16_t)(w))<<8))
 Swaps bytes from a word (16 bit) More...
 
#define ByteSwapDWord(dw)
 Swaps bytes from a dword (32 bits) More...
 

Functions

static void to_upper (char *str)
 Converts input string to uppercase. More...
 
const char * str_is_uint8 (const char *str)
 Evaluates if a string points to a number that can be stored in a uint8_t type variable. More...
 
int ip_validate (const char *str)
 This function evaluates the data entered on the input Menu structure, to guess if it corresponds to a valid IPv4. More...
 
int uint32_to_ip_str (uint32_t ip_u32, char *ip_str)
 Writes the corresponding string representing an IPv4 stored in the input DWORD (32-bit) integer. More...
 
uint32_t ip_str_to_uint32 (const char *ip)
 Returns the binary IP addres (uint32) corresponding to the input string. More...
 
uint16_t uint8_to_str (uint8_t num, char *str)
 Converts an unsigned 8-bit number to its character string representation. More...
 
int8_t int8_to_str (int8_t num, char *str)
 Converts an signed 8-bit number to its character string representation. More...
 
uint8_t uint16_to_str (uint16_t num, char *str)
 Converts an unsigned 16-bit number to its character string representation. More...
 
uint8_t int16_to_str (int16_t num, char *str)
 Converts an signed 16-bit number to its character string representation. More...
 
const char * str_to_uint8 (const char *strIn, uint8_t *result)
 Converts a character string representing an 8-bit unsigned number, to its binary (uint8_t) representation. More...
 
int long_to_str (long num, char *str, int buf_len, int pad_len, char pad_chr)
 Converts an integer to a character string. More...
 
void uint8_to_hex_str (uint8_t num, char *str)
 Converts a 8-bit number to its hexadecimal string representation. More...
 
int uint32_to_hex_str (uint32_t num, char *str, int pad)
 Converts a 32-bit number to its hexadecimal string representation. More...
 
int version_to_str (const uint8_t version[3], char *str)
 Converts version numbers (major, minor, micro) into its string representation [major].[minor].[micro]. More...
 
int version_cmp (const uint8_t old[3], const uint8_t cur[3])
 Compares two version number arrays (major, minor, micro). More...
 
uint16_t concat_strings (const char **str, uint8_t num_strs, char *output, uint16_t max_len)
 Concatenates an array of strings into an output string, separated by a '\0' character. More...
 
uint16_t concat_kv_pairs (const char **key, const char **value, uint8_t num_pairs, char *output, uint16_t max_len)
 Concatenates two arrays of key/value pairs, into an output string, separating each key and value with a '\0' character. More...
 

Detailed Description

General purpose utilities.

Definition in file util.h.