]>
Commit | Line | Data |
---|---|---|
16a67770 SP |
1 | /* |
2 | * This file is free software; you can redistribute it and/or modify | |
3 | * it under the terms of the GNU General Public License, version 2, | |
4 | * as published by the Free Software Foundation. | |
5 | * | |
6 | * In addition to the permissions in the GNU General Public License, | |
7 | * the authors give you unlimited permission to link the compiled | |
8 | * version of this file into combinations with other programs, | |
9 | * and to distribute those combinations without any restriction | |
10 | * coming from the use of this file. (The General Public License | |
11 | * restrictions do apply in other respects; for example, they cover | |
12 | * modification of the file, and distribution when not linked into | |
13 | * a combined executable.) | |
14 | * | |
15 | * This file is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; see the file COPYING. If not, write to | |
22 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, | |
23 | * Boston, MA 02110-1301, USA. | |
24 | */ | |
25 | ||
26 | #ifndef INCLUDE_git_os_abstraction_h__ | |
27 | #define INCLUDE_git_os_abstraction_h__ | |
28 | ||
2dbdb824 SP |
29 | /** Force 64 bit off_t size on POSIX. */ |
30 | #define _FILE_OFFSET_BITS 64 | |
31 | ||
32 | #include <errno.h> | |
16a67770 SP |
33 | #include <unistd.h> |
34 | #include <sys/stat.h> | |
35 | #include <fcntl.h> | |
36 | #include <sys/types.h> | |
37 | #include <time.h> | |
2dbdb824 | 38 | #include <stdlib.h> |
b7c891c6 | 39 | #include <string.h> |
16a67770 SP |
40 | |
41 | /** | |
42 | * @file git/os/unix.h | |
43 | * @brief Portable operating system abstractions | |
44 | * @defgroup git_os_abstraction Portable operating system abstractions | |
45 | * @ingroup Git | |
46 | * @{ | |
47 | */ | |
48 | GIT_BEGIN_DECL | |
49 | ||
50 | /** Descriptor to an open file in the filesystem. */ | |
51 | typedef int git_file; | |
52 | ||
53 | /** | |
54 | * Open a file by path name. | |
55 | * | |
56 | * Valid flags are: | |
57 | * - O_CREAT: Create the file if it does not yet exist. | |
58 | * - O_RDONLY: Open the file for reading. | |
59 | * - O_WRONLY: Open the file for writing. | |
60 | * - O_RDWR: Open the file for both reading and writing. | |
61 | * | |
3e9e6909 | 62 | * @param out descriptor storage to populate on success. |
16a67770 SP |
63 | * @param path path name of the file to open. |
64 | * @param flags bitmask of access requested to the file. | |
3e9e6909 SP |
65 | * @return |
66 | * - On success, GIT_SUCCESS. | |
67 | * - On error, <0. | |
16a67770 | 68 | */ |
3e9e6909 | 69 | GIT_EXTERN(int) git_fopen(git_file *out, const char *path, int flags); |
16a67770 SP |
70 | |
71 | /** | |
72 | * Read from an open file descriptor at the current position. | |
73 | * | |
3e9e6909 SP |
74 | * Exactly the requested number of bytes is read. If the stream |
75 | * ends early, an error is indicated, and the exact number of bytes | |
76 | * transferred is unspecified. | |
16a67770 SP |
77 | * |
78 | * @param fd open descriptor. | |
79 | * @param buf buffer to store the read data into. | |
80 | * @param cnt number of bytes to transfer. | |
81 | * @return | |
3e9e6909 SP |
82 | * - On success, GIT_SUCCESS. |
83 | * - On error, <0. | |
16a67770 | 84 | */ |
3e9e6909 | 85 | GIT_EXTERN(int) git_fread(git_file fd, void *buf, size_t cnt); |
16a67770 SP |
86 | |
87 | /** | |
88 | * Write to an open file descriptor at the current position. | |
89 | * | |
3e9e6909 SP |
90 | * Exactly the requested number of bytes is written. If the stream |
91 | * ends early, an error is indicated, and the exact number of bytes | |
92 | * transferred is unspecified. | |
16a67770 SP |
93 | * |
94 | * @param fd open descriptor. | |
95 | * @param buf buffer to write data from. | |
96 | * @param cnt number of bytes to transfer. | |
97 | * @return | |
3e9e6909 SP |
98 | * - On success, GIT_SUCCESS. |
99 | * - On error, <0. | |
100 | */ | |
101 | GIT_EXTERN(int) git_fwrite(git_file fd, void *buf, size_t cnt); | |
102 | ||
2dbdb824 SP |
103 | /** |
104 | * Get the current size of an open file. | |
105 | * @param fd open descriptor. | |
106 | * @return | |
107 | * - On success, >= 0, indicating the file size in bytes. | |
108 | * - On error, <0. | |
109 | */ | |
110 | GIT_EXTERN(off_t) git_fsize(git_file fd); | |
111 | ||
3e9e6909 SP |
112 | /** |
113 | * Close an open file descriptor. | |
114 | * @param fd descriptor to close. | |
115 | * @return | |
116 | * - On success, GIT_SUCCESS. | |
117 | * - On error, <0. | |
16a67770 | 118 | */ |
3e9e6909 | 119 | #define git_fclose(fd) close(fd) |
16a67770 SP |
120 | |
121 | /** @} */ | |
122 | GIT_END_DECL | |
123 | #endif |