git-2.22.0/tempfile.c
/* Make sure errno contains a meaningful value on error */
Make sure errno contains a meaningful value on error
Make sure errno contains a meaningful value on error
struct tempfile *create_tempfile(const char *path)
{
	struct tempfile *tempfile = new_tempfile();
	strbuf_add_absolute_path(&tempfile->filename, path);
	tempfile->fd = open(tempfile->filename.buf,
			    O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0666);
	if (O_CLOEXEC && tempfile->fd < 0 && errno == EINVAL)
		tempfile->fd = open(tempfile->filename.buf,
				    O_RDWR | O_CREAT | O_EXCL, 0666);
	if (tempfile->fd < 0) {
		deactivate_tempfile(tempfile);
		return NULL;
	}
	activate_tempfile(tempfile);
	if (adjust_shared_perm(tempfile->filename.buf)) {
		int save_errno = errno;
		error("cannot fix permission bits on %s", tempfile->filename.buf);
		delete_tempfile(&tempfile);
		errno = save_errno;
		return NULL;
	}
	return tempfile;
}
struct tempfile * create_tempfile ( const char * path ) { struct tempfile * tempfile = new_tempfile ( ) ; strbuf_add_absolute_path ( & tempfile -> filename , path ) ; tempfile -> fd = open ( tempfile -> filename . buf , O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC , 0666 ) ; if ( O_CLOEXEC && tempfile -> fd < 0 && errno == EINVAL ) tempfile -> fd = open ( tempfile -> filename . buf , O_RDWR | O_CREAT | O_EXCL , 0666 ) ; if ( tempfile -> fd < 0 ) { deactivate_tempfile ( tempfile ) ; return NULL ; } activate_tempfile ( tempfile ) ; if ( adjust_shared_perm ( tempfile -> filename . buf ) ) { int save_errno = errno ; error ( " " , tempfile -> filename . buf ) ; delete_tempfile ( & tempfile ) ; errno = save_errno ; return NULL ; } return tempfile ; }
Make sure errno contains a meaningful value on error
Make sure errno contains a meaningful value on error
/* Try again w/o O_CLOEXEC: the kernel might not support it */