Hi, attached patch adds:
1, simple strncmp implementation in include/string.h 2, changes lib/lar.c to use strncmp for magic check. Current code depends on that the len field will never hold a value bigger than 0xffffff, which is a working assumption given current flash sizes, but my next patch might affect this. -- Alex
Signed-off-by: Alex Beregszaszi <[EMAIL PROTECTED]> Index: lib/lar.c =================================================================== --- lib/lar.c (revision 494) +++ lib/lar.c (working copy) @@ -92,7 +92,7 @@ for (walk = archive->start; (walk < (char *)(archive->start + archive->len - sizeof(struct lar_header))) && (walk >= (char *)archive->start); walk += 16) { - if (strcmp(walk, MAGIC) != 0) + if (strncmp(walk, MAGIC, 8) != 0) continue; header = (struct lar_header *)walk;
Signed-off-by: Alex Beregszaszi <[EMAIL PROTECTED]> Index: include/string.h =================================================================== --- include/string.h (revision 494) +++ include/string.h (working copy) @@ -110,4 +110,24 @@ return c1 - c2; } +/** + * Compare two strings with fixed length. + * + * @param s1 The first string. + * @param s2 The second string. + * @param maxlen Return at most maxlen characters as length of the string. + * @return Returns a non-zero value if s1 and s2 differ. Returns zero, + * if s1 equals s2. + */ +static inline int strncmp(const char *s1, const char *s2, int maxlen) +{ + int i; + + for (i = 0; i < maxlen; i++) + if (s1[i] != s2[i]) + return s1[i] - s2[i]; + + return 0; +} + #endif /* STRING_H */
-- linuxbios mailing list linuxbios@linuxbios.org http://www.linuxbios.org/mailman/listinfo/linuxbios