It's not the logic of hammering my own fingers that is flawed, it is my choice of a hammer!
The 'fixed' code¹ has the property that calling it to create a file with mode==0 (i.e. no permissions) actually creates one with mode==0644 (i.e. some permissions), which is a wtf r u doin that can't be blamed on C.
¹ https://github.com/systemd/systemd/commit/06eeacb6fe029804f2...