Comtrol eCos User Manual
Page 359

Chapter 13. C and math library overview
•
For faster execution speed you should avoid this option and let the compiler use its built-ins. This can be turned
off by invoking GCC with the -fno-builtin option.
•
memcpy()
and
memset()
are located in the infrastructure package, not in the C library package. This is because
the compiler calls these functions, and the kernel needs to resolve them even if the C library is not configured.
•
Error codes such as EDOM and ERANGE, as well as
strerror()
, are implemented in the error package. The
error package is separate from the rest of the C and math libraries so that the rest of eCos can use these error
handling facilities even if the C library is not configured.
•
When
free()
is
invoked,
heap
memory
will
normally
be
coalesced.
If
the
CYGSEM_KERNEL_MEMORY_COALESCE configuration parameter is not set, memory will not be
coalesced, which might cause programs to fail.
•
Signals, as implemented by
<
signal.h
>
, are guaranteed to work correctly if raised using the
raise()
function
from a normal working program context. Using signals from within an ISR or DSR context is not expected to
work. Also, it is not guaranteed that if CYGSEM_LIBC_SIGNALS_HWEXCEPTIONS is set, that handling a
signal using
signal()
will necessarily catch that form of exception. For example, it may be expected that a
divide-by-zero error would be caught by handling
SIGFPE
. However it depends on the underlying HAL imple-
mentation to implement the required hardware exception. And indeed the hardware itself may not be capable of
detecting these exceptions so it may not be possible for the HAL implementer to do this in any case. Despite this
lack of guarantees in this respect, the signals implementation is still ISO C compliant since ISO C does not offer
any such guarantees either.
•
The
getenv()
function is implemented (unless the CYGPKG_LIBC_ENVIRONMENT configuration option is
turned off), but there is no shell or
putenv()
function to set the environment dynamically. The environment is
set in a global variable environ, declared as:
extern char **environ; // Standard environment definition
The
environment
can
be
statically
initialized
at
startup
time
using
the
CYG-
DAT_LIBC_DEFAULT_ENVIRONMENT option. If so, remember that the final entry of the array initializer
must be NULL.
Here is a minimal eCos program which demonstrates the use of environments (see also the test case in
lan-
guage/c/libc/current/tests/stdlib/getenv.c
):
#include
<
stdio.h
>
#include
<
stdlib.h
>
// Main header for stdlib functions
extern char **environ; // Standard environment definition
int
main( int argc, char *argv[] )
{
char *str;
char *env[] = { "PATH=/usr/local/bin:/usr/bin",
"HOME=/home/fred",
"TEST=1234=5678",
"home=hatstand",
NULL };
printf("Display the current PATH environment variable\n");
255