aboutsummaryrefslogblamecommitdiffstats
path: root/libsimple.c
blob: a2ae4bc1ac30865453c7665dd3d00d8bca5d7c64 (plain) (tree)
1
2
3
4
5
6
7
8
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790

                                                         
            

 


                 







                                                                                            

                                     

                                            

                                           

                                               

                                   
 

                                                             



                                                    

                                    











                                                                                           

                                     

                                           

                                        

                                              

                                   

                                               

                                   



                                                    

                                    



                 














                                                              


          
                                        
                  

                                     
                       
                           
                           
                    
                         
                       

                         
 

                                                    

























































































































































































                                                                      
                                          











                                                   






























                                                       















                                                      













































                                                          










                                                       






























                                                           















                                                          































































































































































































                                                              































































                                                                 
                                                                





                                                                


                                 















                                                                        

                                








                                                     

         

























































































































































































































                                                                         

      


                                          


                                                            






                                                        


                                                           



                                                        























                                                                                                                





















                                                                       





































































































































































































































                                                        




                                                    
                                                                       







                                                    
                                                                       







                                                    
                                                                       







                                                    
                                                                       







                                                       
                                                                       







                                                       







                                                                       
                                          








                                                                       
                                          



                                                                       






                                                                           
                                                           










                                                                            
                                                           

                                                                       

                  
                   
 



                                                            
                                          









                                                                       
                                          









                                                                        
                                          



















































                                                                                  
                                          








                                                                         
                                          








                                                                         
                                          








                                                                         
                                          









                                                                         
                                          









                                                                         
                                          









                                                                         
                                          









                                                                         
                                          









                                                                         
                                          









                                                                         
                                                 









                                                                       
                                                 









                                                                        
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 























                                                                          
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 









                                                                       
                                                 























                                                                           
                                                 








                                                                         
                                                 








                                                                         
                                                 








                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 








                                                                         
                                                 








                                                                         
                                                 








                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 









                                                                         
                                                 





                                                                         

































                                                                             

















                                                                                                        





















































































































































                                                                                            

         



























































                                                                                 




                                                        











                                                            




                                                                  













                                                                      







































                                                                                                     













































                                                                                                                                      
































                                                                                                 
































































































































































































































































































































































































                                                                            




                                                                                              



                 
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"
#ifndef TEST


#else
#include "test.h"

static int
test_timespec(double d, time_t sec, long int nsec, double rd, const char *s, const char *ss)
{
	char buf[1000], *str;
	struct timespec t;
	double dt;

	libsimple_doubletotimespec(&t, d);
	subassert(t.tv_sec == sec);
	subassert(t.tv_nsec == nsec);

	dt = libsimple_timespectodouble(&t);
	subassert(dt >= rd - 0.0000000001);
	subassert(dt <= rd + 0.0000000001);

	str = libsimple_timespectostr(buf, &t);
	subassert(str == buf);
	subassert(!strcmp(str, s));

	subassert((str = libsimple_timespectostr(NULL, &t)));
	subassert(!strcmp(str, s));

	strcpy(buf, str);
	free(str);
	str = libsimple_minimise_number_string(buf);
	subassert(str == buf);
	subassert(!strcmp(str, ss));

	return 1;
}

static int
test_timeval(double d, time_t sec, long int usec, double rd, const char *s, const char *ss)
{
	char buf[1000], *str;
	struct timeval t;
	double dt;

	libsimple_doubletotimeval(&t, d);
	subassert(t.tv_sec == sec);
	subassert(t.tv_usec == usec);

	dt = libsimple_timevaltodouble(&t);
	subassert(dt >= rd - 0.0000001);
	subassert(dt <= rd + 0.0000001);

	str = libsimple_timevaltostr(buf, &t);
	subassert(str == buf);
	subassert(!strcmp(str, s));

	str = libsimple_timevaltostr(NULL, &t);
	subassert(str);
	subassert(!strcmp(str, s));

	strcpy(buf, str);
	free(str);
	str = libsimple_minimise_number_string(buf);
	subassert(str == buf);
	subassert(!strcmp(str, ss));

	return 1;
}

#ifdef libsimple_vasprintfa
static int
test_vasprintfa(const char *expected, const char *format, ...)
{
	char *s;
	va_list ap;
	va_start(ap, format);
	s = libsimple_vasprintfa(format, ap);
	subassert(s);
	subassert(!strcmp(s, expected));
	va_end(ap);
	return 1;
}
#endif

int
main(void)
{
	struct allocinfo *volatile info;
	void *ptr;
	struct timespec ts, ts1, ts2;
	struct timeval tv1, tv2;
	const char *cs;
	const wchar_t *cws;
	char buf[1024], *s;
	wchar_t *ws;
	int intarray[10];
	size_t i, j, n;
	DEFINE_PAGESIZE;
	DEFINE_CACHELINE;

	assert(libsimple_default_failure_exit == 1);

	assert(MIN(1, 3) == 1);
	assert(MIN(1, 1) == 1);
	assert(MIN(3, 1) == 1);
	assert(MIN(1, -3) == -3);
	assert(MIN(1, -1) == -1);
	assert(MIN(3, -1) == -1);
	assert(MIN(-1, 3) == -1);
	assert(MIN(-1, 1) == -1);
	assert(MIN(-3, 1) == -3);
	assert(MIN(-1, -3) == -3);
	assert(MIN(-1, -1) == -1);
	assert(MIN(-3, -1) == -3);

	assert(MAX(1, 3) == 3);
	assert(MAX(1, 1) == 1);
	assert(MAX(3, 1) == 3);
	assert(MAX(1, -3) == 1);
	assert(MAX(1, -1) == 1);
	assert(MAX(3, -1) == 3);
	assert(MAX(-1, 3) == 3);
	assert(MAX(-1, 1) == 1);
	assert(MAX(-3, 1) == 1);
	assert(MAX(-1, -3) == -1);
	assert(MAX(-1, -1) == -1);
	assert(MAX(-3, -1) == -1);

	assert(MIN3(1, 2, 3) == 1);
	assert(MIN3(1, 3, 2) == 1);
	assert(MIN3(2, 1, 3) == 1);
	assert(MIN3(2, 3, 1) == 1);
	assert(MIN3(3, 1, 2) == 1);
	assert(MIN3(3, 2, 1) == 1);
	assert(MIN3(1, 2, -3) == -3);
	assert(MIN3(1, 3, -2) == -2);
	assert(MIN3(2, 1, -3) == -3);
	assert(MIN3(2, 3, -1) == -1);
	assert(MIN3(3, 1, -2) == -2);
	assert(MIN3(3, 2, -1) == -1);
	assert(MIN3(1, -2, 3) == -2);
	assert(MIN3(1, -3, 2) == -3);
	assert(MIN3(2, -1, 3) == -1);
	assert(MIN3(2, -3, 1) == -3);
	assert(MIN3(3, -1, 2) == -1);
	assert(MIN3(3, -2, 1) == -2);
	assert(MIN3(1, -2, -3) == -3);
	assert(MIN3(1, -3, -2) == -3);
	assert(MIN3(2, -1, -3) == -3);
	assert(MIN3(2, -3, -1) == -3);
	assert(MIN3(3, -1, -2) == -2);
	assert(MIN3(3, -2, -1) == -2);
	assert(MIN3(-1, 2, 3) == -1);
	assert(MIN3(-1, 3, 2) == -1);
	assert(MIN3(-2, 1, 3) == -2);
	assert(MIN3(-2, 3, 1) == -2);
	assert(MIN3(-3, 1, 2) == -3);
	assert(MIN3(-3, 2, 1) == -3);
	assert(MIN3(-1, 2, -3) == -3);
	assert(MIN3(-1, 3, -2) == -2);
	assert(MIN3(-2, 1, -3) == -3);
	assert(MIN3(-2, 3, -1) == -2);
	assert(MIN3(-3, 1, -2) == -3);
	assert(MIN3(-3, 2, -1) == -3);
	assert(MIN3(-1, -2, 3) == -2);
	assert(MIN3(-1, -3, 2) == -3);
	assert(MIN3(-2, -1, 3) == -2);
	assert(MIN3(-2, -3, 1) == -3);
	assert(MIN3(-3, -1, 2) == -3);
	assert(MIN3(-3, -2, 1) == -3);
	assert(MIN3(-1, -2, -3) == -3);
	assert(MIN3(-1, -3, -2) == -3);
	assert(MIN3(-2, -1, -3) == -3);
	assert(MIN3(-2, -3, -1) == -3);
	assert(MIN3(-3, -1, -2) == -3);
	assert(MIN3(-3, -2, -1) == -3);

	assert(MAX3(1, 2, 3) == 3);
	assert(MAX3(1, 3, 2) == 3);
	assert(MAX3(2, 1, 3) == 3);
	assert(MAX3(2, 3, 1) == 3);
	assert(MAX3(3, 1, 2) == 3);
	assert(MAX3(3, 2, 1) == 3);
	assert(MAX3(1, 2, -3) == 2);
	assert(MAX3(1, 3, -2) == 3);
	assert(MAX3(2, 1, -3) == 2);
	assert(MAX3(2, 3, -1) == 3);
	assert(MAX3(3, 1, -2) == 3);
	assert(MAX3(3, 2, -1) == 3);
	assert(MAX3(1, -2, 3) == 3);
	assert(MAX3(1, -3, 2) == 2);
	assert(MAX3(2, -1, 3) == 3);
	assert(MAX3(2, -3, 1) == 2);
	assert(MAX3(3, -1, 2) == 3);
	assert(MAX3(3, -2, 1) == 3);
	assert(MAX3(1, -2, -3) == 1);
	assert(MAX3(1, -3, -2) == 1);
	assert(MAX3(2, -1, -3) == 2);
	assert(MAX3(2, -3, -1) == 2);
	assert(MAX3(3, -1, -2) == 3);
	assert(MAX3(3, -2, -1) == 3);
	assert(MAX3(-1, 2, 3) == 3);
	assert(MAX3(-1, 3, 2) == 3);
	assert(MAX3(-2, 1, 3) == 3);
	assert(MAX3(-2, 3, 1) == 3);
	assert(MAX3(-3, 1, 2) == 2);
	assert(MAX3(-3, 2, 1) == 2);
	assert(MAX3(-1, 2, -3) == 2);
	assert(MAX3(-1, 3, -2) == 3);
	assert(MAX3(-2, 1, -3) == 1);
	assert(MAX3(-2, 3, -1) == 3);
	assert(MAX3(-3, 1, -2) == 1);
	assert(MAX3(-3, 2, -1) == 2);
	assert(MAX3(-1, -2, 3) == 3);
	assert(MAX3(-1, -3, 2) == 2);
	assert(MAX3(-2, -1, 3) == 3);
	assert(MAX3(-2, -3, 1) == 1);
	assert(MAX3(-3, -1, 2) == 2);
	assert(MAX3(-3, -2, 1) == 1);
	assert(MAX3(-1, -2, -3) == -1);
	assert(MAX3(-1, -3, -2) == -1);
	assert(MAX3(-2, -1, -3) == -1);
	assert(MAX3(-2, -3, -1) == -1);
	assert(MAX3(-3, -1, -2) == -1);
	assert(MAX3(-3, -2, -1) == -1);

	assert(ELEMSOF((char [1]){}) == 1);
	assert(ELEMSOF((char [2]){}) == 2);
	assert(ELEMSOF((char [3]){}) == 3);
	assert(ELEMSOF((short int [3]){}) == 3);
	assert(ELEMSOF((int [3]){}) == 3);
	assert(ELEMSOF((long int [3]){}) == 3);
	assert(ELEMSOF((float [3]){}) == 3);
	assert(ELEMSOF((double [3]){}) == 3);

	assert(STRLEN("") == 0);
	assert(STRLEN("a") == 1);
	assert(STRLEN("aa") == 2);
	assert(STRLEN("abc") == 3);
	assert(STRLEN("a\0bc") == 4);
	assert(STRLEN("\0\0\0\0\0") == 5);

#if defined(__GNUC__) && !defined(__clang__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wtype-limits"
#endif
	assert(INTSTRLEN(int8_t)   == 4);
	assert(INTSTRLEN(uint8_t)  == 3);
	assert(INTSTRLEN(int16_t)  == 6);
	assert(INTSTRLEN(uint16_t) == 5);
	assert(INTSTRLEN(int32_t)  == 11);
	assert(INTSTRLEN(uint32_t) == 10);
	assert(INTSTRLEN(int64_t)  == 20 || INTSTRLEN(int64_t) == 21);
	assert(INTSTRLEN(uint64_t) == 20);
#if defined(__GNUC__) && !defined(__clang__)
# pragma GCC diagnostic pop
#endif

	assert(TYPE_MAX(int8_t)   == INT8_MAX);
	assert(TYPE_MAX(uint8_t)  == UINT8_MAX);
	assert(TYPE_MAX(int16_t)  == INT16_MAX);
	assert(TYPE_MAX(uint16_t) == UINT16_MAX);
	assert(TYPE_MAX(int32_t)  == INT32_MAX);
	assert(TYPE_MAX(uint32_t) == UINT32_MAX);
	assert(TYPE_MAX(int64_t)  == INT64_MAX);
	assert(TYPE_MAX(uint64_t) == UINT64_MAX);

	assert(TYPE_MIN(int8_t)   == INT8_MIN);
	assert(TYPE_MIN(uint8_t)  == 0);
	assert(TYPE_MIN(int16_t)  == INT16_MIN);
	assert(TYPE_MIN(uint16_t) == 0);
	assert(TYPE_MIN(int32_t)  == INT32_MIN);
	assert(TYPE_MIN(uint32_t) == 0);
	assert(TYPE_MIN(int64_t)  == INT64_MIN);
	assert(TYPE_MIN(uint64_t) == 0);

	assert(strcmpnul(libsimple_strend("abc\0xyz"), "xyz"));

	assert(libsimple_inchrset('a', "xyz") == 0);
	assert(libsimple_inchrset('b', "xyz") == 0);
	assert(libsimple_inchrset('c', "xyz") == 0);
	assert(libsimple_inchrset('x', "xyz") == 1);
	assert(libsimple_inchrset('y', "xyz") == 1);
	assert(libsimple_inchrset('z', "xyz") == 1);
	assert(libsimple_inchrset('\0', "xyz") == 0);

	stpcpy(buf, "abcxyz");
	assert(libsimple_mempcpy(buf, "123", 3) == &buf[3]);
	assert(!strcmpnul(buf, "123xyz"));

	assert(libsimple_streq("abc", "abc") == 1);
	assert(libsimple_streq("abc", "ab") == 0);
	assert(libsimple_streq("ab", "abc") == 0);
	assert(libsimple_streq("ab", "xy") == 0);
	assert(libsimple_streq("xy", "ab") == 0);
	assert(libsimple_streq("", "1") == 0);
	assert(libsimple_streq("1", "") == 0);
	assert(libsimple_streq("", "") == 1);
	assert(libsimple_streq("abc", "ABC") == 0);
	assert(libsimple_streq("ABC", "abc") == 0);

	assert(libsimple_strneq("abc", "abc", 5) == 1);
	assert(libsimple_strneq("abc", "ab", 5) == 0);
	assert(libsimple_strneq("ab", "abc", 5) == 0);
	assert(libsimple_strneq("ab", "xy", 5) == 0);
	assert(libsimple_strneq("xy", "ab", 5) == 0);
	assert(libsimple_strneq("", "1", 5) == 0);
	assert(libsimple_strneq("1", "", 5) == 0);
	assert(libsimple_strneq("", "", 5) == 1);
	assert(libsimple_strneq("abc", "ABC", 5) == 0);
	assert(libsimple_strneq("ABC", "abc", 5) == 0);
	assert(libsimple_strneq("abc", "abc", 1) == 1);
	assert(libsimple_strneq("abc", "ab", 1) == 1);
	assert(libsimple_strneq("ab", "abc", 1) == 1);
	assert(libsimple_strneq("ab", "xy", 1) == 0);
	assert(libsimple_strneq("xy", "ab", 1) == 0);
	assert(libsimple_strneq("", "1", 1) == 0);
	assert(libsimple_strneq("1", "", 1) == 0);
	assert(libsimple_strneq("", "", 1) == 1);
	assert(libsimple_strneq("abc", "ABC", 1) == 0);
	assert(libsimple_strneq("ABC", "abc", 1) == 0);
	assert(libsimple_strneq("abc", "abc", 0) == 1);
	assert(libsimple_strneq("abc", "ab", 0) == 1);
	assert(libsimple_strneq("ab", "abc", 0) == 1);
	assert(libsimple_strneq("ab", "xy", 0) == 1);
	assert(libsimple_strneq("xy", "ab", 0) == 1);
	assert(libsimple_strneq("", "1", 0) == 1);
	assert(libsimple_strneq("1", "", 0) == 1);
	assert(libsimple_strneq("", "", 0) == 1);
	assert(libsimple_strneq("abc", "ABC", 0) == 1);
	assert(libsimple_strneq("ABC", "abc", 0) == 1);

	assert(libsimple_streqnul("abc", "abc") == 1);
	assert(libsimple_streqnul("abc", "ab") == 0);
	assert(libsimple_streqnul("ab", "abc") == 0);
	assert(libsimple_streqnul("ab", "xy") == 0);
	assert(libsimple_streqnul("xy", "ab") == 0);
	assert(libsimple_streqnul("", "1") == 0);
	assert(libsimple_streqnul("1", "") == 0);
	assert(libsimple_streqnul("", "") == 1);
	assert(libsimple_streqnul("abc", "ABC") == 0);
	assert(libsimple_streqnul("ABC", "abc") == 0);
	assert(libsimple_streqnul("", NULL) == 0);
	assert(libsimple_streqnul("1", NULL) == 0);
	assert(libsimple_streqnul(NULL, "") == 0);
	assert(libsimple_streqnul(NULL, "1") == 0);
	assert(libsimple_streqnul(NULL, NULL) == 1);

	assert(libsimple_strneqnul("abc", "abc", 5) == 1);
	assert(libsimple_strneqnul("abc", "ab", 5) == 0);
	assert(libsimple_strneqnul("ab", "abc", 5) == 0);
	assert(libsimple_strneqnul("ab", "xy", 5) == 0);
	assert(libsimple_strneqnul("xy", "ab", 5) == 0);
	assert(libsimple_strneqnul("", "1", 5) == 0);
	assert(libsimple_strneqnul("1", "", 5) == 0);
	assert(libsimple_strneqnul("", "", 5) == 1);
	assert(libsimple_strneqnul("abc", "ABC", 5) == 0);
	assert(libsimple_strneqnul("ABC", "abc", 5) == 0);
	assert(libsimple_strneqnul("", NULL, 5) == 0);
	assert(libsimple_strneqnul("1", NULL, 5) == 0);
	assert(libsimple_strneqnul(NULL, "", 5) == 0);
	assert(libsimple_strneqnul(NULL, "1", 5) == 0);
	assert(libsimple_strneqnul(NULL, NULL, 5) == 1);
	assert(libsimple_strneqnul("abc", "abc", 1) == 1);
	assert(libsimple_strneqnul("abc", "ab", 1) == 1);
	assert(libsimple_strneqnul("ab", "abc", 1) == 1);
	assert(libsimple_strneqnul("ab", "xy", 1) == 0);
	assert(libsimple_strneqnul("xy", "ab", 1) == 0);
	assert(libsimple_strneqnul("", "1", 1) == 0);
	assert(libsimple_strneqnul("1", "", 1) == 0);
	assert(libsimple_strneqnul("", "", 1) == 1);
	assert(libsimple_strneqnul("abc", "ABC", 1) == 0);
	assert(libsimple_strneqnul("ABC", "abc", 1) == 0);
	assert(libsimple_strneqnul("", NULL, 1) == 0);
	assert(libsimple_strneqnul("1", NULL, 1) == 0);
	assert(libsimple_strneqnul(NULL, "", 1) == 0);
	assert(libsimple_strneqnul(NULL, "1", 1) == 0);
	assert(libsimple_strneqnul(NULL, NULL, 1) == 1);
	assert(libsimple_strneqnul("abc", "abc", 0) == 1);
	assert(libsimple_strneqnul("abc", "ab", 0) == 1);
	assert(libsimple_strneqnul("ab", "abc", 0) == 1);
	assert(libsimple_strneqnul("ab", "xy", 0) == 1);
	assert(libsimple_strneqnul("xy", "ab", 0) == 1);
	assert(libsimple_strneqnul("", "1", 0) == 1);
	assert(libsimple_strneqnul("1", "", 0) == 1);
	assert(libsimple_strneqnul("", "", 0) == 1);
	assert(libsimple_strneqnul("abc", "ABC", 0) == 1);
	assert(libsimple_strneqnul("ABC", "abc", 0) == 1);
	assert(libsimple_strneqnul("", NULL, 0) == 0);
	assert(libsimple_strneqnul("1", NULL, 0) == 0);
	assert(libsimple_strneqnul(NULL, "", 0) == 0);
	assert(libsimple_strneqnul(NULL, "1", 0) == 0);
	assert(libsimple_strneqnul(NULL, NULL, 0) == 1);

	assert(libsimple_strcaseeq("abc", "abc") == 1);
	assert(libsimple_strcaseeq("abc", "ab") == 0);
	assert(libsimple_strcaseeq("ab", "abc") == 0);
	assert(libsimple_strcaseeq("ab", "xy") == 0);
	assert(libsimple_strcaseeq("xy", "ab") == 0);
	assert(libsimple_strcaseeq("", "1") == 0);
	assert(libsimple_strcaseeq("1", "") == 0);
	assert(libsimple_strcaseeq("", "") == 1);
	assert(libsimple_strcaseeq("abc", "ABC") == 1);
	assert(libsimple_strcaseeq("ABC", "abc") == 1);

	assert(libsimple_strncaseeq("abc", "abc", 5) == 1);
	assert(libsimple_strncaseeq("abc", "ab", 5) == 0);
	assert(libsimple_strncaseeq("ab", "abc", 5) == 0);
	assert(libsimple_strncaseeq("ab", "xy", 5) == 0);
	assert(libsimple_strncaseeq("xy", "ab", 5) == 0);
	assert(libsimple_strncaseeq("", "1", 5) == 0);
	assert(libsimple_strncaseeq("1", "", 5) == 0);
	assert(libsimple_strncaseeq("", "", 5) == 1);
	assert(libsimple_strncaseeq("abc", "ABC", 5) == 1);
	assert(libsimple_strncaseeq("ABC", "abc", 5) == 1);
	assert(libsimple_strncaseeq("abc", "abc", 1) == 1);
	assert(libsimple_strncaseeq("abc", "ab", 1) == 1);
	assert(libsimple_strncaseeq("ab", "abc", 1) == 1);
	assert(libsimple_strncaseeq("ab", "xy", 1) == 0);
	assert(libsimple_strncaseeq("xy", "ab", 1) == 0);
	assert(libsimple_strncaseeq("", "1", 1) == 0);
	assert(libsimple_strncaseeq("1", "", 1) == 0);
	assert(libsimple_strncaseeq("", "", 1) == 1);
	assert(libsimple_strncaseeq("abc", "ABC", 1) == 1);
	assert(libsimple_strncaseeq("ABC", "abc", 1) == 1);
	assert(libsimple_strncaseeq("abc", "abc", 0) == 1);
	assert(libsimple_strncaseeq("abc", "ab", 0) == 1);
	assert(libsimple_strncaseeq("ab", "abc", 0) == 1);
	assert(libsimple_strncaseeq("ab", "xy", 0) == 1);
	assert(libsimple_strncaseeq("xy", "ab", 0) == 1);
	assert(libsimple_strncaseeq("", "1", 0) == 1);
	assert(libsimple_strncaseeq("1", "", 0) == 1);
	assert(libsimple_strncaseeq("", "", 0) == 1);
	assert(libsimple_strncaseeq("abc", "ABC", 0) == 1);
	assert(libsimple_strncaseeq("ABC", "abc", 0) == 1);

	assert(libsimple_strcaseeqnul("abc", "abc") == 1);
	assert(libsimple_strcaseeqnul("abc", "ab") == 0);
	assert(libsimple_strcaseeqnul("ab", "abc") == 0);
	assert(libsimple_strcaseeqnul("ab", "xy") == 0);
	assert(libsimple_strcaseeqnul("xy", "ab") == 0);
	assert(libsimple_strcaseeqnul("", "1") == 0);
	assert(libsimple_strcaseeqnul("1", "") == 0);
	assert(libsimple_strcaseeqnul("", "") == 1);
	assert(libsimple_strcaseeqnul("abc", "ABC") == 1);
	assert(libsimple_strcaseeqnul("ABC", "abc") == 1);
	assert(libsimple_strcaseeqnul("", NULL) == 0);
	assert(libsimple_strcaseeqnul("1", NULL) == 0);
	assert(libsimple_strcaseeqnul(NULL, "") == 0);
	assert(libsimple_strcaseeqnul(NULL, "1") == 0);
	assert(libsimple_strcaseeqnul(NULL, NULL) == 1);

	assert(libsimple_strncaseeqnul("abc", "abc", 5) == 1);
	assert(libsimple_strncaseeqnul("abc", "ab", 5) == 0);
	assert(libsimple_strncaseeqnul("ab", "abc", 5) == 0);
	assert(libsimple_strncaseeqnul("ab", "xy", 5) == 0);
	assert(libsimple_strncaseeqnul("xy", "ab", 5) == 0);
	assert(libsimple_strncaseeqnul("", "1", 5) == 0);
	assert(libsimple_strncaseeqnul("1", "", 5) == 0);
	assert(libsimple_strncaseeqnul("", "", 5) == 1);
	assert(libsimple_strncaseeqnul("abc", "ABC", 5) == 1);
	assert(libsimple_strncaseeqnul("ABC", "abc", 5) == 1);
	assert(libsimple_strncaseeqnul("", NULL, 5) == 0);
	assert(libsimple_strncaseeqnul("1", NULL, 5) == 0);
	assert(libsimple_strncaseeqnul(NULL, "", 5) == 0);
	assert(libsimple_strncaseeqnul(NULL, "1", 5) == 0);
	assert(libsimple_strncaseeqnul(NULL, NULL, 5) == 1);
	assert(libsimple_strncaseeqnul("abc", "abc", 1) == 1);
	assert(libsimple_strncaseeqnul("abc", "ab", 1) == 1);
	assert(libsimple_strncaseeqnul("ab", "abc", 1) == 1);
	assert(libsimple_strncaseeqnul("ab", "xy", 1) == 0);
	assert(libsimple_strncaseeqnul("xy", "ab", 1) == 0);
	assert(libsimple_strncaseeqnul("", "1", 1) == 0);
	assert(libsimple_strncaseeqnul("1", "", 1) == 0);
	assert(libsimple_strncaseeqnul("", "", 1) == 1);
	assert(libsimple_strncaseeqnul("abc", "ABC", 1) == 1);
	assert(libsimple_strncaseeqnul("ABC", "abc", 1) == 1);
	assert(libsimple_strncaseeqnul("", NULL, 1) == 0);
	assert(libsimple_strncaseeqnul("1", NULL, 1) == 0);
	assert(libsimple_strncaseeqnul(NULL, "", 1) == 0);
	assert(libsimple_strncaseeqnul(NULL, "1", 1) == 0);
	assert(libsimple_strncaseeqnul(NULL, NULL, 1) == 1);
	assert(libsimple_strncaseeqnul("abc", "abc", 0) == 1);
	assert(libsimple_strncaseeqnul("abc", "ab", 0) == 1);
	assert(libsimple_strncaseeqnul("ab", "abc", 0) == 1);
	assert(libsimple_strncaseeqnul("ab", "xy", 0) == 1);
	assert(libsimple_strncaseeqnul("xy", "ab", 0) == 1);
	assert(libsimple_strncaseeqnul("", "1", 0) == 1);
	assert(libsimple_strncaseeqnul("1", "", 0) == 1);
	assert(libsimple_strncaseeqnul("", "", 0) == 1);
	assert(libsimple_strncaseeqnul("abc", "ABC", 0) == 1);
	assert(libsimple_strncaseeqnul("ABC", "abc", 0) == 1);
	assert(libsimple_strncaseeqnul("", NULL, 0) == 0);
	assert(libsimple_strncaseeqnul("1", NULL, 0) == 0);
	assert(libsimple_strncaseeqnul(NULL, "", 0) == 0);
	assert(libsimple_strncaseeqnul(NULL, "1", 0) == 0);
	assert(libsimple_strncaseeqnul(NULL, NULL, 0) == 1);

	for (i = 0, n = 10; i < n; i++)
		buf[i] = i;
	LIBSIMPLE_UNLIST(buf, 4, &n);
	LIBSIMPLE_UNLIST(buf, 9 - 1, &n);
	LIBSIMPLE_UNLIST(buf, 6 - 1, &n);
	assert(n == 7);
	assert(buf[0] == 0);
	assert(buf[1] == 1);
	assert(buf[2] == 2);
	assert(buf[3] == 3);
	assert(buf[4] == 5);
	assert(buf[5] == 7);
	assert(buf[6] == 8);

	for (i = 0, n = 10; i < n; i++)
		intarray[i] = i;
	LIBSIMPLE_UNLIST(intarray, 4, &n);
	LIBSIMPLE_UNLIST(intarray, 9 - 1, &n);
	LIBSIMPLE_UNLIST(intarray, 6 - 1, &n);
	assert(n == 7);
	assert(intarray[0] == 0);
	assert(intarray[1] == 1);
	assert(intarray[2] == 2);
	assert(intarray[3] == 3);
	assert(intarray[4] == 5);
	assert(intarray[5] == 7);
	assert(intarray[6] == 8);

	assert(libsimple_strcmpnul(NULL, NULL) == 0);
	assert(libsimple_strcmpnul(NULL, "") < 0);
	assert(libsimple_strcmpnul("", NULL) > 0);
	assert(libsimple_strcmpnul("", "") == 0);
	assert(libsimple_strcmpnul(NULL, "x") < 0);
	assert(libsimple_strcmpnul("x", NULL) > 0);
	assert(libsimple_strcmpnul("x", "x") == 0);
	assert(libsimple_strcmpnul("a", "b") < 0);
	assert(libsimple_strcmpnul("b", "a") > 0);
	assert(libsimple_strcmpnul("aa", "ab") < 0);
	assert(libsimple_strcmpnul("ab", "aa") > 0);
	assert(libsimple_strcmpnul("aa", "aa") == 0);
	assert(libsimple_strcmpnul("A", "a") < 0);
	assert(libsimple_strcmpnul("a", "A") > 0);
	assert(libsimple_strcmpnul("AA", "Aa") < 0);
	assert(libsimple_strcmpnul("Aa", "AA") > 0);
	assert(libsimple_strcmpnul("AA", "AA") == 0);

	assert(libsimple_strcasecmpnul(NULL, NULL) == 0);
	assert(libsimple_strcasecmpnul(NULL, "") < 0);
	assert(libsimple_strcasecmpnul("", NULL) > 0);
	assert(libsimple_strcasecmpnul("", "") == 0);
	assert(libsimple_strcasecmpnul(NULL, "x") < 0);
	assert(libsimple_strcasecmpnul("x", NULL) > 0);
	assert(libsimple_strcasecmpnul("x", "x") == 0);
	assert(libsimple_strcasecmpnul("a", "b") < 0);
	assert(libsimple_strcasecmpnul("b", "a") > 0);
	assert(libsimple_strcasecmpnul("aa", "ab") < 0);
	assert(libsimple_strcasecmpnul("ab", "aa") > 0);
	assert(libsimple_strcasecmpnul("aa", "aa") == 0);
	assert(libsimple_strcasecmpnul("A", "a") == 0);
	assert(libsimple_strcasecmpnul("a", "A") == 0);
	assert(libsimple_strcasecmpnul("AA", "Aa") == 0);
	assert(libsimple_strcasecmpnul("Aa", "AA") == 0);
	assert(libsimple_strcasecmpnul("AA", "AA") == 0);

	assert(libsimple_strncmpnul(NULL, NULL, 5) == 0);
	assert(libsimple_strncmpnul(NULL, "", 5) < 0);
	assert(libsimple_strncmpnul("", NULL, 5) > 0);
	assert(libsimple_strncmpnul("", "", 5) == 0);
	assert(libsimple_strncmpnul(NULL, "x", 5) < 0);
	assert(libsimple_strncmpnul("x", NULL, 5) > 0);
	assert(libsimple_strncmpnul("x", "x", 5) == 0);
	assert(libsimple_strncmpnul("a", "b", 5) < 0);
	assert(libsimple_strncmpnul("b", "a", 5) > 0);
	assert(libsimple_strncmpnul("aa", "ab", 5) < 0);
	assert(libsimple_strncmpnul("ab", "aa", 5) > 0);
	assert(libsimple_strncmpnul("aa", "aa", 5) == 0);
	assert(libsimple_strncmpnul("A", "a", 5) < 0);
	assert(libsimple_strncmpnul("a", "A", 5) > 0);
	assert(libsimple_strncmpnul("AA", "Aa", 5) < 0);
	assert(libsimple_strncmpnul("Aa", "AA", 5) > 0);
	assert(libsimple_strncmpnul("AA", "AA", 5) == 0);
	assert(libsimple_strncmpnul("aa", "ab", 1) == 0);
	assert(libsimple_strncmpnul("ab", "aa", 1) == 0);
	assert(libsimple_strncmpnul("aa", "aa", 1) == 0);
	assert(libsimple_strncmpnul("AA", "Aa", 1) == 0);
	assert(libsimple_strncmpnul("Aa", "AA", 1) == 0);
	assert(libsimple_strncmpnul("AA", "AA", 1) == 0);
	assert(libsimple_strncmpnul(NULL, NULL, 0) == 0);
	assert(libsimple_strncmpnul(NULL, "", 0) < 0);
	assert(libsimple_strncmpnul("", NULL, 0) > 0);
	assert(libsimple_strncmpnul("", "", 0) == 0);
	assert(libsimple_strncmpnul(NULL, "x", 0) < 0);
	assert(libsimple_strncmpnul("x", NULL, 0) > 0);
	assert(libsimple_strncmpnul("x", "x", 0) == 0);
	assert(libsimple_strncmpnul("a", "b", 0) == 0);
	assert(libsimple_strncmpnul("b", "a", 0) == 0);
	assert(libsimple_strncmpnul("aa", "ab", 0) == 0);
	assert(libsimple_strncmpnul("ab", "aa", 0) == 0);
	assert(libsimple_strncmpnul("aa", "aa", 0) == 0);
	assert(libsimple_strncmpnul("A", "a", 0) == 0);
	assert(libsimple_strncmpnul("a", "A", 0) == 0);
	assert(libsimple_strncmpnul("AA", "Aa", 0) == 0);
	assert(libsimple_strncmpnul("Aa", "AA", 0) == 0);
	assert(libsimple_strncmpnul("AA", "AA", 0) == 0);

	assert(libsimple_strncasecmpnul(NULL, NULL, 5) == 0);
	assert(libsimple_strncasecmpnul(NULL, "", 5) < 0);
	assert(libsimple_strncasecmpnul("", NULL, 5) > 0);
	assert(libsimple_strncasecmpnul("", "", 5) == 0);
	assert(libsimple_strncasecmpnul(NULL, "x", 5) < 0);
	assert(libsimple_strncasecmpnul("x", NULL, 5) > 0);
	assert(libsimple_strncasecmpnul("x", "x", 5) == 0);
	assert(libsimple_strncasecmpnul("a", "b", 5) < 0);
	assert(libsimple_strncasecmpnul("b", "a", 5) > 0);
	assert(libsimple_strncasecmpnul("aa", "ab", 5) < 0);
	assert(libsimple_strncasecmpnul("ab", "aa", 5) > 0);
	assert(libsimple_strncasecmpnul("aa", "aa", 5) == 0);
	assert(libsimple_strncasecmpnul("A", "a", 5) == 0);
	assert(libsimple_strncasecmpnul("a", "A", 5) == 0);
	assert(libsimple_strncasecmpnul("AA", "Aa", 5) == 0);
	assert(libsimple_strncasecmpnul("Aa", "AA", 5) == 0);
	assert(libsimple_strncasecmpnul("AA", "AA", 5) == 0);
	assert(libsimple_strncasecmpnul("aa", "ab", 1) == 0);
	assert(libsimple_strncasecmpnul("ab", "aa", 1) == 0);
	assert(libsimple_strncasecmpnul("aa", "aa", 1) == 0);
	assert(libsimple_strncasecmpnul("AA", "Aa", 1) == 0);
	assert(libsimple_strncasecmpnul("Aa", "AA", 1) == 0);
	assert(libsimple_strncasecmpnul("AA", "AA", 1) == 0);
	assert(libsimple_strncasecmpnul(NULL, NULL, 0) == 0);
	assert(libsimple_strncasecmpnul(NULL, "", 0) < 0);
	assert(libsimple_strncasecmpnul("", NULL, 0) > 0);
	assert(libsimple_strncasecmpnul("", "", 0) == 0);
	assert(libsimple_strncasecmpnul(NULL, "x", 0) < 0);
	assert(libsimple_strncasecmpnul("x", NULL, 0) > 0);
	assert(libsimple_strncasecmpnul("x", "x", 0) == 0);
	assert(libsimple_strncasecmpnul("a", "b", 0) == 0);
	assert(libsimple_strncasecmpnul("b", "a", 0) == 0);
	assert(libsimple_strncasecmpnul("aa", "ab", 0) == 0);
	assert(libsimple_strncasecmpnul("ab", "aa", 0) == 0);
	assert(libsimple_strncasecmpnul("aa", "aa", 0) == 0);
	assert(libsimple_strncasecmpnul("A", "a", 0) == 0);
	assert(libsimple_strncasecmpnul("a", "A", 0) == 0);
	assert(libsimple_strncasecmpnul("AA", "Aa", 0) == 0);
	assert(libsimple_strncasecmpnul("Aa", "AA", 0) == 0);
	assert(libsimple_strncasecmpnul("AA", "AA", 0) == 0);

#ifdef libsimple_strdupa
	cs = "";
	s = libsimple_strdupa(cs);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, cs));

	cs = "xyz";
	s = libsimple_strdupa(cs);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, cs));
#else
	fprintf(stderr, "warning: libsimple_strdupa missing\n");
#endif

#ifdef libsimple_strndupa
	cs = "";
	s = libsimple_strndupa(cs, 5);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, ""));

	cs = "xyz";

	s = libsimple_strndupa(cs, 5);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, "xyz"));

	s = libsimple_strndupa(cs, 4);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, "xyz"));

	s = libsimple_strndupa(cs, 3);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, "xyz"));

	s = libsimple_strndupa(cs, 2);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, "xy"));

	s = libsimple_strndupa(cs, 1);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, "x"));

	s = libsimple_strndupa(cs, 0);
	assert(s);
	assert(s != cs);
	assert(!strcmp(s, ""));
#else
	fprintf(stderr, "warning: libsimple_strndupa missing\n");
#endif

#ifdef libsimple_memdupa
	cs = "xyz";
	for (n = 1; n < 4; n++) {
		s = libsimple_memdupa(cs, n);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % _Alignof(max_align_t)));
		assert(!memcmp(s, cs, n));
	}
#else
	fprintf(stderr, "warning: libsimple_memdupa missing\n");
#endif

#ifdef libsimple_aligned_memdupa
	cs = "xyz";
	for (n = 1; n < 4; n++) {
		for (i = 1; i < 5; i++) {
			s = libsimple_aligned_memdupa(cs, i, n);
			assert(s);
			assert(s != cs);
			assert(!((uintptr_t)s % i));
			assert(!memcmp(s, cs, n));
		}
	}
#else
	fprintf(stderr, "warning: libsimple_aligned_memdupa missing\n");
#endif

#ifdef libsimple_aligned_strdupa
	for (i = 1; i < 5; i++) {
		cs = "";
		s = libsimple_aligned_strdupa(cs, i);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, cs));

		cs = "xyz";
		s = libsimple_aligned_strdupa(cs, i);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, cs));
	}
#else
	fprintf(stderr, "warning: libsimple_aligned_strdupa missing\n");
#endif

#ifdef libsimple_aligned_strndupa
	for (i = 1; i < 5; i++) {
		cs = "";
		s = libsimple_aligned_strndupa(cs, i, 5);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, ""));

		cs = "xyz";

		s = libsimple_aligned_strndupa(cs, i, 5);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, "xyz"));

		s = libsimple_aligned_strndupa(cs, i, 4);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, "xyz"));

		s = libsimple_aligned_strndupa(cs, i, 3);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, "xyz"));

		s = libsimple_aligned_strndupa(cs, i, 2);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, "xy"));

		s = libsimple_aligned_strndupa(cs, i, 1);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, "x"));

		s = libsimple_aligned_strndupa(cs, i, 0);
		assert(s);
		assert(s != cs);
		assert(!((uintptr_t)s % i));
		assert(!strcmp(s, ""));
	}
#else
	fprintf(stderr, "warning: libsimple_aligned_strndupa missing\n");
#endif

#ifdef libsimple_wcsdupa
	cws = L"";
	ws = libsimple_wcsdupa(cws);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, cws));

	cws = L"xyz";
	ws = libsimple_wcsdupa(cws);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, cws));
#else
	fprintf(stderr, "warning: libsimple_wcsdupa missing\n");
#endif

#ifdef libsimple_wcsndupa
	cws = L"";
	ws = libsimple_wcsndupa(cws, 5);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, L""));

	cws = L"xyz";

	ws = libsimple_wcsndupa(cws, 5);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, L"xyz"));

	ws = libsimple_wcsndupa(cws, 4);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, L"xyz"));

	ws = libsimple_wcsndupa(cws, 3);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, L"xyz"));

	ws = libsimple_wcsndupa(cws, 2);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, L"xy"));

	ws = libsimple_wcsndupa(cws, 1);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, L"x"));

	ws = libsimple_wcsndupa(cws, 0);
	assert(ws);
	assert(ws != cws);
	assert(!((uintptr_t)ws % _Alignof(wchar_t)));
	assert(!wcscmp(ws, L""));
#else
	fprintf(stderr, "warning: libsimple_wcsndupa missing\n");
#endif

#ifdef libsimple_wmemdupa
	cws = L"xyz";
	for (n = 1; n < 4; n++) {
		ws = libsimple_wmemdupa(cws, n);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % _Alignof(wchar_t)));
		assert(!wmemcmp(ws, cws, n));
	}
#else
	fprintf(stderr, "warning: libsimple_wmemdupa missing\n");
#endif

#ifdef libsimple_aligned_wmemdupa
	cws = L"xyz";
	for (n = 1; n < 4; n++) {
		for (i = 1; i < 5; i++) {
			ws = libsimple_aligned_wmemdupa(cws, i, n);
			assert(ws);
			assert(ws != cws);
			assert(!((uintptr_t)ws % i));
			assert(!wmemcmp(ws, cws, n));
		}
	}
#else
	fprintf(stderr, "warning: libsimple_aligned_wmemdupa missing\n");
#endif

#ifdef libsimple_aligned_wcsdupa
	for (i = 1; i < 5; i++) {
		cws = L"";
		ws = libsimple_aligned_wcsdupa(cws, i);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, cws));

		cws = L"xyz";
		ws = libsimple_aligned_wcsdupa(cws, i);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, cws));
	}
#else
	fprintf(stderr, "warning: libsimple_aligned_wcsdupa missing\n");
#endif

#ifdef libsimple_aligned_wcsndupa
	for (i = 1; i < 5; i++) {
		cws = L"";
		ws = libsimple_aligned_wcsndupa(cws, i, 5);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, L""));

		cws = L"xyz";

		ws = libsimple_aligned_wcsndupa(cws, i, 5);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, L"xyz"));

		ws = libsimple_aligned_wcsndupa(cws, i, 4);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, L"xyz"));

		ws = libsimple_aligned_wcsndupa(cws, i, 3);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, L"xyz"));

		ws = libsimple_aligned_wcsndupa(cws, i, 2);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, L"xy"));

		ws = libsimple_aligned_wcsndupa(cws, i, 1);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, L"x"));

		ws = libsimple_aligned_wcsndupa(cws, i, 0);
		assert(ws);
		assert(ws != cws);
		assert(!((uintptr_t)ws % i));
		assert(!wcscmp(ws, L""));
	}
#else
	fprintf(stderr, "warning: libsimple_aligned_wcsndupa missing\n");
#endif

	unsetenv("X");
	assert(!getenv("X"));
	assert(!libsimple_getenv_ne("X"));
	putenv("X=xyz");
	assert(!strcmpnul(getenv("X"), "xyz"));
	assert(!strcmpnul(libsimple_getenv_ne("X"), "xyz"));
	putenv("X=");
	assert(!strcmpnul(getenv("X"), ""));
	assert(!libsimple_getenv_ne("X"));

	unsetenv("X");
	assert(!getenv("X"));
	assert(!strcmpnul(libsimple_getenv_e("X"), ""));
	putenv("X=xyz");
	assert(!strcmpnul(getenv("X"), "xyz"));
	assert(!strcmpnul(libsimple_getenv_e("X"), "xyz"));
	putenv("X=");
	assert(!strcmpnul(getenv("X"), ""));
	assert(!strcmpnul(libsimple_getenv_e("X"), ""));

	assert(test_timespec(10.3000200010, 10, 300020001L, 10.300020001, "+10.300020001", "10.300020001"));
	assert(test_timespec(10.3000200014, 10, 300020001L, 10.300020001, "+10.300020001", "10.300020001"));
	assert(test_timespec(10.3000200015, 10, 300020002L, 10.300020002, "+10.300020002", "10.300020002"));
	assert(test_timespec(10.9999999999, 11, 0, 11, "+11.000000000", "11"));
	assert(test_timespec(-10.3000200010, -11, 699979999L, -10.300020001, "-10.300020001", "-10.300020001"));
	assert(test_timespec(-10.3000200014, -11, 699979999L, -10.300020001, "-10.300020001", "-10.300020001"));
	assert(test_timespec(-10.3000200015, -11, 699979998L, -10.300020002, "-10.300020002", "-10.300020002"));
	assert(test_timespec(-10.9999999999, -11, 0, -11, "-11.000000000", "-11"));
	assert(test_timespec(10, 10, 0, 10, "+10.000000000", "10"));
	assert(test_timespec(0, 0, 0, 0, "+0.000000000", "0"));
	assert(test_timespec(-10, -10, 0, -10, "-10.000000000", "-10"));

	assert(test_timeval(10.3000201000, 10, 300020L, 10.300020, "+10.300020", "10.30002"));
	assert(test_timeval(10.3000204000, 10, 300020L, 10.300020, "+10.300020", "10.30002"));
	assert(test_timeval(10.3000205000, 10, 300021L, 10.300021, "+10.300021", "10.300021"));
	assert(test_timeval(10.9999999000, 11, 0, 11, "+11.000000", "11"));
	assert(test_timeval(-10.3000201000, -11, 699980L, -10.300020, "-10.300020", "-10.30002"));
	assert(test_timeval(-10.3000204000, -11, 699980L, -10.300020, "-10.300020", "-10.30002"));
	assert(test_timeval(-10.3000205000, -11, 699979L, -10.300021, "-10.300021", "-10.300021"));
	assert(test_timeval(-10.9999999000, -11, 0, -11, "-11.000000", "-11"));
	assert(test_timeval(10, 10, 0, 10, "+10.000000", "10"));
	assert(test_timeval(0, 0, 0, 0, "+0.000000", "0"));
	assert(test_timeval(-10, -10, 0, -10, "-10.000000", "-10"));

	libsimple_timeval2timespec(&ts, &(struct timeval){0, 0L});
	assert(ts.tv_sec  == 0);
	assert(ts.tv_nsec == 0L);
	libsimple_timeval2timespec(&ts, &(struct timeval){0, 1L});
	assert(ts.tv_sec  == 0);
	assert(ts.tv_nsec == 1000L);
	libsimple_timeval2timespec(&ts, &(struct timeval){0, 999999L});
	assert(ts.tv_sec  == 0);
	assert(ts.tv_nsec == 999999000L);
	libsimple_timeval2timespec(&ts, &(struct timeval){10, 0L});
	assert(ts.tv_sec  == 10);
	assert(ts.tv_nsec == 0L);
	libsimple_timeval2timespec(&ts, &(struct timeval){10, 1L});
	assert(ts.tv_sec  == 10);
	assert(ts.tv_nsec == 1000L);
	libsimple_timeval2timespec(&ts, &(struct timeval){-10, 0L});
	assert(ts.tv_sec  == -10);
	assert(ts.tv_nsec == 0L);
	libsimple_timeval2timespec(&ts, &(struct timeval){-10, 1L});
	assert(ts.tv_sec  == -10);
	assert(ts.tv_nsec == 1000L);

	ts1.tv_sec = 0, ts1.tv_nsec = 0L;
	ts2.tv_sec = 0, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
	ts1.tv_sec = 0, ts1.tv_nsec = 1L;
	ts2.tv_sec = 0, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
	ts2.tv_sec = 0, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = 0, ts1.tv_nsec = 0L;
	ts2.tv_sec = 0, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 0, ts1.tv_nsec = 1L;
	ts2.tv_sec = 0, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
	ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
	ts2.tv_sec = 0, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = 0, ts1.tv_nsec = 0L;
	ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 0, ts1.tv_nsec = 1L;
	ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
	ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
	ts1.tv_sec = 1, ts1.tv_nsec = 0L;
	ts2.tv_sec = 0, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = 1, ts1.tv_nsec = 1L;
	ts2.tv_sec = 0, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = 1, ts1.tv_nsec = 0L;
	ts2.tv_sec = 0, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = 1, ts1.tv_nsec = 1L;
	ts2.tv_sec = 0, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = 0, ts1.tv_nsec = 0L;
	ts2.tv_sec = 1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 0, ts1.tv_nsec = 1L;
	ts2.tv_sec = 1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 0, ts1.tv_nsec = 0L;
	ts2.tv_sec = 1, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 0, ts1.tv_nsec = 1L;
	ts2.tv_sec = 1, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 1, ts1.tv_nsec = 0L;
	ts2.tv_sec = 1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
	ts1.tv_sec = 1, ts1.tv_nsec = 1L;
	ts2.tv_sec = 1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = 1, ts1.tv_nsec = 0L;
	ts2.tv_sec = 1, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 1, ts1.tv_nsec = 1L;
	ts2.tv_sec = 1, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
	ts1.tv_sec = -1, ts1.tv_nsec = 0L;
	ts2.tv_sec =  0, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = -1, ts1.tv_nsec = 1L;
	ts2.tv_sec =  0, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = -1, ts1.tv_nsec = 0L;
	ts2.tv_sec =  0, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = -1, ts1.tv_nsec = 1L;
	ts2.tv_sec =  0, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec =  0, ts1.tv_nsec = 0L;
	ts2.tv_sec = -1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec =  0, ts1.tv_nsec = 1L;
	ts2.tv_sec = -1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec =  0, ts1.tv_nsec = 0L;
	ts2.tv_sec = -1, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec =  0, ts1.tv_nsec = 1L;
	ts2.tv_sec = -1, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = -1, ts1.tv_nsec = 0L;
	ts2.tv_sec = -1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
	ts1.tv_sec = -1, ts1.tv_nsec = 1L;
	ts2.tv_sec = -1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = -1, ts1.tv_nsec = 0L;
	ts2.tv_sec = -1, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = -1, ts1.tv_nsec = 1L;
	ts2.tv_sec = -1, ts2.tv_nsec = 1L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
	ts1.tv_sec = 0,        ts1.tv_nsec = 0L;
	ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = 1,        ts1.tv_nsec = 0L;
	ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
	ts1.tv_sec = TIME_MAX, ts1.tv_nsec = 0L;
	ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
	ts1.tv_sec =  1, ts1.tv_nsec = 0L;
	ts2.tv_sec = -1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
	ts1.tv_sec = -1, ts1.tv_nsec = 0L;
	ts2.tv_sec =  1, ts2.tv_nsec = 0L;
	assert(libsimple_cmptimespec(&ts1, &ts2) == -1);

	tv1.tv_sec = 0, tv1.tv_usec = 0L;
	tv2.tv_sec = 0, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
	tv1.tv_sec = 0, tv1.tv_usec = 1L;
	tv2.tv_sec = 0, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = 0, tv1.tv_usec = 999999L;
	tv2.tv_sec = 0, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = 0, tv1.tv_usec = 0L;
	tv2.tv_sec = 0, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 0, tv1.tv_usec = 1L;
	tv2.tv_sec = 0, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
	tv1.tv_sec = 0, tv1.tv_usec = 999999L;
	tv2.tv_sec = 0, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = 0, tv1.tv_usec = 0L;
	tv2.tv_sec = 0, tv2.tv_usec = 999999L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 0, tv1.tv_usec = 1L;
	tv2.tv_sec = 0, tv2.tv_usec = 999999L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 0, tv1.tv_usec = 999999L;
	tv2.tv_sec = 0, tv2.tv_usec = 999999L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
	tv1.tv_sec = 1, tv1.tv_usec = 0L;
	tv2.tv_sec = 0, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = 1, tv1.tv_usec = 1L;
	tv2.tv_sec = 0, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = 1, tv1.tv_usec = 0L;
	tv2.tv_sec = 0, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = 1, tv1.tv_usec = 1L;
	tv2.tv_sec = 0, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = 0, tv1.tv_usec = 0L;
	tv2.tv_sec = 1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 0, tv1.tv_usec = 1L;
	tv2.tv_sec = 1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 0, tv1.tv_usec = 0L;
	tv2.tv_sec = 1, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 0, tv1.tv_usec = 1L;
	tv2.tv_sec = 1, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 1, tv1.tv_usec = 0L;
	tv2.tv_sec = 1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
	tv1.tv_sec = 1, tv1.tv_usec = 1L;
	tv2.tv_sec = 1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = 1, tv1.tv_usec = 0L;
	tv2.tv_sec = 1, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 1, tv1.tv_usec = 1L;
	tv2.tv_sec = 1, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
	tv1.tv_sec = -1, tv1.tv_usec = 0L;
	tv2.tv_sec =  0, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = -1, tv1.tv_usec = 1L;
	tv2.tv_sec =  0, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = -1, tv1.tv_usec = 0L;
	tv2.tv_sec =  0, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = -1, tv1.tv_usec = 1L;
	tv2.tv_sec =  0, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec =  0, tv1.tv_usec = 0L;
	tv2.tv_sec = -1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec =  0, tv1.tv_usec = 1L;
	tv2.tv_sec = -1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec =  0, tv1.tv_usec = 0L;
	tv2.tv_sec = -1, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec =  0, tv1.tv_usec = 1L;
	tv2.tv_sec = -1, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = -1, tv1.tv_usec = 0L;
	tv2.tv_sec = -1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
	tv1.tv_sec = -1, tv1.tv_usec = 1L;
	tv2.tv_sec = -1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = -1, tv1.tv_usec = 0L;
	tv2.tv_sec = -1, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = -1, tv1.tv_usec = 1L;
	tv2.tv_sec = -1, tv2.tv_usec = 1L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
	tv1.tv_sec = 0,        tv1.tv_usec = 0L;
	tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = 1,        tv1.tv_usec = 0L;
	tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
	tv1.tv_sec = TIME_MAX, tv1.tv_usec = 0L;
	tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
	tv1.tv_sec =  1, tv1.tv_usec = 0L;
	tv2.tv_sec = -1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
	tv1.tv_sec = -1, tv1.tv_usec = 0L;
	tv2.tv_sec =  1, tv2.tv_usec = 0L;
	assert(libsimple_cmptimeval(&tv1, &tv2) == -1);

	assert((ptr = libsimple_mallocz(0, 11)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 11);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);

	assert((ptr = libsimple_mallocz(1, 12)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 12);
		assert(info->zeroed == 12);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);

	assert((ptr = libsimple_emallocz(0, 13)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 13);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);

	assert((ptr = libsimple_emallocz(1, 14)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 14);
		assert(info->zeroed == 14);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);

	assert((ptr = libsimple_enmallocz(10, 0, 15)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 15);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);

	assert((ptr = libsimple_enmallocz(10, 1, 16)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 16);
		assert(info->zeroed == 16);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);

	assert((ptr = libsimple_aligned_allocz(0, 8, 8)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 8);
		ASSERT_ALIGNMENT(info, 8);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);

	assert((ptr = libsimple_aligned_allocz(1, 8, 16)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 16);
		ASSERT_ALIGNMENT(info, 8);
		assert(info->zeroed == 16);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert(!libsimple_posix_memalignz(&ptr, 0, 8 * sizeof(void *), 8));
	assert(ptr);
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 8);
		ASSERT_ALIGNMENT(info, 8 * sizeof(void *));
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert(!libsimple_posix_memalignz(&ptr, 1, 4 * sizeof(void *), 16));
	assert(ptr);
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 16);
		ASSERT_ALIGNMENT(info, 4 * sizeof(void *));
		assert(info->zeroed == 16);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_memalignz(0, 4, 9)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 9 || info->size == 12);
		ASSERT_ALIGNMENT(info, 4);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_memalignz(1, 2, 7)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 7 || info->size == 8);
		ASSERT_ALIGNMENT(info, 2);
		assert(info->zeroed == 7 || info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_memalign(2, 5)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 5 || info->size == 6);
		ASSERT_ALIGNMENT(info, 2);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert(!libsimple_memalignzn(0, 128, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalignzn(1, 128, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalignn(128, 0) && errno == EINVAL);
	errno = 0;

	assert(!libsimple_memalignzn(0, 1024, SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;
	assert(!libsimple_memalignzn(1, 1024, SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;
	assert(!libsimple_memalignn(1024, SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;

	assert(!libsimple_memalignz(0, 65, 100) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalignz(1, 65, 100) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalign(65, 100) && errno == EINVAL);
	errno = 0;

	assert(!libsimple_memalignzn(0, 65, 100, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalignzn(1, 65, 100, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalignn(65, 100, 0) && errno == EINVAL);
	errno = 0;

	assert(!libsimple_memalignz(0, 0, 100) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalignz(1, 0, 100) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalign(0, 100) && errno == EINVAL);
	errno = 0;

	assert(!libsimple_memalignzn(0, 0, 100, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalignzn(1, 0, 100, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_memalignn(0, 100, 0) && errno == EINVAL);
	errno = 0;

	assert((ptr = libsimple_memalignzn(0, 1, 9, 9, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 81);
		ASSERT_ALIGNMENT(info, 1);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_memalignzn(1, 2, 9, 9, 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 162);
		ASSERT_ALIGNMENT(info, 2);
		assert(info->zeroed == 162);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_memalignn(4, 9, 9, 3, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 243 || info->size == 244);
		ASSERT_ALIGNMENT(info, 4);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_enmemalignz(1, 1, 2, 9)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 9 || info->size == 10);
		ASSERT_ALIGNMENT(info, 2);
		assert(info->zeroed == 9 || info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_ememalignz(1, 2, 7)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 7 || info->size == 8);
		ASSERT_ALIGNMENT(info, 2);
		assert(info->zeroed == 7 || info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_enmemalignz(1, 0, 2, 8)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 8);
		ASSERT_ALIGNMENT(info, 2);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_ememalignz(0, 4, 4)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 4);
		ASSERT_ALIGNMENT(info, 4);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_enmemalign(1, 4, 8)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 8);
		ASSERT_ALIGNMENT(info, 4);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_ememalign(8, 3)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 3 || info->size == 8);
		ASSERT_ALIGNMENT(info, 8);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_vallocz(0, 9)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 9 || info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_vallocz(1, 7)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 7 || info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == 7 || info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_valloc(5)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 5 || info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_vallocz(1, 3 * pagesize)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 3 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == 3 * pagesize);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_vallocz(0, 4 * pagesize)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 4 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_valloc(5 * pagesize)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 5 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_valloczn(1, 3 * pagesize, 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 6 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == 6 * pagesize);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_valloczn(0, 4 * pagesize, 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 8 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_vallocn(5 * pagesize, 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 10 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert(!libsimple_valloczn(0, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_valloczn(1, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_vallocn(0) && errno == EINVAL);
	errno = 0;

	assert(!libsimple_valloczn(0, SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;
	assert(!libsimple_valloczn(1, SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;
	assert(!libsimple_vallocn(SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;

	assert((ptr = libsimple_pvallocz(0, 9)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvallocz(1, 7)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == pagesize);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvalloc(5)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 5 || info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvallocz(1, pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == pagesize);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvallocz(1, pagesize)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == pagesize);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvallocz(1, pagesize + 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 2 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == 2 * pagesize);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvallocz(1, 3 * pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 3 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == 3 * pagesize);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvallocz(0, 4 * pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 4 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvalloc(5 * pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 5 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvalloczn(1, 3 * pagesize - 1, 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 6 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == 6 * pagesize);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvalloczn(0, 4 * pagesize - 1, 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 8 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvallocn(5 * pagesize - 1, 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 10 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)info->alignment));
	}
	free(ptr);
	ptr = NULL;

	assert(!libsimple_pvalloczn(0, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_pvalloczn(1, 0) && errno == EINVAL);
	errno = 0;
	assert(!libsimple_pvallocn(0) && errno == EINVAL);
	errno = 0;

	assert(!libsimple_pvalloczn(0, SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;
	assert(!libsimple_pvalloczn(1, SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;
	assert(!libsimple_pvallocn(SIZE_MAX, 2, 0) && errno == ENOMEM);
	errno = 0;

	assert((ptr = libsimple_valloczn(0, 9, 9, pagesize - 1, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 81 * (pagesize - 1));
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_valloczn(1, 9, 8, pagesize - 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 72 * (pagesize - 2));
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_vallocn(9, (pagesize - 1), 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 9 * (pagesize - 1));
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_envallocz(1, 1, 5 * pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 5 * pagesize - 1);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_evallocz(1, 3 * pagesize + 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 3 * pagesize + 1);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_envallocz(1, 0, pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == pagesize - 1);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_evallocz(0, pagesize + 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == pagesize + 1);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_envalloc(1, 127)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 127);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_evalloc(3 * pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 3 * pagesize - 1);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_pvalloczn(0, 9, 9, pagesize - 1, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 81 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_pvalloczn(1, 9, 8, pagesize - 2, 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 72 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_pvallocn(9, (pagesize - 1), 0)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 9 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);

	assert((ptr = libsimple_enpvallocz(1, 1, 5 * pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 5 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_epvallocz(1, 3 * pagesize + 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 4 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(info->zeroed == info->size);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_enpvallocz(1, 0, pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_epvallocz(0, pagesize + 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 2 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_enpvalloc(1, 127)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	assert((ptr = libsimple_epvalloc(3 * pagesize - 1)));
	if (have_custom_malloc()) {
		assert((info = get_allocinfo(ptr)));
		assert(info->size == 3 * pagesize);
		ASSERT_ALIGNMENT(info, pagesize);
		assert(!info->zeroed);
		assert(!((uintptr_t)ptr % (uintptr_t)(info->alignment)));
	}
	free(ptr);
	ptr = NULL;

	if (have_custom_malloc()) {
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_enmallocz(5, 0, 20));
		assert(exit_status == 5);
		assert_stderr("%s: malloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_enmallocz(6, 1, 20));
		assert(exit_status == 6);
		assert_stderr("%s: calloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 7;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_emallocz(0, 20));
		assert(exit_status == 7);
		assert_stderr("%s: malloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 8;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_emallocz(1, 20));
		assert(exit_status == 8);
		assert_stderr("%s: calloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(!(ptr = libsimple_mallocz(0, 20)) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(!(ptr = libsimple_mallocz(1, 20)) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(!(ptr = libsimple_aligned_allocz(0, 8, 8)) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(!(ptr = libsimple_aligned_allocz(1, 8, 16)) && errno == ENOMEM);
		assert(!alloc_fail_in);

		errno = 0;

		alloc_fail_in = 1;
		assert(libsimple_posix_memalignz(&ptr, 0, 4 * sizeof(void *), 8) == ENOMEM && !errno);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(libsimple_posix_memalignz(&ptr, 1, 16 * sizeof(void *), 16) == ENOMEM && !errno);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(!libsimple_memalignz(0, 4 * sizeof(void *), 8) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(!libsimple_memalignz(1, 16 * sizeof(void *), 16) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_enmemalignz(3, 1, sizeof(void *), 4));
		assert(exit_status == 3);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 102;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_ememalignz(1, sizeof(void *), 4));
		assert(exit_status == 102);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_enmemalignz(5, 0, sizeof(void *), 4));
		assert(exit_status == 5);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 103;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_ememalignz(0, sizeof(void *), 4));
		assert(exit_status == 103);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_enmemalign(7, sizeof(void *), 4));
		assert(exit_status == 7);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 104;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_ememalign(sizeof(void *), 4));
		assert(exit_status == 104);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;

		alloc_fail_in = 1;
		assert(!libsimple_vallocz(0, 8) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(!libsimple_vallocz(1, 16) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_envallocz(3, 1, 4));
		assert(exit_status == 3);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 102;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_evallocz(1, 4));
		assert(exit_status == 102);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_envallocz(5, 0, 4));
		assert(exit_status == 5);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 103;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_evallocz(0, 4));
		assert(exit_status == 103);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_envalloc(7, 4));
		assert(exit_status == 7);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 104;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_evalloc(4));
		assert(exit_status == 104);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;

		alloc_fail_in = 1;
		assert(!libsimple_pvallocz(0, 8) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert(!libsimple_pvallocz(1, 16) && errno == ENOMEM);
		assert(!alloc_fail_in);

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_enpvallocz(3, 1, 4));
		assert(exit_status == 3);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 102;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_epvallocz(1, 4));
		assert(exit_status == 102);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_enpvallocz(5, 0, 4));
		assert(exit_status == 5);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 103;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_epvallocz(0, 4));
		assert(exit_status == 103);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;

		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_enpvalloc(7, 4));
		assert(exit_status == 7);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);

		libsimple_default_failure_exit = 104;
		alloc_fail_in = 1;
		assert_exit_ptr(libsimple_epvalloc(4));
		assert(exit_status == 104);
		assert_stderr("%s: libsimple_vmemalloc: %s\n", argv0, strerror(ENOMEM));
		assert(!alloc_fail_in);
		libsimple_default_failure_exit = 1;
	}

	assert_exit_ptr(libsimple_enmemalignz(3, 1, 0, 4));
	assert(exit_status == 3);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));

	libsimple_default_failure_exit = 102;
	assert_exit_ptr(libsimple_ememalignz(1, 0, 4));
	assert(exit_status == 102);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));
	assert(!alloc_fail_in);

	assert_exit_ptr(libsimple_enmemalignz(5, 0, 0, 4));
	assert(exit_status == 5);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));

	libsimple_default_failure_exit = 103;
	assert_exit_ptr(libsimple_ememalignz(0, 0, 4));
	assert(exit_status == 103);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));
	assert(!alloc_fail_in);

	assert_exit_ptr(libsimple_enmemalign(7, 0, 4));
	assert(exit_status == 7);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));

	libsimple_default_failure_exit = 104;
	assert_exit_ptr(libsimple_ememalign(0, 4));
	assert(exit_status == 104);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));
	libsimple_default_failure_exit = 1;

	assert_exit_ptr(libsimple_enmemalignz(3, 1, 3, 4));
	assert(exit_status == 3);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));

	libsimple_default_failure_exit = 102;
	assert_exit_ptr(libsimple_ememalignz(1, 3, 4));
	assert(exit_status == 102);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));
	assert(!alloc_fail_in);

	assert_exit_ptr(libsimple_enmemalignz(5, 0, 3, 4));
	assert(exit_status == 5);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));

	libsimple_default_failure_exit = 103;
	assert_exit_ptr(libsimple_ememalignz(0, 3, 4));
	assert(exit_status == 103);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));
	assert(!alloc_fail_in);

	assert_exit_ptr(libsimple_enmemalign(7, 3, 4));
	assert(exit_status == 7);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));

	libsimple_default_failure_exit = 104;
	assert_exit_ptr(libsimple_ememalign(3, 4));
	assert(exit_status == 104);
	assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL));
	libsimple_default_failure_exit = 1;

	assert(libsimple_memeq("abcxyz", "abc123", 3));
	assert(!libsimple_memeq("abcxyz", "abc123", 4));
	assert(libsimple_memeq("abcxyz", "abcx23", 4));
	assert(libsimple_memeq("1", "2", 0));
	assert(!libsimple_memeq("1", "2", 1));
	assert(!libsimple_memeq("abc", "ABC", 3));
	assert(!libsimple_memeq("ABC", "abc", 3));
	assert(libsimple_memeq("ABC", "ABC", 3));

	assert(libsimple_memcaseeq("abcxyz", "abc123", 3));
	assert(!libsimple_memcaseeq("abcxyz", "abc123", 4));
	assert(libsimple_memcaseeq("abcxyz", "abcx23", 4));
	assert(libsimple_memcaseeq("1", "2", 0));
	assert(!libsimple_memcaseeq("1", "2", 1));
	assert(libsimple_memcaseeq("abc", "ABC", 3));
	assert(libsimple_memcaseeq("ABC", "abc", 3));
	assert(libsimple_memcaseeq("ABC", "ABC", 3));

	stpcpy(buf, "abc123");
	assert(!strcmpnul(libsimple_mempset(buf, '.', 3), "123"));
	assert(!strcmp(buf, "...123"));

#ifdef libsimple_asprintfa
	s = libsimple_asprintfa("%sxyz%s", "abc", "123");
	assert(s);
	assert(!strcmp(s, "abcxyz123"));
#else
	fprintf(stderr, "warning: libsimple_asprintfa missing\n");
#endif

#ifdef libsimple_vasprintfa
	assert(test_vasprintfa("abcxyz123", "%sxyz%s", "abc", "123"));
#else
	fprintf(stderr, "warning: libsimple_vasprintfa missing\n");
#endif

	{
		char a[] = "abcdefgh", b[] = "abcdefgh";
		assert(libsimple_strreqlen("", "") == 0);
		assert(libsimple_strreqlen("x", "") == 0);
		assert(libsimple_strreqlen("x", "y") == 0);
		assert(libsimple_strreqlen("", "y") == 0);
		for (i = 0; i <= 8; i++) {
			for (j = 0; j <= 8; j++) {
				assert(libsimple_strreqlen(&a[i], &b[j]) == 8 - (i > j ? i : j));
				a[i] = b[j] = '\0';
				assert(libsimple_strreqlen(a, b) == (i == j ? i : 0));
				a[i] = "abcdefgh"[i];
				b[j] = "abcdefgh"[j];
			}
		}
		assert(libsimple_strreqlen("abc", "ABC") == 0);
		assert(libsimple_strreqlen("123", "123") == 3);
	}

	{
		char a[] = "abcdefgh", b[] = "ABCDEFGH";
		assert(libsimple_strrcaseeqlen("", "") == 0);
		assert(libsimple_strrcaseeqlen("x", "") == 0);
		assert(libsimple_strrcaseeqlen("x", "y") == 0);
		assert(libsimple_strrcaseeqlen("", "y") == 0);
		for (i = 0; i <= 8; i++) {
			for (j = 0; j <= 8; j++) {
				assert(libsimple_strrcaseeqlen(&a[i], &b[j]) == 8 - (i > j ? i : j));
				assert(libsimple_strrcaseeqlen(&b[i], &a[j]) == 8 - (i > j ? i : j));
				a[i] = b[j] = '\0';
				assert(libsimple_strrcaseeqlen(a, b) == (i == j ? i : 0));
				assert(libsimple_strrcaseeqlen(b, a) == (i == j ? i : 0));
				a[i] = "abcdefgh"[i];
				b[j] = "ABCDEFGH"[j];
			}
		}
		assert(libsimple_strrcaseeqlen("abc", "abc") == 3);
		assert(libsimple_strrcaseeqlen("123", "123") == 3);
	}

	for (n = 0; n < 10; n++) {
		char a[] = "abcdefgh", b[] = "abcdefgh";
		size_t I, J;
		assert(libsimple_strrneqlen("", "", n) == 0);
		assert(libsimple_strrneqlen("x", "", n) == 0);
		assert(libsimple_strrneqlen("x", "y", n) == 0);
		assert(libsimple_strrneqlen("", "y", n) == 0);
		for (i = 0; i <= 8; i++) {
			for (j = 0; j <= 8; j++) {
				I = 8 - i;
				J = 8 - j;
				assert(libsimple_strrneqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J))));
				a[i] = b[j] = '\0';
				assert(libsimple_strrneqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0));
				a[i] = "abcdefgh"[i];
				b[j] = "abcdefgh"[j];
			}
		}
		assert(libsimple_strrneqlen("abc", "ABC", n) == 0);
		assert(libsimple_strrneqlen("123", "123", n) == MIN(3, n));
	}

	for (n = 0; n < 10; n++) {
		char a[] = "abcdefgh", b[] = "ABCDEFGH";
		size_t I, J;
		assert(libsimple_strrncaseeqlen("", "", n) == 0);
		assert(libsimple_strrncaseeqlen("x", "", n) == 0);
		assert(libsimple_strrncaseeqlen("x", "y", n) == 0);
		assert(libsimple_strrncaseeqlen("", "y", n) == 0);
		for (i = 0; i <= 8; i++) {
			for (j = 0; j <= 8; j++) {
				I = 8 - i;
				J = 8 - j;
				assert(libsimple_strrncaseeqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J))));
				assert(libsimple_strrncaseeqlen(&b[i], &a[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J))));
				a[i] = b[j] = '\0';
				assert(libsimple_strrncaseeqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0));
				assert(libsimple_strrncaseeqlen(b, a, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0));
				a[i] = "abcdefgh"[i];
				b[j] = "ABCDEFGH"[j];
			}
		}
		assert(libsimple_strrncaseeqlen("abc", "abc", n) == MIN(3, n));
		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);
	}


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strset(buf, 'x') == buf);
	assert(!strcmp(buf, "xxxxxxxxxxx"));
	assert(!strcmp(&buf[12], "goodbye world"));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strset(buf, '\0') == buf);
	assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26));


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_stpset(buf, 'x') == &buf[11]);
	assert(!strcmp(buf, "xxxxxxxxxxx"));
	assert(!strcmp(&buf[12], "goodbye world"));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_stpset(buf, '\0') == &buf[11]);
	assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26));


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnset(buf, 'x', SIZE_MAX) == buf);
	assert(!strcmp(buf, "xxxxxxxxxxx"));
	assert(!strcmp(&buf[12], "goodbye world"));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnset(buf, '\0', SIZE_MAX) == buf);
	assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26));


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_stpnset(buf, 'x', SIZE_MAX) == &buf[11]);
	assert(!strcmp(buf, "xxxxxxxxxxx"));
	assert(!strcmp(&buf[12], "goodbye world"));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_stpnset(buf, '\0', SIZE_MAX) == &buf[11]);
	assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26));


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnset(buf, 'x', 5) == buf);
	assert(!strcmp(buf, "xxxxx world"));
	assert(!strcmp(&buf[12], "goodbye world"));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnset(buf, '\0', 5) == buf);
	assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26));


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_stpnset(buf, 'x', 5) == &buf[5]);
	assert(!strcmp(buf, "xxxxx world"));
	assert(!strcmp(&buf[12], "goodbye world"));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_stpnset(buf, '\0', 5) == &buf[5]);
	assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26));


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_memreplace(buf, 'o', 'x', 46) == &buf[46]);
	assert(!memcmp(buf, "hellx wxrld\0gxxdbye wxrld", 26));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_memreplace(buf, 'o', 'x', 12) == &buf[12]);
	assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26));


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strreplace(buf, 'o', 'x') == &buf[11]);
	assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26));


	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnreplace(buf, 'o', 'x', SIZE_MAX) == &buf[11]);
	assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnreplace(buf, 'o', 'x', 12) == &buf[11]);
	assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnreplace(buf, 'o', 'x', 11) == &buf[11]);
	assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnreplace(buf, 'o', 'x', 6) == &buf[6]);
	assert(!memcmp(buf, "hellx world\0goodbye world", 26));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnreplace(buf, 'o', 'x', 5) == &buf[5]);
	assert(!memcmp(buf, "hellx world\0goodbye world", 26));

	stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
	assert(libsimple_strnreplace(buf, 'o', 'x', 4) == &buf[4]);
	assert(!memcmp(buf, "hello world\0goodbye world", 26));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strmove(&buf[3], buf) == &buf[3]);
	assert(!strcmp(buf, "helhello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strmove(buf, &buf[3]) == buf);
	assert(!strcmp(buf, "lo world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strmove(buf, buf) == buf);
	assert(!strcmp(buf, "hello world"));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(&buf[3], buf, SIZE_MAX) == &buf[3]);
	assert(!strcmp(buf, "helhello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(buf, &buf[3], SIZE_MAX) == buf);
	assert(!strcmp(buf, "lo world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(buf, buf, SIZE_MAX) == buf);
	assert(!strcmp(buf, "hello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(&buf[3], buf, 12) == &buf[3]);
	assert(!strcmp(buf, "helhello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(buf, &buf[3], 9) == buf);
	assert(!strcmp(buf, "lo world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(buf, buf, 12) == buf);
	assert(!strcmp(buf, "hello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(&buf[3], buf, 11) == &buf[3]);
	assert(!strncmp(buf, "helhello worldx", 15));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(buf, &buf[3], 8) == buf);
	assert(!strcmp(buf, "lo worldrld"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(buf, buf, 11) == buf);
	assert(!strcmp(buf, "hello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(&buf[3], buf, 2) == &buf[3]);
	assert(!strcmp(buf, "helhe world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(buf, &buf[3], 2) == buf);
	assert(!strcmp(buf, "lollo world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_strnmove(buf, buf, 2) == buf);
	assert(!strcmp(buf, "hello world"));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpmove(&buf[3], buf) == &buf[11 + 3]);
	assert(!strcmp(buf, "helhello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpmove(buf, &buf[3]) == &buf[11 - 3]);
	assert(!strcmp(buf, "lo world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpmove(buf, buf) == &buf[11]);
	assert(!strcmp(buf, "hello world"));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(&buf[3], buf, SIZE_MAX) == &buf[11 + 3]);
	assert(!strcmp(buf, "helhello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(buf, &buf[3], SIZE_MAX) == &buf[11 - 3]);
	assert(!strcmp(buf, "lo world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(buf, buf, SIZE_MAX) == &buf[11]);
	assert(!strcmp(buf, "hello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(&buf[3], buf, 12) == &buf[11 + 3]);
	assert(!strcmp(buf, "helhello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(buf, &buf[3], 9) == &buf[11 - 3]);
	assert(!strcmp(buf, "lo world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(buf, buf, 12) == &buf[11]);
	assert(!strcmp(buf, "hello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(&buf[3], buf, 11) == &buf[11 + 3]);
	assert(!strncmp(buf, "helhello worldx", 15));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(buf, &buf[3], 8) == &buf[8]);
	assert(!strcmp(buf, "lo worldrld"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(buf, buf, 11) == &buf[11]);
	assert(!strcmp(buf, "hello world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(&buf[3], buf, 2) == &buf[3 + 2]);
	assert(!strcmp(buf, "helhe world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(buf, &buf[3], 2) == &buf[2]);
	assert(!strcmp(buf, "lollo world"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	strcpy(buf, "hello world");
	assert(libsimple_stpnmove(buf, buf, 2) == &buf[2]);
	assert(!strcmp(buf, "hello world"));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strccpy(buf, "hello", '\0') == &buf[6]);
	assert(!strcmp(buf, "hello"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strccpy(buf, "hello", 'o') == &buf[5]);
	assert(!strcmp(buf, "hello"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strccpy(buf, "hello", 'l') == &buf[3]);
	assert(!strcmp(buf, "hel"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strccpy(buf, "hello", 'x') == NULL);
	assert(!strcmp(buf, "hello"));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", '\0', 1024) == &buf[6]);
	assert(!strcmp(buf, "hello"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'o', 1024) == &buf[5]);
	assert(!strcmp(buf, "hello"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'l', 1024) == &buf[3]);
	assert(!strcmp(buf, "hel"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'x', 1024) == NULL);
	assert(!strcmp(buf, "hello"));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", '\0', 6) == &buf[6]);
	assert(!strcmp(buf, "hello"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'o', 6) == &buf[5]);
	assert(!strcmp(buf, "hello"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'l', 6) == &buf[3]);
	assert(!strcmp(buf, "hel"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'x', 6) == NULL);
	assert(!strcmp(buf, "hello"));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", '\0', 5) == NULL);
	assert(!strncmp(buf, "hellox", 6));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'o', 5) == &buf[5]);
	assert(!strncmp(buf, "hellox", 6));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'l', 5) == &buf[3]);
	assert(!strcmp(buf, "hel"));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'x', 5) == NULL);
	assert(!strncmp(buf, "hellox", 6));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_strnccpy(buf, "hello", 'o', 3) == NULL);
	assert(!strncmp(buf, "helx", 4));


	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';
	assert(libsimple_rawmemcmove(&buf[5], &buf[5], 'o') == &buf[5 + 5]);
	assert(!strncmp(buf, "-----hello-", 11));

	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';;
	assert(libsimple_rawmemcmove(&buf[5], &buf[5], 'l') == &buf[5 + 3]);
	assert(!strncmp(buf, "-----hello-", 11));


	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';
	assert(libsimple_rawmemcmove(&buf[3], &buf[5], 'o') == &buf[3 + 5]);
	assert(!strncmp(buf, "---hellolo-", 11));

	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';
	assert(libsimple_rawmemcmove(&buf[3], &buf[5], 'l') == &buf[3 + 3]);
	assert(!strncmp(buf, "---helello-", 11));


	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';
	assert(libsimple_rawmemcmove(&buf[8], &buf[5], 'o') == &buf[8 + 5]);
	assert(!strncmp(buf, "-----helhello-", 14));

	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';
	assert(libsimple_rawmemcmove(&buf[8], &buf[5], 'l') == &buf[8 + 3]);
	assert(!strncmp(buf, "-----helhel-", 12));


	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_rawmemccpy(buf, "hello", 'o') == &buf[5]);
	assert(!strncmp(buf, "hellox", 6));

	memset(buf, 'x', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	assert(libsimple_rawmemccpy(buf, "hello", 'l') == &buf[3]);
	assert(!strncmp(buf, "helx", 4));


	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';
	assert(libsimple_mempmove(&buf[5], &buf[5], 5) == &buf[5 + 5]);
	assert(!strncmp(buf, "-----hello-", 11));

	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';
	assert(libsimple_mempmove(&buf[3], &buf[5], 5) == &buf[3 + 5]);
	assert(!strncmp(buf, "---hellolo-", 11));

	memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0';
	stpcpy(&buf[5], "hello")[0] = '-';
	assert(libsimple_mempmove(&buf[8], &buf[5], 5) == &buf[8 + 5]);
	assert(!strncmp(buf, "-----helhello-", 14));


	if (!have_custom_malloc()) {
		stderr_real = 1;
		fprintf(stderr, "\nSome tests have not been ran because malloc(3) was not "
		                "replaced, this is normal if running under valgrind(1).\n\n");
	}
	return 0;
}

#endif