Skip to content

OSDEP API

This header provides a comprehensive cross-platform abstraction layer for embedded IoT applications. It defines standard types, platform detection constants, compiler abstractions, and operating system compatibility macros to enable portability across diverse embedded and desktop systems. This is the foundational module consumed by all other EmbedThis modules and must be included first in any source file. The module automatically detects the target platform's CPU architecture, operating system, compiler, and endianness to provide consistent behavior across ARM, x86, MIPS, PowerPC, SPARC, RISC-V, Xtensa, and other architectures running on Linux, macOS, Windows, VxWorks, FreeRTOS, ESP32, and other operating systems.

By including "osdep.h", you will include most common O/S headers and define a set of useful cross-platform constants.

Function Index

Typedef Index

OffsetSigned 64-bit file offset type.
SocketArgument for sockets.
SocklenSize to hold the length of a socket address.
TicksRelative time in milliseconds for durations and intervals.
TimeAbsolute time in milliseconds since Unix epoch.
boolBoolean data type.
ccharConstant character pointer type.
cintConstant int data type.
cucharConstant unsigned character type.
cushortConstant unsigned short data type.
cvoidConstant void data type.
int16Signed 16-bit integer type.
int32Signed 32-bit integer type.
int8Signed 8-bit integer type.
scharSigned 8-bit character type.
size_tUnsigned integral type.
ssizeSigned size type for memory and I/O operations.
time_tUnsigned time type.
ucharUnsigned 8-bit character type.
uintUnsigned integer (machine dependent bit size) data type.
uint16Unsigned 16-bit integer type.
uint32Unsigned 32-bit integer type.
uint8Unsigned 8-bit integer type.
ulongUnsigned long (machine dependent bit size) data type.
ushortUnsigned short data type.
wcharWide character type for ASCII/UTF-8.
wsizeWindows uses uint for write/read counts (Ugh!).

Defines

#defineBITS   ((int) (BITSPERBYTE * (int) sizeof(type)))
 Calculate number of bits in a data type.
#defineBITSPERBYTE   ((int) (8 * sizeof(char)))
 Number of bits per byte.
#defineHAS_BOOL   1
#definemax   (((a) > (b)) ? (a) : (b))
 Return the maximum of two values.
#defineME_64   0
#defineME_BIG_ENDIAN   2
 Big endian byte ordering.
#defineME_BUFSIZE   4096
 Standard buffer size for desktop/server systems.
#defineME_CHAR_LEN   1
 Character length for Unicode support.
#defineME_CPU_ARM   1
 ARM 32-bit architecture (ARMv7 and earlier).
#defineME_CPU_ARM64   2
 ARM 64-bit architecture (ARMv8 and later).
#defineME_CPU_ITANIUM   3
 Intel Itanium (IA-64) architecture.
#defineME_CPU_MIPS   6
 MIPS 32-bit architecture.
#defineME_CPU_MIPS64   7
 MIPS 64-bit architecture.
#defineME_CPU_PPC   8
 PowerPC 32-bit architecture.
#defineME_CPU_PPC64   9
 PowerPC 64-bit architecture.
#defineME_CPU_RISCV   13
 RISC-V 32-bit architecture.
#defineME_CPU_RISCV64   14
 RISC-V 64-bit architecture.
#defineME_CPU_SH   12
 SuperH architecture.
#defineME_CPU_SPARC   10
 SPARC architecture.
#defineME_CPU_TIDSP   11
 Texas Instruments DSP architecture.
#defineME_CPU_UNKNOWN   0
 Unknown or unsupported CPU architecture.
#defineME_CPU_X64   5
 Intel/AMD x86-64 architecture.
#defineME_CPU_X86   4
 Intel x86 32-bit architecture.
#defineME_CPU_XTENSA   15
 Xtensa architecture including ESP32.
#defineME_DEBUG   0
 Default to a debug build.
#defineME_DOUBLE_BUFFER   (DBL_MANT_DIG - DBL_MIN_EXP + 4)
 Buffer size for double-precision floating point string conversion.
#defineME_ENDIAN   CPU_ENDIAN
#defineME_LITTLE_ENDIAN   1
 Little endian byte ordering.
#defineME_MAX_ARGC   32
 Maximum command line arguments for desktop/server systems.
#defineME_MAX_FNAME   256
 Maximum filename length for desktop/server systems.
#defineME_MAX_IP   1024
 Maximum IP address string length for desktop/server systems.
#defineME_MAX_PATH   1024
 Maximum path length for desktop/server systems.
#defineME_STACK_SIZE   (32 * 1024)
 Default thread stack size for systems without virtual memory.
#definemin   (((a) < (b)) ? (a) : (b))
 Return the minimum of two values.
#definePRINTF_ATTRIBUTE   
#defineTPS   1000
 Time/Ticks units per second (milliseconds).
#defineUT   s
 String literal macro for ASCII/UTF-8 (no conversion).

Typedefs

typedef char bool

Boolean data type.

Description:
Provides consistent boolean type across platforms. Uses char underlying type for compatibility with systems lacking native bool support. Should be used with true/false constants.
API Stability:
Stable.

typedef const char cchar

Constant character pointer type.

Description:
Commonly used for read-only string parameters and immutable text data.
API Stability:
Stable.

typedef const int cint

Constant int data type.

API Stability:
Stable.

typedef const unsigned char cuchar

Constant unsigned character type.

Description:
Provides read-only access to unsigned byte data.
API Stability:
Stable.

typedef const unsigned short cushort

Constant unsigned short data type.

API Stability:
Stable.

typedef const void cvoid

Constant void data type.

API Stability:
Stable.

typedef short int16

Signed 16-bit integer type.

Description:
Guaranteed 16-bit signed integer (-32,768 to 32,767) for network protocols and compact data.
API Stability:
Stable.

typedef int int32

Signed 32-bit integer type.

Description:
Guaranteed 32-bit signed integer for general-purpose arithmetic and system values.
API Stability:
Stable.

typedef char int8

Signed 8-bit integer type.

Description:
Guaranteed 8-bit signed integer (-128 to 127) for precise byte-level operations.
API Stability:
Stable.

typedef int64 Offset

Signed 64-bit file offset type.

Description:
Supports large files greater than 4GB in size on all systems. Used for file positioning, seeking, and size calculations. Always 64-bit regardless of platform word size.
API Stability:
Stable.

typedef signed char schar

Signed 8-bit character type.

Description:
Provides explicit signed char semantics when the sign of char values matters.
API Stability:
Stable.

typedef long size_t

Unsigned integral type.

Equivalent in size to void*

typedef int Socket

Argument for sockets.

API Stability:
Stable.

typedef int Socklen

Size to hold the length of a socket address.

API Stability:
Stable.

typedef ssize_t ssize

Signed size type for memory and I/O operations.

Description:
Platform-appropriate signed integer type large enough to hold array indices, memory sizes, and I/O transfer counts. Can represent negative values for error conditions. Equivalent to size_t but signed.
API Stability:
Stable.

typedef int64 Ticks

Relative time in milliseconds for durations and intervals.

Description:
Elapsed time measurement in milliseconds from an arbitrary starting point. Used for timeouts, delays, performance measurements, and relative time calculations.
API Stability:
Stable.

typedef int64 Time

Absolute time in milliseconds since Unix epoch.

Description:
Time value representing milliseconds since January 1, 1970 UTC (Unix epoch). Used for timestamps, timeouts, and absolute time calculations across the system.
API Stability:
Stable.

typedef long time_t

Unsigned time type.

Time in seconds since Jan 1, 1970

typedef unsigned char uchar

Unsigned 8-bit character type.

Description:
Provides explicit unsigned char semantics for byte manipulation and binary data handling.
API Stability:
Stable.

typedef unsigned int uint

Unsigned integer (machine dependent bit size) data type.

API Stability:
Stable.

typedef unsigned short uint16

Unsigned 16-bit integer type.

Description:
Guaranteed 16-bit unsigned integer (0 to 65,535) for ports, packet sizes, and compact counters.
API Stability:
Stable.

typedef unsigned int uint32

Unsigned 32-bit integer type.

Description:
Guaranteed 32-bit unsigned integer for addresses, large counters, and hash values.
API Stability:
Stable.

typedef unsigned char uint8

Unsigned 8-bit integer type.

Description:
Guaranteed 8-bit unsigned integer (0 to 255) for byte manipulation and flags.
API Stability:
Stable.

typedef unsigned long ulong

Unsigned long (machine dependent bit size) data type.

API Stability:
Stable.

typedef unsigned short ushort

Unsigned short data type.

API Stability:
Stable.

typedef char wchar

Wide character type for ASCII/UTF-8.

API Stability:
Stable.

typedef ssize wsize

Windows uses uint for write/read counts (Ugh!).

API Stability:
Stable.

Functions