FastLED 3.9.15
Loading...
Searching...
No Matches
cstdlib.h
Go to the documentation of this file.
1#pragma once
2
4// FastLED C Standard Library Compatibility Header
5//
6// This header provides a compatibility layer for third-party code that
7// expects standard C library functions like malloc, free, exit, etc.
9
10#include "fl/stl/stdint.h"
11#include "fl/stl/cstddef.h"
12#include "fl/stl/noexcept.h"
13
14namespace fl {
15
16// ============================================================================
17// fl::aligned_alloc / fl::aligned_free — Portable over-aligned allocation
18// ============================================================================
19// Mirrors std::aligned_alloc from <cstdlib> (C++17 / C11).
20// Falls back to plain malloc on platforms where over-alignment is
21// unsupported or unnecessary (AVR, ESP8266).
22// Defined in cstdlib.cpp.hpp.
23
24void *aligned_alloc(fl::size_t alignment, fl::size_t size) FL_NOEXCEPT;
25
26// Portable free for memory obtained from fl::aligned_alloc.
27// On POSIX, std::free suffices; on Windows, _aligned_free is required.
28void aligned_free(void *ptr) FL_NOEXCEPT;
29
30// Convert string to long integer
31// Similar to standard strtol but without locale support
32long strtol(const char* str, char** endptr, int base) FL_NOEXCEPT;
33
34// Convert string to unsigned long integer
35unsigned long strtoul(const char* str, char** endptr, int base) FL_NOEXCEPT;
36
37// Convert string to integer
38int atoi(const char* str) FL_NOEXCEPT;
39
40// Convert string to long
41long atol(const char* str) FL_NOEXCEPT;
42
43// Convert string to double
44double strtod(const char* str, char** endptr) FL_NOEXCEPT;
45
46// C-style comparison function type for qsort
47typedef int (*qsort_compare_fn)(const void*, const void*);
48
49// qsort - Quick sort function compatible with C stdlib qsort
50// Sorts an array of elements using the provided comparison function
51void qsort(void* base, size_t nmemb, size_t size, qsort_compare_fn compar) FL_NOEXCEPT;
52
53// Pseudo-random number generator (mirrors ::rand()).
54// Returns u32 — values are always non-negative [0, RAND_MAX].
55// Fixed-width avoids AVR's 16-bit int truncation.
56u32 rand() FL_NOEXCEPT;
57
58// Get the value of an environment variable
59// Only functional on FASTLED_TESTING (stub platform), returns nullptr otherwise
60// This avoids std:: namespace dependencies on embedded platforms
61const char* getenv(const char* name) FL_NOEXCEPT;
62
63} // namespace fl
__SIZE_TYPE__ size_t
Definition s16x16x4.h:16
void aligned_free(void *ptr)
long atol(const char *str)
const char * getenv(const char *name)
int(* qsort_compare_fn)(const void *, const void *)
Definition cstdlib.h:47
void * aligned_alloc(fl::size_t alignment, fl::size_t size)
void qsort(void *base, size_t nmemb, size_t size, qsort_compare_fn compar)
int atoi(const char *str)
u32 rand()
double strtod(const char *str, char **endptr)
unsigned long strtoul(const char *str, char **endptr, int base)
long strtol(const char *str, char **endptr, int base)
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT