add memhd.c
move struct buf to buf.h
move buffer flags to buf.h
lots of changes to buffer