1) No idea I've not had much practice with the functions in the POSIX standard.

2) Don't print the entire buffer? Print until a null terminator.

write(fd,buffer,sizeof(char)*strlen(buffer));