/* Public domain. */

#include "byte.h"
#include "str.h"

int str_copyn(char *d, int dlen, const char* s, int slen) {
  if(slen < 0)
    slen = str_len(s);

  if(dlen <= slen) {
    byte_copy(d, dlen, s);
    d[dlen-1] = '\0';
    return dlen;
  }
  else {
    byte_copy(d, slen, s);
    d[slen] = '\0';
    return slen;
  }
}
