| 1 |
$Id$ |
|---|
| 2 |
|
|---|
| 3 |
PDCLib - Public Domain C Library |
|---|
| 4 |
================================ |
|---|
| 5 |
|
|---|
| 6 |
License |
|---|
| 7 |
------- |
|---|
| 8 |
|
|---|
| 9 |
Permission is granted to use, modify, and / or redistribute at will. |
|---|
| 10 |
|
|---|
| 11 |
This includes removing authorship notices, re-use of code parts in |
|---|
| 12 |
other software (with or without giving credit), and / or creating a |
|---|
| 13 |
commercial product based on it. |
|---|
| 14 |
|
|---|
| 15 |
This permission is not revocable by the author. |
|---|
| 16 |
|
|---|
| 17 |
This software is provided as-is. Use it at your own risk. There is |
|---|
| 18 |
no warranty whatsoever, neither expressed nor implied, and by using |
|---|
| 19 |
this software you accept that the author(s) shall not be held liable |
|---|
| 20 |
for any loss of data, loss of service, or other damages, be they |
|---|
| 21 |
incidental or consequential. Your only option other than accepting |
|---|
| 22 |
this is not to use the software at all. |
|---|
| 23 |
|
|---|
| 24 |
A case for Public Domain |
|---|
| 25 |
------------------------ |
|---|
| 26 |
|
|---|
| 27 |
There was a time when you could just post a piece of code to usenet |
|---|
| 28 |
and say, "I give it away for free; perhaps it's useful for you." |
|---|
| 29 |
|
|---|
| 30 |
Then came the lawyers. |
|---|
| 31 |
|
|---|
| 32 |
There are building blocks in software engineering that are so basic |
|---|
| 33 |
that everyone should have free access to them without having to |
|---|
| 34 |
employ a complete legal department for advice. They should be FREE. |
|---|
| 35 |
Available for free, free of licensing implications, free of attached |
|---|
| 36 |
propaganda, free of everything but their useful self. |
|---|
| 37 |
|
|---|
| 38 |
Today, even the term "free" has to be defined by several paragraphs |
|---|
| 39 |
of legal blah-blah. |
|---|
| 40 |
|
|---|
| 41 |
Sick and tired of it, the author brought you this piece of software |
|---|
| 42 |
under a "license" that should not be neccessary in the first place: |
|---|
| 43 |
"Free" should have been enough. |
|---|
| 44 |
|
|---|
| 45 |
Unfortunately, German law does not even *allow* to declare a work to |
|---|
| 46 |
be "in the Public Domain", so the "free for all" license I intended |
|---|
| 47 |
had to be made expressively. |
|---|
| 48 |
|
|---|
| 49 |
What is it |
|---|
| 50 |
---------- |
|---|
| 51 |
|
|---|
| 52 |
This is a C Standard Library. Nothing more, nothing less. No POSIX |
|---|
| 53 |
or other extensions, just what's defined in ISO/IEC 9899. |
|---|
| 54 |
|
|---|
| 55 |
(Well, this is what it will be when the 1.0 release comes out. See |
|---|
| 56 |
the "Development Status" section to see what's implemented so far.) |
|---|
| 57 |
|
|---|
| 58 |
Internals |
|---|
| 59 |
--------- |
|---|
| 60 |
|
|---|
| 61 |
As a namespace convention, everything (files, typedefs, functions, |
|---|
| 62 |
macros) not defined in ISO/IEC 9899 is prefixed with _PDCLIB. |
|---|
| 63 |
The standard defines any identifiers starting with '_' and a capital |
|---|
| 64 |
letter as reserved for the implementation, and since the chances of |
|---|
| 65 |
your compiler using an identifier in the _PDCLIB range are slim, |
|---|
| 66 |
any strictly conforming application should work with this library. |
|---|
| 67 |
|
|---|
| 68 |
PDCLib consists of several parts: |
|---|
| 69 |
|
|---|
| 70 |
1) standard headers; |
|---|
| 71 |
2) implementation files for standard functions; |
|---|
| 72 |
3) internal header files keeping complex stuff out of the standard |
|---|
| 73 |
headers; |
|---|
| 74 |
4) the central, platform-specific file _PDCLIB_config.h; |
|---|
| 75 |
5) platform-specific implementation files; |
|---|
| 76 |
6) platform-specific, optimized "overlay" implementations (optional). |
|---|
| 77 |
|
|---|
| 78 |
The standard headers (in ./includes/) only contain what they are |
|---|
| 79 |
defined to contain. Where additional logic or macro magic is |
|---|
| 80 |
necessary, that is deferred to the internal files. This has been done |
|---|
| 81 |
so that the headers are actually educational as to what they provide |
|---|
| 82 |
(as opposed to how the library does it). |
|---|
| 83 |
|
|---|
| 84 |
Note that there *might* be some feature to remove this additional |
|---|
| 85 |
level of indirection for a production release, to ease the workload |
|---|
| 86 |
put on the preprocessor. |
|---|
| 87 |
|
|---|
| 88 |
There is a seperate implementation file (in ./function/{header}/) for |
|---|
| 89 |
every function defined by the standard, named {function}.c. Not only |
|---|
| 90 |
does this avoid linking in huge amounts of unused code when you use |
|---|
| 91 |
but a single function, it also allows the optimization overlay to work |
|---|
| 92 |
(see below). |
|---|
| 93 |
|
|---|
| 94 |
(The directory ./functions/_PDCLIB/ contains internal and helper |
|---|
| 95 |
functions that are not part of the standard.) |
|---|
| 96 |
|
|---|
| 97 |
Then there are internal header files (in ./internal/), which contain |
|---|
| 98 |
all the "black magic" and "code fu" that was kept out of the standard |
|---|
| 99 |
headers. You should not have to touch them if you want to adapt PDCLib |
|---|
| 100 |
to a new platform. Note that, if you *do* have to touch them, I would |
|---|
| 101 |
consider it a serious design flaw, and would be happy to fix it in the |
|---|
| 102 |
next PDCLib release. Any adaption work should be covered by the steps |
|---|
| 103 |
detailed below. |
|---|
| 104 |
|
|---|
| 105 |
For adapting PDCLib to a new platform (the trinity of CPU, operating |
|---|
| 106 |
system, and compiler), make a copy of ./platform/example/ named |
|---|
| 107 |
./platform/{your_platform}/, and modify the files of your copy to suit |
|---|
| 108 |
the constraints of your platform. When you are done, copy the contents |
|---|
| 109 |
of your platform directory over the source directory structure |
|---|
| 110 |
of PDCLib (or link them into the appropriate places). That should be |
|---|
| 111 |
all that is actually required to make PDCLib work for your platform. |
|---|
| 112 |
|
|---|
| 113 |
Of course, your platform might provide more efficient replacements |
|---|
| 114 |
for the generic implementations offered by PDCLib. The math functions |
|---|
| 115 |
are an especially "juicy" target for optimization - while PDCLib does |
|---|
| 116 |
provide generic implementations for each of them, there are usually |
|---|
| 117 |
FPU opcodes that do the same job, only orders of magnitude faster. For |
|---|
| 118 |
this, you might want to create an "optimization overlay" for PDCLib. |
|---|
| 119 |
|
|---|
| 120 |
Optimization Overlay |
|---|
| 121 |
-------------------- |
|---|
| 122 |
|
|---|
| 123 |
The basic idea of PDCLib is to provide a generic implementation that |
|---|
| 124 |
is useable even on platforms I have never heard of - for example, the |
|---|
| 125 |
OS and/or compiler *you* just wrote and now need a C library for. That |
|---|
| 126 |
is actually what PDCLib was written for: To provide a C library for |
|---|
| 127 |
compiler and OS builders that do not want the usual baggage of POSIX |
|---|
| 128 |
and GNU extensions, licensing considerations etc. etc. |
|---|
| 129 |
|
|---|
| 130 |
Thus, PDCLib provides generic implementations. They do work, and do |
|---|
| 131 |
so correctly, but they are not very efficient when compared to hand- |
|---|
| 132 |
crafted assembler or compiler build-ins. So I wanted to provide a |
|---|
| 133 |
means to modify PDCLib to run more efficiently on a given platform, |
|---|
| 134 |
without cluttering the main branch with tons of #ifdef statements and |
|---|
| 135 |
"featureset #defines" that grow stale quickly. |
|---|
| 136 |
|
|---|
| 137 |
The solution is the "optimization overlay". Every function has its |
|---|
| 138 |
own implementation file, which makes it possible to replace them |
|---|
| 139 |
piecemeal by copying a platform-specific overlay over the main PDCLib |
|---|
| 140 |
branch to create a PDCLib adapted / optimized for the platform in |
|---|
| 141 |
question. That overlay could be part of the PDCLib source tree (for |
|---|
| 142 |
established platforms where maintainers won't bother with PDCLib), or |
|---|
| 143 |
part of that platform's source tree (for under-development platforms |
|---|
| 144 |
PDCLib maintainers won't bother with). |
|---|
| 145 |
|
|---|
| 146 |
So, to use PDCLib on your given platform, you unpack PDCLib (as you |
|---|
| 147 |
obviously have done already since you are reading this), and copy |
|---|
| 148 |
the overlay for your platform over the PDCLib source tree structure. |
|---|
| 149 |
|
|---|
| 150 |
Development Status |
|---|
| 151 |
------------------ |
|---|
| 152 |
|
|---|
| 153 |
v0.1 - 2004-12-12 |
|---|
| 154 |
Freestanding-only C99 implementation without any overlay, and missing |
|---|
| 155 |
the INTN_C() / UINTN_C() macros. <float.h> still has the enquire.c |
|---|
| 156 |
values hardcoded into it; not sure whether to include enquire.c in the |
|---|
| 157 |
package, to leave <float.h> to the overlay, or devise some parameterized |
|---|
| 158 |
macro magic as for <limits.h> / <stdint.h>. Not thoroughly tested, but |
|---|
| 159 |
I had to make the 0.1 release sometime so why not now. |
|---|
| 160 |
|
|---|
| 161 |
v0.2 - 2005-01-12 |
|---|
| 162 |
Adds implementations for <string.h> (excluding strerror()), INTN_C() / |
|---|
| 163 |
UINTN_C() macros, and some improvements in the internal headers. |
|---|
| 164 |
Test drivers still missing, but added warnings about that. |
|---|
| 165 |
|
|---|
| 166 |
v0.3 - 2005-11-21 |
|---|
| 167 |
Adds test drivers, fixes some bugs in <string.h>. |
|---|
| 168 |
|
|---|
| 169 |
v0.4 - 2005-02-06 |
|---|
| 170 |
Implementations for parts of <stdlib.h>. Still missing are the floating |
|---|
| 171 |
point conversions, and the wide-/multibyte-character functions. |
|---|
| 172 |
|
|---|
| 173 |
v0.4.1 - 2006-11-16 |
|---|
| 174 |
With v0.5 (<stdio.h>) taking longer than expected, v0.4.1 was set up as |
|---|
| 175 |
a backport of bugfixes in the current development code. |
|---|
| 176 |
- #1 realloc( NULL, size ) fails (fixed) |
|---|
| 177 |
- #2 stdlib.h - insufficient documentation (fixed) |
|---|
| 178 |
- #4 Misspelled name in credits (fixed) |
|---|
| 179 |
- #5 malloc() splits off too-small nodes (fixed) |
|---|
| 180 |
- #6 qsort() stack overflow (fixed) |
|---|
| 181 |
- #7 malloc() bug in list handling (fixed) |
|---|
| 182 |
- #8 strncmp() does not terminate at '\0' (fixed) |
|---|
| 183 |
- #9 stdint.h dysfunctional (fixed) |
|---|
| 184 |
- #10 NULL redefinition warnings (fixed) |
|---|
| 185 |
|
|---|
| 186 |
v0.5 - unreleased |
|---|
| 187 |
Implementations for <inttypes.h>, <errno.h>, most parts of <stdio.h>, |
|---|
| 188 |
and strerror() from <string.h>. |
|---|
| 189 |
Still no locale / wide-char support. Enabled all GCC compiler warnings I |
|---|
| 190 |
could find, and fixed everything that threw a warning. (You see this, |
|---|
| 191 |
maintainers of Open Source software? No warnings whatsoever. Stop telling |
|---|
| 192 |
me it cannot be done.) Fixed all known bugs in the v0.4 release. |
|---|
| 193 |
|
|---|