Added read functions to encodings.c, and fixed a race condition.