diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-22 21:56:24 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 04:44:32 +1000 |
commit | d680f769d003a19f51158a689e6039d650a3efe0 (patch) | |
tree | d1bdc7af37ec3f2118bf87cb66c8b5f4b726adf2 /libbb/git.c | |
parent | ef9b20fa7904ee5f72e3a759934560226360842d (diff) | |
download | busybox-w32-d680f769d003a19f51158a689e6039d650a3efe0.tar.gz busybox-w32-d680f769d003a19f51158a689e6039d650a3efe0.tar.bz2 busybox-w32-d680f769d003a19f51158a689e6039d650a3efe0.zip |
update imported git files to adapt to new environment
Diffstat (limited to 'libbb/git.c')
-rw-r--r-- | libbb/git.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/libbb/git.c b/libbb/git.c new file mode 100644 index 000000000..3ca8a9424 --- /dev/null +++ b/libbb/git.c | |||
@@ -0,0 +1,62 @@ | |||
1 | #include "libbb.h" | ||
2 | #include "git.h" | ||
3 | |||
4 | ssize_t write_in_full(int fd, const void *buf, size_t count) | ||
5 | { | ||
6 | const char *p = buf; | ||
7 | ssize_t total = 0; | ||
8 | |||
9 | while (count > 0) { | ||
10 | ssize_t written = xwrite(fd, p, count); | ||
11 | if (written < 0) | ||
12 | return -1; | ||
13 | if (!written) { | ||
14 | errno = ENOSPC; | ||
15 | return -1; | ||
16 | } | ||
17 | count -= written; | ||
18 | p += written; | ||
19 | total += written; | ||
20 | } | ||
21 | |||
22 | return total; | ||
23 | } | ||
24 | |||
25 | |||
26 | void *xcalloc(size_t nmemb, size_t size) | ||
27 | { | ||
28 | void *ret = calloc(nmemb, size); | ||
29 | if (!ret && (!nmemb || !size)) | ||
30 | ret = calloc(1, 1); | ||
31 | if (!ret) { | ||
32 | ret = calloc(nmemb, size); | ||
33 | if (!ret && (!nmemb || !size)) | ||
34 | ret = calloc(1, 1); | ||
35 | if (!ret) | ||
36 | die("Out of memory, calloc failed"); | ||
37 | } | ||
38 | return ret; | ||
39 | } | ||
40 | |||
41 | /* | ||
42 | * This is like mktime, but without normalization of tm_wday and tm_yday. | ||
43 | */ | ||
44 | time_t tm_to_time_t(const struct tm *tm) | ||
45 | { | ||
46 | static const int mdays[] = { | ||
47 | 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 | ||
48 | }; | ||
49 | int year = tm->tm_year - 70; | ||
50 | int month = tm->tm_mon; | ||
51 | int day = tm->tm_mday; | ||
52 | |||
53 | if (year < 0 || year > 129) /* algo only works for 1970-2099 */ | ||
54 | return -1; | ||
55 | if (month < 0 || month > 11) /* array bounds */ | ||
56 | return -1; | ||
57 | if (month < 2 || (year + 2) % 4) | ||
58 | day--; | ||
59 | return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + | ||
60 | tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; | ||
61 | } | ||
62 | |||