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 CLOCKS_PER_SEC constant defined in time.h is 1000. 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 (see the section called Option: Provide real-time clock in Chapter 14).
The FILE type is not implemented as a structure, but rather as a CYG_ADDRESS.
The GNU C compiler will place its own builtin 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 builtins. 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.
The implemented rand() uses a very simple algorithm that may not produce a good enough distribution for scientific applications. A choice of algorithms will be available in a future version of the C library.
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.
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 |
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; } |