#include #include #include #include "xalloc.h" #include "zalloc.h" #include "zalloc_ext.h" int main() { /* Duplicate functions */ void *zptr = zmalloc(384932); void *zptr2 = zalloc_dup(zptr); void *arr = xmalloc(9832472); void *zptr3 = zalloc_dup_usual(arr, 9832472); void *zptr4_str = zalloc_dup_usual_str("Hello, world!"); /* Append functions */ zptr = zalloc_append(zptr, zptr2); zptr4_str = zalloc_append_str(zptr4_str, zptr4_str); zptr2 = zalloc_append_usual(zptr2, arr, 9832472); zptr4_str = zalloc_append_usual_str(zptr4_str, " - twice :)"); puts(zptr4_str); zptr = zalloc_append8(zptr, 'a'); zptr4_str = zalloc_append8_str(zptr4_str, 'E'); puts(zptr4_str); zptr = zalloc_append16(zptr, 12345); zptr4_str = zalloc_append16_str(zptr4_str, ('H' << 8) + 'H'); puts(zptr4_str); zptr = zalloc_append32(zptr, 65489498L); zptr4_str = zalloc_append32_str(zptr4_str, (((((('4' << 8) + '4') << 8) + '4') << 8) + '4')); puts(zptr4_str); zptr3 = zalloc_append64(zptr3, 3232423423423LLU); zptr = zalloc_append_ptr(zptr, (void *)93842); int64_t i64 = 1561; int i; for (i = 0; i < 8; i++) i64 = (i64 << 8) + '8'; printf("%x %x %x %x\n", *((char *)&i64 + 0), *((char *)&i64 + 1), *((char *)&i64 + 2), *((char *)&i64 + 3)); zptr4_str = zalloc_append64_str(zptr4_str, i64); puts(zptr4_str); /* Cut/Copy/Insert functions */ zptr3 = zalloc_cut(zptr3, 6547, 564); zptr4_str = zalloc_cut_str(zptr4_str, 5, 7); puts(zptr4_str); void *zptr5 = zalloc_copy(zptr2, 8424, 345); void *zptr6_str = zalloc_copy_str(zptr4_str, 6, 13); puts(zptr6_str); zptr5 = zalloc_insert(zptr5, 0, zptr); zptr4_str = zalloc_insert_str(zptr4_str, 31, zptr6_str); puts(zptr4_str); void *arr2 = zmalloc(54547); zptr2 = zalloc_insert_usual(zptr2, zalloc_size(zptr2) - 3, arr2, zalloc_size(arr2)); zptr4_str = zalloc_insert_usual_str(zptr4_str, 5, ":zalloc_insert_usual_str():"); puts(zptr4_str); zptr5 = zalloc_insert8(zptr5, 9874, 'd'); zptr6_str = zalloc_insert8_str(zptr6_str, 0, '0'); puts(zptr6_str); zptr5 = zalloc_insert16(zptr5, 9874, 5478); zptr6_str = zalloc_insert16_str(zptr6_str, 1, ('1' << 8) + '1'); puts(zptr6_str); zptr5 = zalloc_insert32(zptr5, 9874, 5478323); zptr6_str = zalloc_insert32_str(zptr6_str, 0, (((((('4' << 8) + '4') << 8) + '4') << 8) + '4')); puts(zptr6_str); zptr5 = zalloc_insert64(zptr5, 9874, 5478433443LU); zptr6_str = zalloc_insert64_str(zptr6_str, zalloc_size(zptr6_str) - 1, i64); puts(zptr6_str); zptr = zalloc_insert_ptr(zptr, 8, (void *)93842); return EXIT_SUCCESS; }