# HG changeset patch # User Markus Bröker # Date 1239878953 -7200 # Node ID 7739518acafb5b1067c28c6b65b14795ab77379c # Parent 966ad681f25d8ac042300b55e8e28ed6b4c56afe duff.c: * Large String support added * parameter num renamed to len committer: Markus Bröker diff --git a/duff.c b/duff.c --- a/duff.c +++ b/duff.c @@ -8,13 +8,13 @@ #include #include -char *duffcopy (char *to, char *from, int num) +char *duffcopy (char *to, char *from, int len) { int n, pos = 0; - n = (num + 7) / 8; + n = (len + 7) / 8; - switch (num % 8) { + switch (len % 8) { case 0: do { to[pos] = from[pos]; @@ -48,7 +48,8 @@ int main (int argc, char **argv) { - char to[80], *from; + char *to, *from; + int len; if (argc != 2) { printf ("Usage: %s \n", argv[0]); @@ -56,7 +57,18 @@ } from = argv[1]; + len = strlen (from) + 1; - printf ("DUFF: %s\n", duffcopy (to, from, strlen (from))); + if ((to = malloc (len)) == NULL) { + perror ("MALLOC"); + return EXIT_FAILURE; + } + + printf ("DUFF: %s\n", duffcopy (to, from, len)); + + if (to != NULL) { + free (to); + } + return EXIT_SUCCESS; }