diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2018-03-01 12:51:30 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2018-03-01 12:51:30 +0000 |
commit | 4684272897e351ed21f82a0ef84bc94194b4d538 (patch) | |
tree | 91a52b9dd3881e2ae001c5dd1a2a08fbc65da0bc /src | |
parent | ccb423ed6f317da5a02f4feeda082d791215a4ba (diff) | |
download | skalibs-4684272897e351ed21f82a0ef84bc94194b4d538.tar.xz |
Add byte_zzero, openb_read
Diffstat (limited to 'src')
-rw-r--r-- | src/include/skalibs/bytestr.h | 1 | ||||
-rw-r--r-- | src/include/skalibs/djbunix.h | 1 | ||||
-rw-r--r-- | src/libstddjb/byte_zzero.c | 35 | ||||
-rw-r--r-- | src/libstddjb/openb_read.c | 10 | ||||
-rw-r--r-- | src/sysdeps/tryexplicit_bzero.c | 30 |
5 files changed, 77 insertions, 0 deletions
diff --git a/src/include/skalibs/bytestr.h b/src/include/skalibs/bytestr.h index 3a5c95e..b20a34d 100644 --- a/src/include/skalibs/bytestr.h +++ b/src/include/skalibs/bytestr.h @@ -31,6 +31,7 @@ extern size_t byte_in (char const *, size_t, char const *, size_t) gccattr_pure #define byte_equal(s, n, t) (!memcmp(s, (t), n)) extern size_t byte_count (char const *, size_t, char) gccattr_pure ; extern size_t byte_search (char const *, size_t, char const *, size_t) ; +extern void byte_zzero (char *, size_t) ; #define str_diffb(a, n, b) strncmp(a, (b), n) extern size_t str_chr (char const *, int) gccattr_pure ; diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h index 6e2adcc..d3edc97 100644 --- a/src/include/skalibs/djbunix.h +++ b/src/include/skalibs/djbunix.h @@ -44,6 +44,7 @@ extern void lock_unx (int) ; extern int open2 (char const *, unsigned int) ; extern int open3 (char const *, unsigned int, unsigned int) ; extern int open_read (char const *) ; +extern int openb_read (char const *) ; extern int open_readb (char const *) ; extern int open_excl (char const *) ; extern int open_append (char const *) ; diff --git a/src/libstddjb/byte_zzero.c b/src/libstddjb/byte_zzero.c new file mode 100644 index 0000000..99a5e3a --- /dev/null +++ b/src/libstddjb/byte_zzero.c @@ -0,0 +1,35 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> + +#ifdef SKALIBS_HASEXPLICIT_BZERO + +#include <skalibs/nonposix.h> +#include <string.h> +#include <strings.h> +#include <skalibs/bytestr.h> + +void byte_zzero (char *s, size_t n) +{ + explicit_bzero(s, n) ; +} + +#else + +#include <string.h> +#include <skalibs/gccattributes.h> +#include <skalibs/bytestr.h> + +void _byte_zzero_hook (char *, size_t) gccattr_weak ; + +gccattr_weak void _byte_zzero_hook (char *s, size_t n) +{ +} + +void byte_zzero (char *s, size_t n) +{ + memset(s, 0, n) ; + _byte_zzero_hook(s, n) ; +} + +#endif diff --git a/src/libstddjb/openb_read.c b/src/libstddjb/openb_read.c new file mode 100644 index 0000000..19ec073 --- /dev/null +++ b/src/libstddjb/openb_read.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <skalibs/nonposix.h> +#include <fcntl.h> +#include <skalibs/djbunix.h> + +int openb_read (char const *fn) +{ + return open2(fn, O_RDONLY) ; +} diff --git a/src/sysdeps/tryexplicit_bzero.c b/src/sysdeps/tryexplicit_bzero.c new file mode 100644 index 0000000..869c578 --- /dev/null +++ b/src/sysdeps/tryexplicit_bzero.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ +#endif +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _NETBSD_SOURCE +#define _NETBSD_SOURCE +#endif +#ifndef _INCOMPLETE_XOPEN_C063 +#define _INCOMPLETE_XOPEN_C063 +#endif + +#include <string.h> +#include <strings.h> + +int main (void) +{ + char blah[4] ; + explicit_bzero(blah, 4) ; + return 0 ; +} |