fileops.c 622 Bytes
Newer Older
1 2
#define GIT__WIN32_NO_HIDE_FILEOPS
#include "fileops.h"
3
#include <errno.h>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

int git__unlink(const char *path)
{
	chmod(path, 0666);
	return unlink(path);
}

int git__mkstemp(char *template)
{
	char *file = mktemp(template);
	if (file == NULL)
		return -1;
	return open(file, O_RDWR | O_CREAT | O_BINARY, 0600);
}

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
int git__fsync(int fd)
{
	HANDLE fh = (HANDLE)_get_osfhandle(fd);

	if (fh == INVALID_HANDLE_VALUE) {
		errno = EBADF;
		return -1;
	}

	if (!FlushFileBuffers(fh)) {
		DWORD code = GetLastError();

		if (code == ERROR_INVALID_HANDLE)
			errno = EINVAL;
		else
			errno = EIO;

		return -1;
	}

	return 0;
}