💾 Archived View for thrig.me › blog › 2023 › 05 › 05 › cpy1.c captured on 2023-05-24 at 18:10:23.
-=-=-=-=-=-=-
// 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); }