int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode) { int fd; mode_t mask; p_umask(mask = p_umask(0)); git_buf_sets(path_out, filename); git_buf_puts(path_out, "_git2_XXXXXX"); if (git_buf_oom(path_out)) return -1; if ((fd = p_mkstemp(path_out->ptr)) < 0) { giterr_set(GITERR_OS, "Failed to create temporary file '%s'", path_out->ptr); return -1; } if (p_chmod(path_out->ptr, (mode & ~mask))) { giterr_set(GITERR_OS, "Failed to set permissions on file '%s'", path_out->ptr); return -1; } return fd; }
int git_futils_mktmp(char *path_out, const char *filename) { int fd; strcpy(path_out, filename); strcat(path_out, "_git2_XXXXXX"); if ((fd = p_mkstemp(path_out)) < 0) return git__throw(GIT_EOSERR, "Failed to create temporary file %s", path_out); return fd; }
int git_futils_mktmp(git_buf *path_out, const char *filename) { int fd; git_buf_sets(path_out, filename); git_buf_puts(path_out, "_git2_XXXXXX"); if (git_buf_oom(path_out)) return -1; if ((fd = p_mkstemp(path_out->ptr)) < 0) { giterr_set(GITERR_OS, "Failed to create temporary file '%s'", path_out->ptr); return -1; } return fd; }
/* Check if the platform is decomposing unicode data for us. We will * emulate core Git and prefer to use precomposed unicode data internally * on these platforms, composing the decomposed unicode on the fly. * * This mainly happens on the Mac where HDFS stores filenames as * decomposed unicode. Even on VFAT and SAMBA file systems, the Mac will * return decomposed unicode from readdir() even when the actual * filesystem is storing precomposed unicode. */ bool git_path_does_fs_decompose_unicode(const char *root) { git_buf path = GIT_BUF_INIT; int fd; bool found_decomposed = false; char tmp[6]; /* Create a file using a precomposed path and then try to find it * using the decomposed name. If the lookup fails, then we will mark * that we should precompose unicode for this repository. */ if (git_buf_joinpath(&path, root, nfc_file) < 0 || (fd = p_mkstemp(path.ptr)) < 0) goto done; p_close(fd); /* record trailing digits generated by mkstemp */ memcpy(tmp, path.ptr + path.size - sizeof(tmp), sizeof(tmp)); /* try to look up as NFD path */ if (git_buf_joinpath(&path, root, nfd_file) < 0) goto done; memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp)); found_decomposed = git_path_exists(path.ptr); /* remove temporary file (using original precomposed path) */ if (git_buf_joinpath(&path, root, nfc_file) < 0) goto done; memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp)); (void)p_unlink(path.ptr); done: git_buf_free(&path); return found_decomposed; }