lkml.org 
[lkml]   [2003]   [May]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Date
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/

\
 
 \ /
  Last update: 2005-03-22 13:35    [from the cache]
©2003-2011 Jasper Spaans