Skip to main content

Checkpoint: Portable Utility Core

Challenge on lesson: Checkpoint: Portable Utility Core

CHALLENGE
Difficulty: advanced+25 XP

ISO C. Implement the composed utility: int core_init(void) runs the endianness probe (1 little, 0 big) and stores it (see given static); int core_safe_copy(char *dst, size_t dstsize, const char *src) โ€” module 23's refusing copy (0 ok, -1 refuse, dst untouched on refusal); int core_frame(const char *payload, size_t plen, unsigned char *out, size_t outsz) โ€” write a 4-byte header (payload length, this platform's byte order via core_init's stored verdict, least-significant-byte-first when little-endian) then the payload bytes; refuse (-1) if 4+plen exceeds outsz or args are NULL; return 4+(int)plen on success. Implement int core_unframe(const unsigned char *in, size_t insz, char *out, size_t outsz) โ€” read the 4-byte header (same order rules), refuse if the claimed length exceeds insz-4 or outsz-1, copy payload and NUL-terminate; return the payload length, -1 on refusal.

Back to lesson: Checkpoint: Portable Utility Core