#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/* not completely the same as ISO/IEC memmove_s */
#define memmove_s(d, dz, s, sz) memmove((d), (s), ((dz)<=(sz)?(dz):(sz)))

struct {
  char buf[16+1];
  char foo[16+1];
} bar = {
  "0123456789abcdef",
  "****************",
};

int main(int argc, char *argv[])
{
  if (argc == 3+1) {
    int d = atoi(argv[1]);
    int s = atoi(argv[2]);
    int l = atoi(argv[3]);

    if (d < 0 || s < 0 || l < 0) return 1;
    printf("memmove(buf+%d, buf+%d, %d)\n", d, s, l);
#if defined(UNSAFE)
    memmove(bar.buf+d, bar.buf+s, l);
#else
    memmove_s(bar.buf+d, sizeof(bar.buf)-d, bar.buf+s, l);
    /*bar.buf[sizeof(bar.buf)-1] = '\0';*/
#endif
  }
  puts(bar.buf);
  return 0;
}
