Why not:

```c
nwritten = 0;

if (tap_output)
  nwritten += write(fd, "#", 1);

nwritten += write(fd, buf, strlen(buf));
```