compat.c

説明を見る。
00001 /* 
00002    Copyright (C) Andrew Tridgell 1998
00003    Copyright (C) 2002 by Martin Pool
00004    
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009    
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014    
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /**
00021  * @file compat.c
00022  *
00023  * Reimplementations of standard functions for platforms that don't
00024  * have them.
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         /* 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 }
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  * Find the first ocurrence in @p s of any character in @p accept.
00088  *
00089  * Derived from glibc 
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  * Like strncpy but does not 0 fill the buffer and always null 
00109  * terminates.
00110  *
00111  * @param bufsize is the size of the destination buffer.
00112  *
00113  * @return index of the terminating byte.
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) {
00120                 if (len >= bufsize)
00121                         len = bufsize-1;
00122                 memcpy(d, s, len);
00123                 d[len] = 0;
00124         }
00125         return ret;
00126 }
00127 #endif
00128 
00129 #ifndef HAVE_STRLCAT
00130 /**
00131  * Like strncat() but does not 0 fill the buffer and always null 
00132  * terminates.
00133  *
00134  * @param bufsize length of the buffer, which should be one more than
00135  * the maximum resulting string length.
00136  **/
00137  size_t strlcat(char *d, const char *s, size_t bufsize)
00138 {
00139         size_t len1 = strlen(d);
00140         size_t len2 = strlen(s);
00141         size_t ret = len1 + len2;
00142 
00143         if (len1 < bufsize - 1) {
00144                 if (len2 >= bufsize - len1)
00145                         len2 = bufsize - len1 - 1;
00146                 memcpy(d+len1, s, len2);
00147                 d[len1+len2] = 0;
00148         }
00149         return ret;
00150 }
00151 #endif
00152 
00153 /* some systems don't take the 2nd argument */
00154 int sys_gettimeofday(struct timeval *tv)
00155 {
00156 #ifdef HAVE_GETTIMEOFDAY_TZ
00157         return gettimeofday(tv, NULL);
00158 #else
00159         return gettimeofday(tv);
00160 #endif
00161 }

rsyncに対してSat Dec 5 19:45:40 2009に生成されました。  doxygen 1.4.7