global int strncopy (char *s, char *d, int sz) {
  char *origd

  origd = d
  while ((*s != 0) && sz > 0) {
    *d = *s
    s = s + 1
    d = d + 1
    sz = sz - 1
  }
  if (*d != 0) {
    *d = 0
  }
  return origd
}
