tags:

views:

342

answers:

5

I've been tasked with adding streams support (C89/C90) to the libraries for my company's legacy embedded C compiler. Our target hardware typically has 1MB or less of code space and does not have an operating system.

We have a lot of stream-like implementations throughout the codebase that I can use as a starting point. For example, a console that works over a TCP sockets or serial port, a web server that reads from FAT on SD card or in-memory file, and even a firmware updater that reads from many sources.

Before I go and re-invent the wheel, I'm wondering if there are existing implementations that I could either port or use as a starting point for my work. Even though we provide full source code to our customers, GPL-licensed code isn't an option since our customers don't want to release source code to their products.

Can anyone recommend a book (annotated Unix source, CompSci text) or public domain/BSD-licensed source? I'd prefer to look at an older OS targeted to a single device, as current operating systems contain a tangle of macros and layers of typedefs that make following even a simple struct definition difficult.

+1  A: 

Try looking at http://www.minix3.org/

Ofir
+5  A: 

Take a look at P.J. Plauger's book The Standard C Library, which describes in detail one possible implementation of the complete C89 standard library.

anon
Exactly what I'm looking for -- I'll be ordering it before the end of the day. Thanks!
tomlogic
A very good book, but note that the library source published in the book isn't freely distributable. Strictly speaking, you'd have to reimplement the lib yourself (not a huge job, but depending how strict your company is about IP, might require some hoops to be jumped through). Note that Plauger sells the library and sells it with redistrbution rights. MSVC's library and the IAR library I'm currently using are both originally licensed from Plaugher's Dinkumware, and I'm sure several other compiler vendors do the same. I have no idea what the cost would be if you wanted to go that route.
Michael Burr
A quick followup -- I got the book, and it has been a great reference. Just having the commentary on the stdlib excerpts of the C90 document has been handy. I was able to document a plan for updating our existing library to C90 compliance, and have been working on a design to fully support streams. Thanks for the tip, Neil.
tomlogic
+2  A: 

Wouldn't *BSD (Net|Open|Free)'s libc be suitable? At least as a starting point.

mctylr
+3  A: 

You should be able to pull most of what you need from the source code for the GNU C standard library. It is licensed with the Lesser GPL, which means you can link to the library without affecting the license of your software (or forcing your customers to release their code). Porting this to your platform (thus keeping the LGPL-ed code in its own library) may be easier than implementing your own from scratch.

Several different projects have taken GNU GLIBC and optimized it for embedded systems. You may want to look at:

In particular, EGLIBC and uLIBC were designed to run properly on embedded systems that lack a MMU.

You can also have a look at BSD's implementation of libc

Alternatively there is STLSoft, who provides several libraries (including the C standard lib) under a BSD license. I can't attest to their quality since I haven't used their code myself, but it might be worth looking at if you can't work LGPL-ed code into your project.

bta
As a correction: Newlib isn't based on GNU GLIBC; it's its own thing. Also, most of it's BSD-licensed or equivalent, aside from some of the Linux-specific pieces and a few other things.In any case, it's not a bad place to start.
Brooks Moses
@Brooks Moses: Thank you for the clarification
bta
A: 

Check your development tools. Some development tools come with their on source for their software libraries.

I took the source for the Compiler's printf and adapted for a debug port on an embedded system. There is less work when you have a foundation to build from.

Thomas Matthews
That's what I'm doing -- adding source to the software libraries for the development tool that we sell.
tomlogic