Commit 3ccc1a4d by Carlos Martín Nieto

futils: add a function to truncate a file

We want to do this in order to get FETCH_HEAD to be empty when we start updating
it due to fetching from the remote.
parent c0bfda87
......@@ -102,6 +102,16 @@ int git_futils_open_ro(const char *path)
return fd;
}
int git_futils_truncate(const char *path, int mode)
{
int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode);
if (fd < 0)
return git_path_set_error(errno, path, "open");
close(fd);
return 0;
}
git_off_t git_futils_filesize(git_file fd)
{
struct stat sb;
......
......@@ -248,6 +248,11 @@ extern int git_futils_cp_r(
extern int git_futils_open_ro(const char *path);
/**
* Truncate a file, creating it if it doesn't exist.
*/
extern int git_futils_truncate(const char *path, int mode);
/**
* Get the filesize in bytes of a file
*/
extern git_off_t git_futils_filesize(git_file fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment