Messages in this thread | | | From | "Riley Williams" <> | Subject | RE: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE | Date | Sun, 25 May 2003 18:25:12 +0100 |
| |
Hi Matt.
>> How about just adding a sane >> >> int copy_string(char *dest, const char *src, int len) >> { >> int size; >> >> if (!len) >> return 0; >> size = strlen(src); >> if (size >= len) >> size = len-1; >> memcpy(dest, src, size); >> dest[size] = '\0'; >> return size; >> }
> The return value here isn't particularly useful. The OpenBSD > strlcpy/strlcat variant tell you how big the result should have been > so that you can realloc if need be.
Something along the lines of...
int strlcpy(char *tgt, char *src, int len) { int size = strlen(src);
if (size < len) strcpy(tgt, src); else { memcpy(tgt, src, len-1); tgt[len] = '\0'; } return size; }
...reindented according to standards (which I don't have to hand).
Best wishes from Riley. --- * Nothing as pretty as a smile, nothing as ugly as a frown.
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.483 / Virus Database: 279 - Release Date: 19-May-2003
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |