Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

compat.c File Reference

Go to the source code of this file.

Functions

char * strdup (char *s)
char * getcwd (char *buf, int size)
pid_t waitpid (pid_t pid, int *statptr, int options)
void * memmove (void *dest, const void *src, size_t n)
char * strpbrk (const char *s, const char *accept)
 Find the first ocurrence in s of any character in accept. More...

size_t strlcpy (char *d, const char *s, size_t bufsize)
 Like strncpy but does not 0 fill the buffer and always null terminates. More...

size_t strlcat (char *d, const char *s, size_t bufsize)
 Like strncat() but does not 0 fill the buffer and always null terminates. More...

char * rep_inet_ntoa (struct in_addr ip)
int inet_aton (const char *cp, struct in_addr *inp)
int sys_gettimeofday (struct timeval *tv)


Function Documentation

char* strdup char *    s
 

Definition at line 33 of file lib/compat.c.

Referenced by access_match(), add_exclude_line(), add_include_line(), add_list(), auth_server(), copy_argv(), delete_files(), do_cmd(), getpassf(), glob_expand(), glob_expand_one(), make_exclude(), make_file(), push_dir(), read_batch_flist_info(), receive_file_entry(), rsync_module(), set_compression(), set_socket_options(), string_set(), and unsafe_symlink().

00034 {
00035   int l = strlen(s) + 1;
00036   char *ret = (char *)malloc(l);
00037   if (ret)
00038     strcpy(ret,s);
00039   return ret;
00040 }

char* getcwd char *    buf,
int    size
 

Definition at line 44 of file lib/compat.c.

Referenced by push_dir().

00045 {
00046         return getwd(buf);
00047 }

pid_t waitpid pid_t    pid,
int *    statptr,
int    options
 

Definition at line 52 of file lib/compat.c.

Referenced by _exit_cleanup(), sigchld_handler(), start_accept_loop(), and wait_process().

00053 {
00054 #ifdef HAVE_WAIT4
00055         return wait4(pid, statptr, options, NULL);
00056 #else
00057         /* If wait4 is also not available, try wait3 for SVR3 variants */
00058         /* Less ideal because can't actually request a specific pid */
00059         /* At least the WNOHANG option is supported */
00060         /* Code borrowed from apache fragment written by dwd@bell-labs.com */
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 }

void* memmove void *    dest,
const void *    src,
size_t    n
 

Definition at line 78 of file lib/compat.c.

Referenced by clean_flist(), log_formatted(), and map_ptr().

00079 {
00080         bcopy((char *) src, (char *) dest, n);
00081         return dest;
00082 }

char* strpbrk const char *    s,
const char *    accept
 

Find the first ocurrence in s of any character in accept.

Derived from glibc

Definition at line 91 of file lib/compat.c.

Referenced by make_exclude().

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 }

size_t strlcpy char *    d,
const char *    s,
size_t    bufsize
 

Like strncpy but does not 0 fill the buffer and always null terminates.

Parameters:
bufsize  is the size of the destination buffer.
Returns:
index of the terminating byte.

Definition at line 115 of file lib/compat.c.

Referenced by f_name(), gen_challenge(), get_secret(), log_formatted(), lp_do_parameter(), make_file(), open_socket_out(), pop_dir(), push_dir(), read_batch_csums_file(), read_batch_delta_file(), read_batch_flist_file(), receive_file_entry(), recv_files(), robust_unlink(), send_directory(), send_exclude_list(), send_file_entry(), send_file_list(), send_files(), timestring(), write_batch_argvs_file(), write_batch_csums_file(), write_batch_delta_file(), and write_batch_flist_file().

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 }

size_t strlcat char *    d,
const char *    s,
size_t    bufsize
 

Like strncat() but does not 0 fill the buffer and always null terminates.

Parameters:
bufsize  length of the buffer, which should be one more than the maximum resulting string length.

Definition at line 135 of file lib/compat.c.

Referenced by push_dir(), read_batch_csums_file(), read_batch_delta_file(), read_batch_flist_file(), send_directory(), send_exclude_list(), send_file_list(), send_files(), write_batch_argvs_file(), write_batch_csums_file(), write_batch_delta_file(), and write_batch_flist_file().

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 }

char* rep_inet_ntoa struct in_addr    ip
 

Definition at line 153 of file lib/compat.c.

References snprintf().

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 }

int inet_aton const char *    cp,
struct in_addr *    inp
 

Definition at line 169 of file lib/compat.c.

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 }

int sys_gettimeofday struct timeval *    tv
 

Definition at line 196 of file lib/compat.c.

Referenced by gen_challenge().

00197 {
00198 #if HAVE_GETTIMEOFDAY_TZ
00199         return gettimeofday(tv, NULL);
00200 #else
00201         return gettimeofday(tv);
00202 #endif
00203 }


Generated on Tue Apr 16 12:37:38 2002 for rsync by doxygen1.2.15