Add gitignore
build fix
return total bytes written
Fix getopt() GNUism

getopt() with "-" is GNUism, not portable.