# HG changeset patch # User mru # Date 1182558066 0 # Node ID 6eb481ce83d96a7a494cd0b5d3d35995078f659e # Parent 2b2cae486387c1219253e0f3b8c1248eadc245f1 simplify pstrcpy() diff -r 2b2cae486387 -r 6eb481ce83d9 cutils.c --- a/cutils.c Fri Jun 22 22:35:55 2007 +0000 +++ b/cutils.c Sat Jun 23 00:21:06 2007 +0000 @@ -75,19 +75,12 @@ */ void pstrcpy(char *buf, int buf_size, const char *str) { - int c; - char *q = buf; - if (buf_size <= 0) return; - for(;;) { - c = *str++; - if (c == 0 || q >= buf + buf_size - 1) - break; - *q++ = c; - } - *q = '\0'; + while (buf_size-- > 1 && *str) + *buf++ = *str++; + *buf = 0; } /* strcat and truncate. */