This unconditional `chmod` call will change the file's permissions to `octdec(NULL) == 0`. You should initialize the `perms` member with something useful, e.g. 644, or 600.