utfecpy.c 282 B

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