utfecpy.c 267 B

1234567891011121314151617181920
  1. #include "lib9.h"
  2. char*
  3. utfecpy(char *to, char *e, char *from)
  4. {
  5. char *end;
  6. if(to >= e)
  7. return to;
  8. end = memccpy(to, from, '\0', e - to);
  9. if(end == nil){
  10. end = e;
  11. while(end>to && (*--end&0xC0)==0x80)
  12. ;
  13. *end = '\0';
  14. }else{
  15. end--;
  16. }
  17. return end;
  18. }