aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libsimple.c33
-rw-r--r--libsimple/mem.h4
l---------man/libsimple_default_failure_exit.31
-rw-r--r--man/libsimple_vweprintf.35
-rw-r--r--mempsetelem.c34
5 files changed, 72 insertions, 5 deletions
diff --git a/libsimple.c b/libsimple.c
index 5d77549..93f7357 100644
--- a/libsimple.c
+++ b/libsimple.c
@@ -2132,6 +2132,39 @@ main(void)
assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n));
}
+ {
+ char p_[4096];
+ char *p = p_;
+
+ memset(p, 0, sizeof(p_));
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 10) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 1, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 2, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 4, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 8, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 16, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 3, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint8_t){0x09}, 1, 3000) == p);
+ assert(libsimple_memsetelem(p, &(uint16_t){0x0807}, 2, 1000) == p);
+ assert(libsimple_memsetelem(p, &(uint32_t){0x10203040UL}, 4, 300) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){0x0102030450607080ULL}, 8, 100) == p);
+ assert(libsimple_memsetelem(p, (char []){0xA0, 0xB0, 0xC0}, 3, 16) == p);
+
+ for (i = 0; i < 48; i++)
+ assert(p[i] == ((char []){0xA0, 0xB0, 0xC0})[i % 3]);
+ for (; i < 800; i += 8)
+ assert(*(uint64_t *)&p[i] == 0x0102030450607080ULL);
+ for (; i < 1200; i += 4)
+ assert(*(uint32_t *)&p[i] == 0x10203040UL);
+ for (; i < 2000; i += 2)
+ assert(*(uint16_t *)&p[i] == 0x0807);
+ for (; i < 3000; i++)
+ assert(p[i] == 0x09);
+ for (; i < sizeof(p_); i++)
+ assert(p[i] == 0);
+ }
+
if (!have_custom_malloc()) {
stderr_real = 1;
fprintf(stderr, "\nSome tests have not been ran because malloc(3) was not "
diff --git a/libsimple/mem.h b/libsimple/mem.h
index 57a1f2b..b50e714 100644
--- a/libsimple/mem.h
+++ b/libsimple/mem.h
@@ -420,8 +420,8 @@ void *libsimple_mempsetelem(void *__buf, const void *__item, size_t __size, size
* @return `buf`
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__)))
-static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t __size, size_t __nitems) /* TODO test */
-{ return libsimple_mempsetelem(__buf, __item, __size, __nitems), __buf; }
+static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t __size, size_t __nitems)
+{ return __item = libsimple_mempsetelem(__buf, __item, __size, __nitems), __buf; }
#ifndef memsetelem
# define memsetelem libsimple_memsetelem
#endif
diff --git a/man/libsimple_default_failure_exit.3 b/man/libsimple_default_failure_exit.3
new file mode 120000
index 0000000..39ff456
--- /dev/null
+++ b/man/libsimple_default_failure_exit.3
@@ -0,0 +1 @@
+libsimple_vweprintf.3 \ No newline at end of file
diff --git a/man/libsimple_vweprintf.3 b/man/libsimple_vweprintf.3
index ef2bedd..ca241b1 100644
--- a/man/libsimple_vweprintf.3
+++ b/man/libsimple_vweprintf.3
@@ -1,10 +1,12 @@
-.TH LIBSIMPLE_VWEPRINTF 3 2018-11-05 libsimple
+.TH LIBSIMPLE_VWEPRINTF 3 2018-11-06 libsimple
.SH NAME
libsimple_vweprintf \- print an error message
.SH SYNOPSIS
.nf
#include <libsimple.h>
+extern int libsimple_default_failure_exit;
+
void libsimple_vweprintf(const char *\fIfmt\fP, va_list \fIap\fP);
static inline void libsimple_weprintf(const char *\fIfmt\fP, ...);
static inline void libsimple_venprintf(int \fIstatus\fP, const char *\fIfmt\fP, va_list \fIap\fP);
@@ -173,7 +175,6 @@ None.
.SH BUGS
None.
.SH SEE ALSO
-.BR libsimple_vweprintf (3),
.BR perror (3),
.BR fprintf (3),
.BR exit (3)
diff --git a/mempsetelem.c b/mempsetelem.c
index c8990ed..6759579 100644
--- a/mempsetelem.c
+++ b/mempsetelem.c
@@ -4,7 +4,7 @@
void *
-libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems) /* TODO test */
+libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems)
{
switch (size) {
case 0:
@@ -54,6 +54,38 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems)
int
main(void)
{
+ char buf_[4096];
+ char *buf = buf_;
+ size_t i;
+
+ memset(buf, 0, sizeof(buf_));
+ assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 0, 0) == &buf[0]);
+ assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 0, 10) == &buf[0]);
+ assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 1, 0) == &buf[0]);
+ assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 2, 0) == &buf[0]);
+ assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 4, 0) == &buf[0]);
+ assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 8, 0) == &buf[0]);
+ assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 16, 0) == &buf[0]);
+ assert(libsimple_mempsetelem(buf, &(uint64_t){~0}, 3, 0) == &buf[0]);
+ assert(libsimple_mempsetelem(buf, &(uint8_t){0x09}, 1, 3000) == &buf[3000]);
+ assert(libsimple_mempsetelem(buf, &(uint16_t){0x0807}, 2, 1000) == &buf[2000]);
+ assert(libsimple_mempsetelem(buf, &(uint32_t){0x10203040UL}, 4, 300) == &buf[1200]);
+ assert(libsimple_mempsetelem(buf, &(uint64_t){0x0102030450607080ULL}, 8, 100) == &buf[800]);
+ assert(libsimple_mempsetelem(buf, (char []){0xA0, 0xB0, 0xC0}, 3, 16) == &buf[48]);
+
+ for (i = 0; i < 48; i++)
+ assert(buf[i] == ((char []){0xA0, 0xB0, 0xC0})[i % 3]);
+ for (; i < 800; i += 8)
+ assert(*(uint64_t *)&buf[i] == 0x0102030450607080ULL);
+ for (; i < 1200; i += 4)
+ assert(*(uint32_t *)&buf[i] == 0x10203040UL);
+ for (; i < 2000; i += 2)
+ assert(*(uint16_t *)&buf[i] == 0x0807);
+ for (; i < 3000; i++)
+ assert(buf[i] == 0x09);
+ for (; i < sizeof(buf_); i++)
+ assert(buf[i] == 0);
+
return 0;
}