Author: uwe Date: 2007-09-08 21:36:35 +0200 (Sat, 08 Sep 2007) New Revision: 496
Modified: LinuxBIOSv3/include/string.h LinuxBIOSv3/lib/lar.c Log: 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
Modified: LinuxBIOSv3/include/string.h =================================================================== --- LinuxBIOSv3/include/string.h 2007-09-07 17:53:47 UTC (rev 495) +++ LinuxBIOSv3/include/string.h 2007-09-08 19:36:35 UTC (rev 496) @@ -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 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 */
Modified: LinuxBIOSv3/lib/lar.c =================================================================== --- LinuxBIOSv3/lib/lar.c 2007-09-07 17:53:47 UTC (rev 495) +++ LinuxBIOSv3/lib/lar.c 2007-09-08 19:36:35 UTC (rev 496) @@ -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;