00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "rsync.h"
00030
00031
00032 #ifndef HAVE_STRDUP
00033 char *strdup(char *s)
00034 {
00035 int l = strlen(s) + 1;
00036 char *ret = (char *)malloc(l);
00037 if (ret)
00038 strcpy(ret,s);
00039 return ret;
00040 }
00041 #endif
00042
00043 #ifndef HAVE_GETCWD
00044 char *getcwd(char *buf, int size)
00045 {
00046 return getwd(buf);
00047 }
00048 #endif
00049
00050
00051 #ifndef HAVE_WAITPID
00052 pid_t waitpid(pid_t pid, int *statptr, int options)
00053 {
00054 #ifdef HAVE_WAIT4
00055 return wait4(pid, statptr, options, NULL);
00056 #else
00057
00058
00059
00060
00061 int tmp_pid, dummystat;;
00062 if (kill(pid, 0) == -1) {
00063 errno = ECHILD;
00064 return -1;
00065 }
00066 if (statptr == NULL)
00067 statptr = &dummystat;
00068 while (((tmp_pid = wait3(statptr, options, 0)) != pid) &&
00069 (tmp_pid != -1) && (tmp_pid != 0) && (pid != -1))
00070 ;
00071 return tmp_pid;
00072 #endif
00073 }
00074 #endif
00075
00076
00077 #ifndef HAVE_MEMMOVE
00078 void *memmove(void *dest, const void *src, size_t n)
00079 {
00080 bcopy((char *) src, (char *) dest, n);
00081 return dest;
00082 }
00083 #endif
00084
00085 #ifndef HAVE_STRPBRK
00086
00087
00088
00089
00090
00091 char *strpbrk(const char *s, const char *accept)
00092 {
00093 while (*s != '\0') {
00094 const char *a = accept;
00095 while (*a != '\0') {
00096 if (*a++ == *s) return (char *)s;
00097 }
00098 ++s;
00099 }
00100
00101 return NULL;
00102 }
00103 #endif
00104
00105
00106 #ifndef HAVE_STRLCPY
00107
00108
00109
00110
00111
00112
00113
00114
00115 size_t strlcpy(char *d, const char *s, size_t bufsize)
00116 {
00117 size_t len = strlen(s);
00118 size_t ret = len;
00119 if (bufsize <= 0) return 0;
00120 if (len >= bufsize) len = bufsize-1;
00121 memcpy(d, s, len);
00122 d[len] = 0;
00123 return ret;
00124 }
00125 #endif
00126
00127 #ifndef HAVE_STRLCAT
00128
00129
00130
00131
00132
00133
00134
00135 size_t strlcat(char *d, const char *s, size_t bufsize)
00136 {
00137 size_t len1 = strlen(d);
00138 size_t len2 = strlen(s);
00139 size_t ret = len1 + len2;
00140
00141 if (len1+len2 >= bufsize) {
00142 len2 = bufsize - (len1+1);
00143 }
00144 if (len2 > 0) {
00145 memcpy(d+len1, s, len2);
00146 d[len1+len2] = 0;
00147 }
00148 return ret;
00149 }
00150 #endif
00151
00152 #ifdef REPLACE_INET_NTOA
00153 char *rep_inet_ntoa(struct in_addr ip)
00154 {
00155 unsigned char *p = (unsigned char *)&ip.s_addr;
00156 static char buf[18];
00157 #if WORDS_BIGENDIAN
00158 snprintf(buf, 18, "%d.%d.%d.%d",
00159 (int)p[0], (int)p[1], (int)p[2], (int)p[3]);
00160 #else
00161 snprintf(buf, 18, "%d.%d.%d.%d",
00162 (int)p[3], (int)p[2], (int)p[1], (int)p[0]);
00163 #endif
00164 return buf;
00165 }
00166 #endif
00167
00168 #ifdef REPLACE_INET_ATON
00169 int inet_aton(const char *cp, struct in_addr *inp)
00170 {
00171 unsigned int a1, a2, a3, a4;
00172 unsigned long ret;
00173
00174 if (strcmp(cp, "255.255.255.255") == 0) {
00175 inp->s_addr = (unsigned) -1;
00176 return 0;
00177 }
00178
00179 if (sscanf(cp, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4 ||
00180 a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255) {
00181 return 0;
00182 }
00183
00184 ret = (a1 << 24) | (a2 << 16) | (a3 << 8) | a4;
00185
00186 inp->s_addr = htonl(ret);
00187
00188 if (inp->s_addr == (unsigned) -1) {
00189 return 0;
00190 }
00191 return 1;
00192 }
00193 #endif
00194
00195
00196 int sys_gettimeofday(struct timeval *tv)
00197 {
00198 #if HAVE_GETTIMEOFDAY_TZ
00199 return gettimeofday(tv, NULL);
00200 #else
00201 return gettimeofday(tv);
00202 #endif
00203 }