1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-02 14:33:18 +02:00

Introduce helpers.c

Move some suitable functions there, add it to the Makefile, but leave the
declarations in flash.h for now.

Corresponding to flashrom svn r1819.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
Stefan Tauner
2014-06-12 00:04:32 +00:00
parent a60d408a78
commit 6ad6e01e9b
5 changed files with 81 additions and 52 deletions

View File

@ -535,42 +535,6 @@ int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start,
return 0;
}
int min(int a, int b)
{
return (a < b) ? a : b;
}
int max(int a, int b)
{
return (a > b) ? a : b;
}
int bitcount(unsigned long a)
{
int i = 0;
for (; a != 0; a >>= 1)
if (a & 1)
i++;
return i;
}
void tolower_string(char *str)
{
for (; *str != '\0'; str++)
*str = (char)tolower((unsigned char)*str);
}
char *strcat_realloc(char *dest, const char *src)
{
dest = realloc(dest, strlen(dest) + strlen(src) + 1);
if (!dest) {
msg_gerr("Out of memory!\n");
return NULL;
}
strcat(dest, src);
return dest;
}
/* This is a somewhat hacked function similar in some ways to strtok().
* It will look for needle with a subsequent '=' in haystack, return a copy of
* needle and remove everything from the first occurrence of needle to the next