diff options
| author | Shawn O. Pearce <spearce@spearce.org> | 2008-11-01 16:53:06 -0700 |
|---|---|---|
| committer | Shawn O. Pearce <spearce@spearce.org> | 2008-11-01 16:53:06 -0700 |
| commit | 16a67770b7d8d72317c4b775213c23a8bd74f5e0 (patch) | |
| tree | cc5aaa5fa825a103a547d381c7a5c0524c4853cd /src | |
| parent | 50298f44a45eda3a29dae82dbe911b5aa176ac07 (diff) | |
| download | libgit2-16a67770b7d8d72317c4b775213c23a8bd74f5e0.tar.gz | |
Create a micro abstraction around the POSIX file APIs
This way we can start to write IO code to read and write files in the
Git object database, but provide a hook to inject native Win32 APIs
instead so libgit2 can be ported to run natively on that platform.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/os/unix.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/os/unix.c b/src/os/unix.c new file mode 100644 index 000000000..d132e9755 --- /dev/null +++ b/src/os/unix.c @@ -0,0 +1,47 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, + * as published by the Free Software Foundation. + * + * In addition to the permissions in the GNU General Public License, + * the authors give you unlimited permission to link the compiled + * version of this file into combinations with other programs, + * and to distribute those combinations without any restriction + * coming from the use of this file. (The General Public License + * restrictions do apply in other respects; for example, they cover + * modification of the file, and distribution when not linked into + * a combined executable.) + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <errno.h> +#include "git/common.h" + +ssize_t git_fread(git_file fd, void *buf, size_t cnt) +{ + for (;;) { + ssize_t r = read(fd, buf, cnt); + if (r < 0 && (errno == EINTR || errno == EAGAIN)) + continue; + return r; + } +} + +ssize_t git_fwrite(git_file fd, void *buf, size_t cnt) +{ + for (;;) { + ssize_t r = write(fd, buf, cnt); + if (r < 0 && (errno == EINTR || errno == EAGAIN)) + continue; + return r; + } +} |
