Fix bcopy()/bzero() #define hack

Replace #define bcopy(...) memset(...) with inline functions only if
bcopy() is unavailable, as checked by configure script

Ditto bzero()
This commit is contained in:
Andrew Bettison 2013-02-25 15:23:03 +10:30
parent cb6d65f621
commit 1e61e7a02f
3 changed files with 41 additions and 8 deletions

View File

@ -70,7 +70,7 @@ dnl Solaris hides nanosleep here
AC_CHECK_LIB(rt,nanosleep) AC_CHECK_LIB(rt,nanosleep)
dnl BSD way of getting socket creds dnl BSD way of getting socket creds
AC_CHECK_FUNCS(getpeereid) AC_CHECK_FUNCS([getpeereid bcopy bzero])
AC_CHECK_HEADERS( AC_CHECK_HEADERS(
stdio.h \ stdio.h \

21
os.c
View File

@ -17,11 +17,30 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#define __SERVALDNA_OS_INLINE
#include "os.h"
#include "log.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <alloca.h> #include <alloca.h>
#include <dirent.h> #include <dirent.h>
#include <time.h> #include <time.h>
#include "serval.h" #include <string.h>
#ifndef HAVE_BZERO
__SERVALDNA_OS_INLINE void bzero(void *buf, size_t len) {
memset(buf, 0, len);
}
#endif
#ifndef HAVE_BCOPY
__SERVALDNA_OS_INLINE void bcopy(void *src, void *dst, size_t len) {
memcpy(dst, src, len);
}
#endif
int mkdirs(const char *path, mode_t mode) int mkdirs(const char *path, mode_t mode)
{ {

26
os.h
View File

@ -17,13 +17,21 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef __SERVALDNA_OS_H
#define __SERVALDNA_OS_H
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#ifndef __SERVALDNA_OS_H #ifndef __SERVALDNA_OS_INLINE
#define __SERVALDNA_OS_H # if __GNUC__ && !__GNUC_STDC_INLINE__
# define __SERVALDNA_OS_INLINE extern inline
# else
# define __SERVALDNA_OS_INLINE inline
# endif
#endif
/* All wall clock times in the Serval daemon are represented in milliseconds /* All wall clock times in the Serval daemon are represented in milliseconds
* since the Unix epoch. The gettime_ms() function uses gettimeofday(2) to * since the Unix epoch. The gettime_ms() function uses gettimeofday(2) to
@ -49,11 +57,17 @@ typedef long long time_ms_t;
time_ms_t gettime_ms(); time_ms_t gettime_ms();
time_ms_t sleep_ms(time_ms_t milliseconds); time_ms_t sleep_ms(time_ms_t milliseconds);
/* bzero(3) is deprecated in favour of memset(3). */ #ifndef HAVE_BZERO
#define bzero(addr,len) memset((addr), 0, (len)) __SERVALDNA_OS_INLINE void bzero(void *buf, size_t len) {
memset(buf, 0, len);
}
#endif
/* OpenWRT libc doesn't have bcopy, but has memmove */ #ifndef HAVE_BCOPY
#define bcopy(A,B,C) memmove(B,A,C) __SERVALDNA_OS_INLINE void bcopy(void *src, void *dst, size_t len) {
memcpy(dst, src, len);
}
#endif
int mkdirs(const char *path, mode_t mode); int mkdirs(const char *path, mode_t mode);
int mkdirsn(const char *path, size_t len, mode_t mode); int mkdirsn(const char *path, size_t len, mode_t mode);