mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-22 10:10:54 +00:00
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:
parent
cb6d65f621
commit
1e61e7a02f
@ -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
21
os.c
@ -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
26
os.h
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user