Make sure errno contains a meaningful value on error */
| 135 | |
| 136 | /* Make sure errno contains a meaningful value on error */ |
| 137 | struct tempfile *create_tempfile_mode(const char *path, int mode) |
| 138 | { |
| 139 | struct tempfile *tempfile = new_tempfile(); |
| 140 | |
| 141 | strbuf_add_absolute_path(&tempfile->filename, path); |
| 142 | tempfile->fd = open(tempfile->filename.buf, |
| 143 | O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, mode); |
| 144 | if (O_CLOEXEC && tempfile->fd < 0 && errno == EINVAL) |
| 145 | /* Try again w/o O_CLOEXEC: the kernel might not support it */ |
| 146 | tempfile->fd = open(tempfile->filename.buf, |
| 147 | O_RDWR | O_CREAT | O_EXCL, mode); |
| 148 | if (tempfile->fd < 0) { |
| 149 | deactivate_tempfile(tempfile); |
| 150 | return NULL; |
| 151 | } |
| 152 | activate_tempfile(tempfile); |
| 153 | if (adjust_shared_perm(the_repository, tempfile->filename.buf)) { |
| 154 | int save_errno = errno; |
| 155 | error("cannot fix permission bits on %s", tempfile->filename.buf); |
| 156 | delete_tempfile(&tempfile); |
| 157 | errno = save_errno; |
| 158 | return NULL; |
| 159 | } |
| 160 | |
| 161 | return tempfile; |
| 162 | } |
| 163 | |
| 164 | struct tempfile *register_tempfile(const char *path) |
| 165 | { |
no test coverage detected