mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-26 17:44:59 +00:00

This converts blob.c, fileops.c, and all of the win32 files. Also, various minor cleanups throughout the code. Plus, in testing the win32 build, I cleaned up a bunch (although not all) of the warnings with the 64-bit build.
94 lines
1.5 KiB
C
94 lines
1.5 KiB
C
/*
|
|
* Copyright (C) 2009-2012 the libgit2 contributors
|
|
*
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
* a Linking Exception. For full terms see the included COPYING file.
|
|
*/
|
|
#include "common.h"
|
|
#include "posix.h"
|
|
#include "path.h"
|
|
#include <stdio.h>
|
|
#include <ctype.h>
|
|
|
|
#ifndef GIT_WIN32
|
|
|
|
int p_open(const char *path, int flags)
|
|
{
|
|
return open(path, flags | O_BINARY);
|
|
}
|
|
|
|
int p_creat(const char *path, mode_t mode)
|
|
{
|
|
return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
|
|
}
|
|
|
|
int p_getcwd(char *buffer_out, size_t size)
|
|
{
|
|
char *cwd_buffer;
|
|
|
|
assert(buffer_out && size > 0);
|
|
|
|
cwd_buffer = getcwd(buffer_out, size);
|
|
|
|
if (cwd_buffer == NULL)
|
|
return -1;
|
|
|
|
git_path_mkposix(buffer_out);
|
|
git_path_string_to_dir(buffer_out, size); /* append trailing slash */
|
|
|
|
return 0;
|
|
}
|
|
|
|
int p_rename(const char *from, const char *to)
|
|
{
|
|
if (!link(from, to)) {
|
|
p_unlink(from);
|
|
return 0;
|
|
}
|
|
|
|
if (!rename(from, to))
|
|
return 0;
|
|
|
|
return -1;
|
|
}
|
|
|
|
#endif
|
|
|
|
int p_read(git_file fd, void *buf, size_t cnt)
|
|
{
|
|
char *b = buf;
|
|
while (cnt) {
|
|
ssize_t r = read(fd, b, cnt);
|
|
if (r < 0) {
|
|
if (errno == EINTR || errno == EAGAIN)
|
|
continue;
|
|
return -1;
|
|
}
|
|
if (!r)
|
|
break;
|
|
cnt -= r;
|
|
b += r;
|
|
}
|
|
return (int)(b - (char *)buf);
|
|
}
|
|
|
|
int p_write(git_file fd, const void *buf, size_t cnt)
|
|
{
|
|
const char *b = buf;
|
|
while (cnt) {
|
|
ssize_t r = write(fd, b, cnt);
|
|
if (r < 0) {
|
|
if (errno == EINTR || errno == EAGAIN)
|
|
continue;
|
|
return -1;
|
|
}
|
|
if (!r) {
|
|
errno = EPIPE;
|
|
return -1;
|
|
}
|
|
cnt -= r;
|
|
b += r;
|
|
}
|
|
return 0;
|
|
}
|