Just curious, why do you want to write a 'lightweight' library ?
The standard, well tested ones, seem to work well enough.