Skip to content

Instantly share code, notes, and snippets.

@arrbee
Created March 22, 2012 20:36
Show Gist options
  • Save arrbee/2163858 to your computer and use it in GitHub Desktop.
Save arrbee/2163858 to your computer and use it in GitHub Desktop.
Alternative rewrite for test_helpers.c:copy_file
int copy_file(const char *src, const char *dst)
{
git_buf source_buf = GIT_BUF_INIT;
git_file dst_fd;
int error = GIT_ERROR;
if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS)
return GIT_ENOTFOUND;
dst_fd = git_futils_creat_withpath(dst, 0777, 0666);
if (dst_fd < 0)
error = dst_fd;
else
error = p_write(dst_fd, source_buf.ptr, source_buf.size);
git_buf_free(&source_buf);
if (dst_fd >= 0)
p_close(dst_fd);
return error;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment