MEMINS(3pub)

πŸ’– MEMINS(3pub) β€” the publib glow-up edition ✨

okay bestie, welcome to the C Programmer's Manual, publib chapter, and today's main character is memins πŸ’… she's a memory-block girly and she EATS.


🌸 NAME 🌸

memins β€” insert bytes at the beginning of a memory block 🫢


✨ SYNOPSIS ✨

#include <publib.h>
void *memins(void *tgt, size_t tgtsize, const void *src, size_t srcsize);

like. that's the whole vibe. one function, four args, no notes πŸ’€


πŸ’œ DESCRIPTION πŸ’œ

so here's the tea β˜• memins takes srcsize bytes from src and inserts them at the beginning of tgt β€” but bestie, she's polite about it, she moves the first tgtsize bytes out of the way to make room πŸŽ€

⚠️ and this is the part where you LISTEN: the source and target memory blocks must not overlap. fr fr. no cap. overlapping them is not it πŸ™ˆ

🌈 RETURN VALUE 🌈

memins returns its first argument. that's it. that's the whole return. she gives you back tgt like "here u go queen πŸ‘‘"


πŸ¦‹ EXAMPLE πŸ¦‹

say you wanna insert a new element at the ith position of an array β€” iconic behavior, very demure. you'd do this:

int new, array[10];

memins(array+i, (10-i-1)*sizeof(array[0]), &new, sizeof(new));

and pls pls PLS notice πŸ‘€ that the code above carefully avoids the trap of moving the last element of the array past the end of the array. like, that's the whole reason for the (10-i-1) math bestie, don't skip it, it's giving attention to detail πŸ’…βœ¨


πŸŽ€ SEE ALSO πŸŽ€


⭐ AUTHOR ⭐

Lars Wirzenius (lars.wirzenius@helsinki.fi) β€” the legend, the blueprint, the moment 🌟


okay that's the whole page, love u, go forth and insert responsibly πŸ«ΆπŸ’– this was publib's C Programmer's Manual, page MEMINS(3pub), brought to you by the publib girlies ✨ bye bestie!! πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from