changeset 2180:6eb481ce83d9 libavformat

simplify pstrcpy()
author mru
date Sat, 23 Jun 2007 00:21:06 +0000
parents 2b2cae486387
children 99f7793b7311
files cutils.c
diffstat 1 files changed, 3 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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. */