summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2012-06-22 20:48:50 +0200
committerVicent Marti <tanoku@gmail.com>2012-06-22 20:48:50 +0200
commit2ae052d1b1574d1a4de402c91ebb98f061c997d4 (patch)
treeb300607ad284ef97e5b0d09cf519905f84668174 /src
parent430af731d259053691b0de9b18917f7adf97021a (diff)
parentdb5a6ec72b63c986cca764c75f9d3d720cff44ef (diff)
downloadlibgit2-2ae052d1b1574d1a4de402c91ebb98f061c997d4.tar.gz
Merge branch 'pull-req' of https://github.com/chris-y/libgit2 into amigaos
Diffstat (limited to 'src')
-rwxr-xr-xsrc/amiga/map.c51
-rw-r--r--src/indexer.c2
-rw-r--r--src/map.h4
-rw-r--r--src/mwindow.c1
-rw-r--r--src/netops.c96
-rw-r--r--src/pack.c2
-rw-r--r--src/pool.c2
-rw-r--r--src/posix.h10
-rw-r--r--src/unix/map.c2
-rw-r--r--src/unix/posix.h2
10 files changed, 168 insertions, 4 deletions
diff --git a/src/amiga/map.c b/src/amiga/map.c
new file mode 100755
index 000000000..2fb065c8b
--- /dev/null
+++ b/src/amiga/map.c
@@ -0,0 +1,51 @@
+/*
+ * 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 <git2/common.h>
+
+#ifndef GIT_WIN32
+
+#include "posix.h"
+#include "map.h"
+#include <errno.h>
+
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+{
+ GIT_MMAP_VALIDATE(out, len, prot, flags);
+
+ out->data = NULL;
+ out->len = 0;
+
+ if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) {
+ giterr_set(GITERR_OS, "Trying to map shared-writeable");
+ return -1;
+ }
+
+ if((out->data = malloc(len))) {
+ p_lseek(fd, offset, SEEK_SET);
+ p_read(fd, out->data, len);
+ }
+
+ if (!out->data || (out->data == MAP_FAILED)) {
+ giterr_set(GITERR_OS, "Failed to mmap. Could not write data");
+ return -1;
+ }
+
+ out->len = len;
+
+ return 0;
+}
+
+int p_munmap(git_map *map)
+{
+ assert(map != NULL);
+ free(map->data);
+
+ return 0;
+}
+
+#endif
+
diff --git a/src/indexer.c b/src/indexer.c
index 5ae66c9f1..565d9ea0e 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -365,11 +365,11 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
if (error < 0) {
idx->off = entry_start;
error = store_delta(idx);
+
if (error == GIT_EBUFS)
return 0;
if (error < 0)
return error;
-
continue;
}
diff --git a/src/map.h b/src/map.h
index 96d879547..6ce6d3685 100644
--- a/src/map.h
+++ b/src/map.h
@@ -23,6 +23,10 @@
#define GIT_MAP_TYPE 0xf
#define GIT_MAP_FIXED 0x10
+#ifdef __amigaos4__
+#define MAP_FAILED 0
+#endif
+
typedef struct { /* memory mapped buffer */
void *data; /* data bytes */
size_t len; /* data length */
diff --git a/src/mwindow.c b/src/mwindow.c
index 57adabd48..74fbf7834 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -158,6 +158,7 @@ static git_mwindow *new_window(
git_mwindow *w;
w = git__malloc(sizeof(*w));
+
if (w == NULL)
return NULL;
diff --git a/src/netops.c b/src/netops.c
index 32554743f..0342d7fa1 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -32,6 +32,99 @@
#include "buffer.h"
#include "transport.h"
+#ifdef NO_ADDRINFO
+struct addrinfo {
+ struct hostent *ai_hostent;
+ struct servent *ai_servent;
+ struct sockaddr_in ai_addr_in;
+ struct sockaddr *ai_addr;
+ size_t ai_addrlen;
+ int ai_family;
+ int ai_socktype;
+ int ai_protocol;
+ long ai_port;
+ struct addrinfo *ai_next;
+};
+
+static int getaddrinfo(const char *host, const char *port, struct addrinfo *hints, struct addrinfo **info) {
+ GIT_UNUSED(hints);
+
+ struct addrinfo *ainfo, *ai;
+ int p = 0;
+
+ if((ainfo = malloc(sizeof(struct addrinfo))) == NULL)
+ return -1;
+
+ if((ainfo->ai_hostent = gethostbyname(host)) == NULL)
+ return -2;
+
+ ainfo->ai_servent = getservbyname(port, 0);
+
+ if(ainfo->ai_servent)
+ ainfo->ai_port = ainfo->ai_servent->s_port;
+ else
+ ainfo->ai_port = atol(port);
+
+
+ memcpy(&ainfo->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[0], ainfo->ai_hostent->h_length);
+ ainfo->ai_protocol = 0;
+ ainfo->ai_socktype = hints->ai_socktype;
+ ainfo->ai_family = ainfo->ai_hostent->h_addrtype;
+ ainfo->ai_addr_in.sin_family = ainfo->ai_family;
+ ainfo->ai_addr_in.sin_port = ainfo->ai_port;
+ ainfo->ai_addr = (struct addrinfo *)&ainfo->ai_addr_in;
+ ainfo->ai_addrlen = sizeof(struct sockaddr_in);
+
+ *info = ainfo;
+
+ if(ainfo->ai_hostent->h_addr_list[1] == NULL) {
+ ainfo->ai_next = NULL;
+ return 0;
+ }
+
+ ai = ainfo;
+
+ for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
+ ai->ai_next = malloc(sizeof(struct addrinfo));
+ memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo));
+ memcpy(&ai->ai_next->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[p], ainfo->ai_hostent->h_length);
+ ai->ai_next->ai_addr = (struct addrinfo *)&ai->ai_next->ai_addr_in;
+ ai = ai->ai_next;
+ }
+
+ ai->ai_next = NULL;
+ return 0;
+}
+
+static void freeaddrinfo(struct addrinfo *info) {
+ struct addrinfo *p, *next;
+
+ p = info;
+
+ while(p != NULL) {
+ next = p->ai_next;
+ free(p);
+ p = next;
+ }
+}
+
+static const char *gai_strerror(int ret) {
+ switch(ret) {
+ case -1:
+ return "Out of memory";
+ break;
+
+ case -2:
+ return "Address lookup failed";
+ break;
+
+ default:
+ return "Unknown error";
+ break;
+ }
+}
+#endif
+
#ifdef GIT_WIN32
static void net_set_error(const char *str)
{
@@ -381,8 +474,8 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
GIT_SOCKET s = INVALID_SOCKET;
memset(&hints, 0x0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
+ hints.ai_family = AF_UNSPEC;
if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) {
giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret));
@@ -391,6 +484,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
for (p = info; p != NULL; p = p->ai_next) {
s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
+
if (s == INVALID_SOCKET) {
net_set_error("error creating socket");
break;
diff --git a/src/pack.c b/src/pack.c
index 0db1069de..9b5e0e18f 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -262,7 +262,7 @@ int git_packfile_unpack_header(
if (base == NULL)
return GIT_EBUFS;
- ret = packfile_unpack_header1(&used, size_p, type_p, base, left);
+ ret = packfile_unpack_header1(&used, size_p, type_p, base, left);
git_mwindow_close(w_curs);
if (ret == GIT_EBUFS)
return ret;
diff --git a/src/pool.c b/src/pool.c
index 641292d06..63bf09cee 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -275,6 +275,8 @@ uint32_t git_pool__system_page_size(void)
SYSTEM_INFO info;
GetSystemInfo(&info);
size = (uint32_t)info.dwPageSize;
+#elif defined(__amigaos4__)
+ size = (uint32_t)4096; /* 4K as there is no global value we can query */
#else
size = (uint32_t)sysconf(_SC_PAGE_SIZE);
#endif
diff --git a/src/posix.h b/src/posix.h
index 5799c0499..d423b7e07 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -83,6 +83,16 @@ extern int p_gettimeofday(struct timeval *tv, struct timezone *tz);
# include "unix/posix.h"
#endif
+#ifndef NO_READDIR_R
#define p_readdir_r(d,e,r) readdir_r(d,e,r)
+#else
+#include <dirent.h>
+GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
+{
+ GIT_UNUSED(entry);
+ *result = readdir(dirp);
+ return 0;
+}
+#endif
#endif
diff --git a/src/unix/map.c b/src/unix/map.c
index 772f4e247..9dcae5845 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -33,6 +33,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
mflag = MAP_PRIVATE;
out->data = mmap(NULL, len, mprot, mflag, fd, offset);
+
if (!out->data || out->data == MAP_FAILED) {
giterr_set(GITERR_OS, "Failed to mmap. Could not write data");
return -1;
@@ -47,6 +48,7 @@ int p_munmap(git_map *map)
{
assert(map != NULL);
munmap(map->data, map->len);
+
return 0;
}
diff --git a/src/unix/posix.h b/src/unix/posix.h
index 48b492941..83fd8a189 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_posix__w32_h__
#define INCLUDE_posix__w32_h__
-#ifndef __sun
+#if !defined(__sun) && !defined(__amigaos4__)
# include <fnmatch.h>
# define p_fnmatch(p, s, f) fnmatch(p, s, f)
#else