Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 96 lines (78 sloc) 1.72 kB
bb742ed @vmg Cleanup legal data
vmg authored
1 /*
5e0de32 @schu Update Copyright header
schu authored
2 * Copyright (C) 2009-2012 the libgit2 contributors
bb742ed @vmg Cleanup legal data
vmg authored
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
f79026b @vmg fileops: Cleanup
vmg authored
7 #include "common.h"
8 #include "posix.h"
9 #include "path.h"
10 #include <stdio.h>
11 #include <ctype.h>
12
7998ae5 @paulcbetts Rewrite p_* functions to use Unicode and marshal to UTF8 internally
paulcbetts authored
13 #ifndef GIT_WIN32
14
f79026b @vmg fileops: Cleanup
vmg authored
15 int p_open(const char *path, int flags)
16 {
17 return open(path, flags | O_BINARY);
18 }
19
3312704 @brodie fileops/posix: replace usage of "int mode" with "mode_t mode"
brodie authored
20 int p_creat(const char *path, mode_t mode)
f79026b @vmg fileops: Cleanup
vmg authored
21 {
22 return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
23 }
24
7998ae5 @paulcbetts Rewrite p_* functions to use Unicode and marshal to UTF8 internally
paulcbetts authored
25 int p_getcwd(char *buffer_out, size_t size)
26 {
27 char *cwd_buffer;
28
29 assert(buffer_out && size > 0);
30
31 cwd_buffer = getcwd(buffer_out, size);
32
33 if (cwd_buffer == NULL)
34 return git__throw(GIT_EOSERR, "Failed to retrieve current working directory");
35
36 git_path_mkposix(buffer_out);
37
9776928 @arrbee Use git_buf for path storage instead of stack-based buffers
arrbee authored
38 git_path_string_to_dir(buffer_out, size); //Ensure the path ends with a trailing slash
39
7998ae5 @paulcbetts Rewrite p_* functions to use Unicode and marshal to UTF8 internally
paulcbetts authored
40 return GIT_SUCCESS;
41 }
42
0c49ec2 @carlosmn Implement p_rename
carlosmn authored
43 int p_rename(const char *from, const char *to)
44 {
45 if (!link(from, to)) {
46 p_unlink(from);
47 return GIT_SUCCESS;
48 }
49
50 if (!rename(from, to))
51 return GIT_SUCCESS;
52
53 return GIT_ERROR;
54
55 }
56
7998ae5 @paulcbetts Rewrite p_* functions to use Unicode and marshal to UTF8 internally
paulcbetts authored
57 #endif
58
f79026b @vmg fileops: Cleanup
vmg authored
59 int p_read(git_file fd, void *buf, size_t cnt)
60 {
61 char *b = buf;
62 while (cnt) {
63 ssize_t r = read(fd, b, cnt);
64 if (r < 0) {
65 if (errno == EINTR || errno == EAGAIN)
66 continue;
67 return GIT_EOSERR;
68 }
69 if (!r)
70 break;
71 cnt -= r;
72 b += r;
73 }
74 return (int)(b - (char *)buf);
75 }
76
2ba222c @kiryl posix: declare 'buf' argument of p_write() as const
kiryl authored
77 int p_write(git_file fd, const void *buf, size_t cnt)
f79026b @vmg fileops: Cleanup
vmg authored
78 {
2ba222c @kiryl posix: declare 'buf' argument of p_write() as const
kiryl authored
79 const char *b = buf;
f79026b @vmg fileops: Cleanup
vmg authored
80 while (cnt) {
81 ssize_t r = write(fd, b, cnt);
82 if (r < 0) {
83 if (errno == EINTR || errno == EAGAIN)
84 continue;
85 return GIT_EOSERR;
86 }
87 if (!r) {
88 errno = EPIPE;
89 return GIT_EOSERR;
90 }
91 cnt -= r;
92 b += r;
93 }
94 return GIT_SUCCESS;
95 }
Something went wrong with that request. Please try again.