Add a simple strncmp() implementation in include/string.h.

Change 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.

Signed-off-by: Alex Beregszaszi <alex@rtfs.hu>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>



git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@496 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Uwe Hermann 2007-09-08 19:36:35 +00:00
parent b200a2927c
commit 872be1d31b
2 changed files with 21 additions and 1 deletions

View file

@ -110,4 +110,24 @@ static inline int strcmp(const char *s1, const char *s2)
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 A non-zero value if s1 and s2 differ, or 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 */

View file

@ -92,7 +92,7 @@ int find_file(struct mem_file *archive, const char *filename, struct mem_file *r
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;