Here are some details about the implementation which might be interesting, although they do not affect the ISO-defined semantics of the library.
It is possible to configure eCos to have the standard C library without the kernel. You might want to do this to use less memory. But if you disable the kernel, you will be unable to use memory allocation, thread-safety and certain stdio functions such as input. Other C library functionality is unaffected.
The opaque type returned by
clock()
is called clock_t, and is implemented as a 64 bit integer.
The value returned by
clock()
is only correct if the kernel is configured with real-time clock
support, as determined by the CYGVAR_KERNEL_COUNTERS_CLOCK
configuration option in
kernel.h
.
The FILE type is not implemented as a structure, but rather as a CYG_ADDRESS.
The GNU C compiler will place its own built-in implementations
instead of some C library functions. This can be turned off with
the -fno-builtin option. The functions affected
by this are
abs()
,
cos()
,
fabs()
,
labs()
,
memcmp()
,
memcpy()
,
sin()
,
sqrt()
,
strcmp()
,
strcpy()
, and
strlen()
.
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 implementation 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 CYGDAT_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 language/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"); environ = (char **)&env; str = getenv("PATH"); if (str==NULL) { printf("The current PATH is unset\n"); } else { printf("The current PATH is \"%s\"\n", str); } return 0; } |