copy of buffer.c