💾 Archived View for thrig.me › blog › 2023 › 05 › 05 › cpy1.c captured on 2024-03-21 at 15:52:30.
⬅️ Previous capture (2023-05-24)
-=-=-=-=-=-=-
// cpy1 - test strlcpy #include <stdio.h> #include <string.h> #define MAXLEN 3 union { char buf[MAXLEN]; char overlay[MAXLEN * 2]; } bar; int main(void) { char *toolong = "verymuchtoolongofaninputstring"; for (int i = 0; i < MAXLEN * 2; i++) { bar.overlay[i] = 'x'; } strlcpy(bar.buf, toolong, MAXLEN); fprintf(stderr, "%s\n%s\n", bar.buf, bar.overlay); }