From 7ea0d136d0e819ddec8a5f794fa537b761ae4a3d Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 13 Apr 2010 22:43:15 +0200 Subject: win32: remove git.c (probably not correct) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy --- win32/git.c | 91 ---------------------------------------------------------- win32/strbuf.c | 18 +++++++++++- 2 files changed, 17 insertions(+), 92 deletions(-) delete mode 100644 win32/git.c (limited to 'win32') diff --git a/win32/git.c b/win32/git.c deleted file mode 100644 index 668f8c118..000000000 --- a/win32/git.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "libbb.h" -#include "git.h" - -#define die bb_error_msg_and_die - -/* - * xwrite() is the same a write(), but it automatically restarts write() - * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT - * GUARANTEE that "len" bytes is written even if the operation is successful. - */ -ssize_t _xwrite(int fd, const void *buf, size_t len) -{ - ssize_t nr; - while (1) { - nr = write(fd, buf, len); - if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) - continue; - return nr; - } -} - -ssize_t _xread(int fd, void *buf, size_t len) -{ - ssize_t nr; - while (1) { - nr = read(fd, buf, len); - if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) - continue; - return nr; - } -} - -ssize_t write_in_full(int fd, const void *buf, size_t count) -{ - const char *p = buf; - ssize_t total = 0; - - while (count > 0) { - ssize_t written = _xwrite(fd, p, count); - if (written < 0) - return -1; - if (!written) { - errno = ENOSPC; - return -1; - } - count -= written; - p += written; - total += written; - } - - return total; -} - - -void *xcalloc(size_t nmemb, size_t size) -{ - void *ret = calloc(nmemb, size); - if (!ret && (!nmemb || !size)) - ret = calloc(1, 1); - if (!ret) { - ret = calloc(nmemb, size); - if (!ret && (!nmemb || !size)) - ret = calloc(1, 1); - if (!ret) - die("Out of memory, calloc failed"); - } - return ret; -} - -/* - * This is like mktime, but without normalization of tm_wday and tm_yday. - */ -time_t tm_to_time_t(const struct tm *tm) -{ - static const int mdays[] = { - 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 - }; - int year = tm->tm_year - 70; - int month = tm->tm_mon; - int day = tm->tm_mday; - - if (year < 0 || year > 129) /* algo only works for 1970-2099 */ - return -1; - if (month < 0 || month > 11) /* array bounds */ - return -1; - if (month < 2 || (year + 2) % 4) - day--; - return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + - tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; -} - diff --git a/win32/strbuf.c b/win32/strbuf.c index 98659d448..27a8157b2 100644 --- a/win32/strbuf.c +++ b/win32/strbuf.c @@ -90,6 +90,22 @@ void strbuf_tolower(struct strbuf *sb) sb->buf[i] = tolower(sb->buf[i]); } +void *xcalloc(size_t nmemb, size_t size) +{ + void *ret = calloc(nmemb, size); + if (!ret && (!nmemb || !size)) + ret = calloc(1, 1); + if (!ret) { + ret = calloc(nmemb, size); + if (!ret && (!nmemb || !size)) + ret = calloc(1, 1); + if (!ret) + die("Out of memory, calloc failed"); + } + return ret; +} + + struct strbuf **strbuf_split(const struct strbuf *sb, int delim) { int alloc = 2, pos = 0; @@ -266,7 +282,7 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint) for (;;) { ssize_t cnt; - cnt = _xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1); + cnt = read(fd, sb->buf + sb->len, sb->alloc - sb->len - 1); if (cnt < 0) { if (oldalloc == 0) strbuf_release(sb); -- cgit v1.2.3-55-g6feb