le_basics.h File Reference
Go to the source code of this file.
Macros | |
#define | EXIT_UNAVAILABLE 69 |
#define | CONTAINER_OF(memberPtr, type, member) ((type*)(((uint8_t*)(memberPtr))-((size_t)(&(((type*)0)->member))))) |
#define | NUM_ARRAY_MEMBERS(array) (sizeof(array) / sizeof((array)[0])) |
#define | INDEX_OF_ARRAY_MEMBER(array, memberPtr) ((((size_t)memberPtr) - ((size_t)array)) / sizeof(*(memberPtr))) |
#define | STRINGIZE(x) STRINGIZE_EXPAND(x) |
#define | STRINGIZE_EXPAND(x) #x |
#define | CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__) |
#define | PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__ |
#define | SECOND(a, b, ...) b |
#define | LE_DEFAULT(...) SECOND(__VA_ARGS__) |
#define | LE_SHARED __attribute__((visibility ("default"))) |
#define | LE_DECLARE_INLINE inline |
#define | LE_DEFINE_INLINE extern inline |
#define | __is_identifier(x) 1 |
#define | __has_warning(x) 0 |
#define | __has_attribute(x) 0 |
#define | LE_NONNULL |
#define | LE_NULLABLE |
#define | LE_UNUSED(v) ((void) (v)) |
#define | __PRIS_PREFIX "z" |
#define | PRIdS __PRIS_PREFIX "d" |
#define | PRIxS __PRIS_PREFIX "x" |
#define | PRIuS __PRIS_PREFIX "u" |
#define | PRIXS __PRIS_PREFIX "X" |
#define | PRIoS __PRIS_PREFIX "o" |
#define | static_assert(cond, msg) ((void)sizeof(char[1 - 2*!(cond)])) |
#define | inline_static_assert(cond, msg) ((void)(0)) |
#define | LE_CONFIG_IS_ENABLED(option) (("" STRINGIZE(option))[0] == '1') |
Bit Masks | |
Single byte bit definitions that can be used for bit masking. | |
#define | BIT0 0x01 |
#define | BIT1 0x02 |
#define | BIT2 0x04 |
#define | BIT3 0x08 |
#define | BIT4 0x10 |
#define | BIT5 0x20 |
#define | BIT6 0x40 |
#define | BIT7 0x80 |
Enumerations | |
enum | le_result_t { LE_OK = 0, LE_NOT_FOUND = -1, LE_NOT_POSSIBLE = -2, LE_OUT_OF_RANGE = -3, LE_NO_MEMORY = -4, LE_NOT_PERMITTED = -5, LE_FAULT = -6, LE_COMM_ERROR = -7, LE_TIMEOUT = -8, LE_OVERFLOW = -9, LE_UNDERFLOW = -10, LE_WOULD_BLOCK = -11, LE_DEADLOCK = -12, LE_FORMAT_ERROR = -13, LE_DUPLICATE = -14, LE_BAD_PARAMETER = -15, LE_CLOSED = -16, LE_BUSY = -17, LE_UNSUPPORTED = -18, LE_IO_ERROR = -19, LE_NOT_IMPLEMENTED = -20, LE_UNAVAILABLE = -21, LE_TERMINATED = -22, LE_IN_PROGRESS = -23, LE_SUSPENDED = -24 } |
enum | le_onoff_t { LE_OFF = 0, LE_ON = 1 } |
Detailed Description
Legato Basic Type and Constant Definitions include file.
Copyright (C) Sierra Wireless Inc.
Macro Definition Documentation
◆ __PRIS_PREFIX
#define __PRIS_PREFIX "z" |
Format specifiers for size_t
◆ CAT
#define CAT | ( | a, | |
... | |||
) | PRIMITIVE_CAT(a, __VA_ARGS__) |
Macro to help concatenate preprocessor tokens while first allowing macro expansion of those tokens.
Original source: https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms
◆ CONTAINER_OF
#define CONTAINER_OF | ( | memberPtr, | |
type, | |||
member | |||
) | ((type*)(((uint8_t*)(memberPtr))-((size_t)(&(((type*)0)->member))))) |
Find the address of a containing structure or union, based on the address of one of its members.
If countPtr
points to the count
member of an object type my_class_t
, then a pointer to that object should use this:
my_class_t* myObjPtr = CONTAINER_OF(countPtr, my_class_t, count);
◆ EXIT_UNAVAILABLE
#define EXIT_UNAVAILABLE 69 |
Standard exit codes.
- Note
- The value follow standardize exit codes of BSD(Berkeley software distribution), detail in file <sysexits.h>.
Present exit status of process that is stopped by loss of a service or resource.
◆ INDEX_OF_ARRAY_MEMBER
#define INDEX_OF_ARRAY_MEMBER | ( | array, | |
memberPtr | |||
) | ((((size_t)memberPtr) - ((size_t)array)) / sizeof(*(memberPtr))) |
Computes the index of a member within an array.
This code sample prints out "The 'w' is at index 6.":
const char message[] = "Hello world!";const char* charPtr;int i;for (i = 0; i < sizeof(message); i++){if (message[i] == 'w'){charPtr = &message[i];}}printf("The 'w' is at index %zu.\n", INDEX_OF_ARRAY_MEMBER(message, charPtr));
◆ LE_CONFIG_IS_ENABLED
#define LE_CONFIG_IS_ENABLED | ( | option | ) | (("" STRINGIZE(option))[0] == '1') |
Test if a KConfig feature is enabled.
◆ LE_DECLARE_INLINE
#define LE_DECLARE_INLINE inline |
LE_DECLARE_INLINE
Declare an inline function in a header.
GNU by default uses a non-standard method of declaring inline functions with the exact opposite meaning of the C99 standard.
So use LE_DECLARE_INLINE with the function body in a header. Then use LE_DEFINE_INLINE with just the function prototype in a .c file to tell the compiler to emit the function definition for cases where the function is not inlined.
This is preferred over using "static inline" since if a static inline function is not inlined by gcc, there may be multiple copies of the function included in the output. LE_DEFINE_INLINE
Cause a function definition to be emitted for an inline function, in case the compiler decides not to use the inline definition.
- See also
LE_DECLARE_INLINE
◆ LE_DEFAULT
#define LE_DEFAULT | ( | ... | ) | SECOND(__VA_ARGS__) |
If the macro passed as the first parameter is defined in the form ,
(note the leading comma) this evaluates to
. If the macro is not defined in this format (or not defined at all, this evaluates to the second, default parameter.
◆ LE_SHARED
#define LE_SHARED __attribute__((visibility ("default"))) |
Macro used to declare that a symbol should be shared outside the dynamic shared object in which it is defined.
This can be used with either a declaration or a definition.
E.g., with a declaration (perhaps in a header file):
LE_SHARED void my_Function();
E.g., with a definition (in a .c file):
LE_SHARED void my_OtherFunction(){LE_INFO("Hello world.");}
◆ LE_UNUSED
#define LE_UNUSED | ( | v | ) | ((void) (v)) |
Mark a variable as unused.
- Parameters
-
v Variable to mark as unused.
◆ NUM_ARRAY_MEMBERS
#define NUM_ARRAY_MEMBERS | ( | array | ) | (sizeof(array) / sizeof((array)[0])) |
Computes number of members in an array at compile time.
- Warning
- Does NOT work for pointers to arrays.
Here's a code sample:
const char message[] = "Hello world!";size_t x = NUM_ARRAY_MEMBERS(message);printf("%lu\n", x);
Will print 13
on a 32-bit target.
But this example is incorrect:
const char message[] = "Hello world!";const char* messagePtr = &message;printf("%lu\n", x);
◆ PRIMITIVE_CAT
#define PRIMITIVE_CAT | ( | a, | |
... | |||
) | a ## __VA_ARGS__ |
Helper macro for STRINGIZE(x).
◆ SECOND
#define SECOND | ( | a, | |
b, | |||
... | |||
) | b |
Helper macro for SECOND(...). Always select the second parameter.
◆ static_assert
#define static_assert | ( | cond, | |
msg | |||
) | ((void)sizeof(char[1 - 2*!(cond)])) |
Provide static_assert if not available.
◆ STRINGIZE
#define STRINGIZE | ( | x | ) | STRINGIZE_EXPAND(x) |
This function takes the characters as an argument and puts quotes around them.
Code sample:
Is seen by the compiler as
const char name[] = "foo";
The STRINGIZE() macro function passes names like macro definitions on the compiler's command-line. If the above code were changed to:
then compiling it using the following command line makes it equivalent to the example above:
$ gcc -c -DNAME=foo file.c
The -DNAME=foo
defines a macro called NAME
with a value foo
. The C preprocessor then replaces STRINGIZE(NAME)
with "foo"
.
◆ STRINGIZE_EXPAND
#define STRINGIZE_EXPAND | ( | x | ) | #x |
Helper macro for STRINGIZE(x).
Enumeration Type Documentation
◆ le_onoff_t
enum le_onoff_t |
ON/OFF type.
◆ le_result_t
enum le_result_t |
If the compiler is armcc, allow anonymous unions, as these are useful and used quite a bit in Legato Standard result codes.
- Note
- All error codes are negative integers. They allow functions with signed integers to return non-negative values when successful or standard error codes on failure.
- Deprecated:
- the result code LE_NOT_POSSIBLE has been removed and replaced other error codes that are more clear.
Enumerator | |
---|---|
LE_OK | Successful. |
LE_NOT_FOUND | Referenced item does not exist or could not be found. |
LE_NOT_POSSIBLE |
|
LE_OUT_OF_RANGE | An index or other value is out of range. |
LE_NO_MEMORY | Insufficient memory is available. |
LE_NOT_PERMITTED | Current user does not have permission to perform requested action. |
LE_FAULT | Unspecified internal error. |
LE_COMM_ERROR | Communications error. |
LE_TIMEOUT | A time-out occurred. |
LE_OVERFLOW | An overflow occurred or would have occurred. |
LE_UNDERFLOW | An underflow occurred or would have occurred. |
LE_WOULD_BLOCK | Would have blocked if non-blocking behaviour was not requested. |
LE_DEADLOCK | Would have caused a deadlock. |
LE_FORMAT_ERROR | Format error. |
LE_DUPLICATE | Duplicate entry found or operation already performed. |
LE_BAD_PARAMETER | Parameter is invalid. |
LE_CLOSED | The resource is closed. |
LE_BUSY | The resource is busy. |
LE_UNSUPPORTED | The underlying resource does not support this operation. |
LE_IO_ERROR | An IO operation failed. |
LE_NOT_IMPLEMENTED | Unimplemented functionality. |
LE_UNAVAILABLE | A transient or temporary loss of a service or resource. |
LE_TERMINATED | The process, operation, data stream, session, etc. has stopped. |
LE_IN_PROGRESS | The operation is in progress. |
LE_SUSPENDED | The operation is suspended. |