Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/posix.c')
-rw-r--r--src/posix.c55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/posix.c b/src/posix.c
index 916aad726..a9a6af984 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2011 the libgit2 contributors
+ * 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.
@@ -12,9 +12,20 @@
#ifndef GIT_WIN32
-int p_open(const char *path, int flags)
+int p_open(const char *path, int flags, ...)
{
- return open(path, flags | O_BINARY);
+ mode_t mode = 0;
+
+ if (flags & O_CREAT)
+ {
+ va_list arg_list;
+
+ va_start(arg_list, flags);
+ mode = (mode_t)va_arg(arg_list, int);
+ va_end(arg_list);
+ }
+
+ return open(path, flags | O_BINARY, mode);
}
int p_creat(const char *path, mode_t mode)
@@ -31,27 +42,25 @@ int p_getcwd(char *buffer_out, size_t size)
cwd_buffer = getcwd(buffer_out, size);
if (cwd_buffer == NULL)
- return git__throw(GIT_EOSERR, "Failed to retrieve current working directory");
+ return -1;
git_path_mkposix(buffer_out);
+ git_path_string_to_dir(buffer_out, size); /* append trailing slash */
- git_path_string_to_dir(buffer_out, size); //Ensure the path ends with a trailing slash
-
- return GIT_SUCCESS;
+ return 0;
}
int p_rename(const char *from, const char *to)
{
if (!link(from, to)) {
p_unlink(from);
- return GIT_SUCCESS;
+ return 0;
}
if (!rename(from, to))
- return GIT_SUCCESS;
-
- return GIT_ERROR;
+ return 0;
+ return -1;
}
#endif
@@ -60,11 +69,17 @@ int p_read(git_file fd, void *buf, size_t cnt)
{
char *b = buf;
while (cnt) {
- ssize_t r = read(fd, b, cnt);
+ ssize_t r;
+#ifdef GIT_WIN32
+ assert((size_t)((unsigned int)cnt) == cnt);
+ r = read(fd, b, (unsigned int)cnt);
+#else
+ r = read(fd, b, cnt);
+#endif
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
- return GIT_EOSERR;
+ return -1;
}
if (!r)
break;
@@ -78,18 +93,24 @@ 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);
+ ssize_t r;
+#ifdef GIT_WIN32
+ assert((size_t)((unsigned int)cnt) == cnt);
+ r = write(fd, b, (unsigned int)cnt);
+#else
+ r = write(fd, b, cnt);
+#endif
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
- return GIT_EOSERR;
+ return -1;
}
if (!r) {
errno = EPIPE;
- return GIT_EOSERR;
+ return -1;
}
cnt -= r;
b += r;
}
- return GIT_SUCCESS;
+ return 0;
}