simplify pstrcpy()

Originally committed as revision 9391 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Måns Rullgård 2007-06-23 00:21:06 +00:00
parent 12a6f28928
commit 26301cb806
1 changed files with 3 additions and 10 deletions

View File

@ -75,19 +75,12 @@ int stristart(const char *str, const char *val, const char **ptr)
*/ */
void pstrcpy(char *buf, int buf_size, const char *str) void pstrcpy(char *buf, int buf_size, const char *str)
{ {
int c;
char *q = buf;
if (buf_size <= 0) if (buf_size <= 0)
return; return;
for(;;) { while (buf_size-- > 1 && *str)
c = *str++; *buf++ = *str++;
if (c == 0 || q >= buf + buf_size - 1) *buf = 0;
break;
*q++ = c;
}
*q = '\0';
} }
/* strcat and truncate. */ /* strcat and truncate. */