Add 'mode' parameter when using 'O_CREAT'. Thanks to Evgeniy for pointing this out.