diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-14 02:15:41 +0200 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-20 19:14:19 +0200 |
commit | 87a429e345437cb476295f2a09e9690eaa90f9f7 (patch) | |
tree | 3360929812bd4c9cb8a18f3672c2b1bb31f6b710 /win32 | |
parent | bd0bb5d89b591326583754d4cbf45666aefc0fb8 (diff) | |
download | busybox-w32-87a429e345437cb476295f2a09e9690eaa90f9f7.tar.gz busybox-w32-87a429e345437cb476295f2a09e9690eaa90f9f7.tar.bz2 busybox-w32-87a429e345437cb476295f2a09e9690eaa90f9f7.zip |
win32: mingw32/git.c
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Diffstat (limited to 'win32')
-rw-r--r-- | win32/git.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/win32/git.c b/win32/git.c new file mode 100644 index 000000000..668f8c118 --- /dev/null +++ b/win32/git.c | |||
@@ -0,0 +1,91 @@ | |||
1 | #include "libbb.h" | ||
2 | #include "git.h" | ||
3 | |||
4 | #define die bb_error_msg_and_die | ||
5 | |||
6 | /* | ||
7 | * xwrite() is the same a write(), but it automatically restarts write() | ||
8 | * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT | ||
9 | * GUARANTEE that "len" bytes is written even if the operation is successful. | ||
10 | */ | ||
11 | ssize_t _xwrite(int fd, const void *buf, size_t len) | ||
12 | { | ||
13 | ssize_t nr; | ||
14 | while (1) { | ||
15 | nr = write(fd, buf, len); | ||
16 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
17 | continue; | ||
18 | return nr; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | ssize_t _xread(int fd, void *buf, size_t len) | ||
23 | { | ||
24 | ssize_t nr; | ||
25 | while (1) { | ||
26 | nr = read(fd, buf, len); | ||
27 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
28 | continue; | ||
29 | return nr; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | ssize_t write_in_full(int fd, const void *buf, size_t count) | ||
34 | { | ||
35 | const char *p = buf; | ||
36 | ssize_t total = 0; | ||
37 | |||
38 | while (count > 0) { | ||
39 | ssize_t written = _xwrite(fd, p, count); | ||
40 | if (written < 0) | ||
41 | return -1; | ||
42 | if (!written) { | ||
43 | errno = ENOSPC; | ||
44 | return -1; | ||
45 | } | ||
46 | count -= written; | ||
47 | p += written; | ||
48 | total += written; | ||
49 | } | ||
50 | |||
51 | return total; | ||
52 | } | ||
53 | |||
54 | |||
55 | void *xcalloc(size_t nmemb, size_t size) | ||
56 | { | ||
57 | void *ret = calloc(nmemb, size); | ||
58 | if (!ret && (!nmemb || !size)) | ||
59 | ret = calloc(1, 1); | ||
60 | if (!ret) { | ||
61 | ret = calloc(nmemb, size); | ||
62 | if (!ret && (!nmemb || !size)) | ||
63 | ret = calloc(1, 1); | ||
64 | if (!ret) | ||
65 | die("Out of memory, calloc failed"); | ||
66 | } | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | /* | ||
71 | * This is like mktime, but without normalization of tm_wday and tm_yday. | ||
72 | */ | ||
73 | time_t tm_to_time_t(const struct tm *tm) | ||
74 | { | ||
75 | static const int mdays[] = { | ||
76 | 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 | ||
77 | }; | ||
78 | int year = tm->tm_year - 70; | ||
79 | int month = tm->tm_mon; | ||
80 | int day = tm->tm_mday; | ||
81 | |||
82 | if (year < 0 || year > 129) /* algo only works for 1970-2099 */ | ||
83 | return -1; | ||
84 | if (month < 0 || month > 11) /* array bounds */ | ||
85 | return -1; | ||
86 | if (month < 2 || (year + 2) % 4) | ||
87 | day--; | ||
88 | return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + | ||
89 | tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; | ||
90 | } | ||
91 | |||