Move some suitable functions there, add it to the Makefile, but leave the declarations in flash.h for now.
Signed-off-by: Stefan Tauner stefan.tauner@alumni.tuwien.ac.at --- Makefile | 2 +- flash.h | 11 +++++++---- flashrom.c | 36 ------------------------------------ helpers.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 helpers.c
diff --git a/Makefile b/Makefile index d3c1ba5..7a48889 100644 --- a/Makefile +++ b/Makefile @@ -353,7 +353,7 @@ CHIP_OBJS = jedec.o stm50.o w39.o w29ee011.o \ ############################################################################### # Library code.
-LIB_OBJS = layout.o flashrom.o udelay.o programmer.o +LIB_OBJS = layout.o flashrom.o udelay.o programmer.o helpers.o
############################################################################### # Frontend related stuff. diff --git a/flash.h b/flash.h index cf496b6..7949628 100644 --- a/flash.h +++ b/flash.h @@ -241,6 +241,13 @@ char *flashbuses_to_text(enum chipbustype bustype); int print_supported(void); void print_supported_wiki(void);
+/* helpers.c */ +void tolower_string(char *str); +char *strcat_realloc(char *dest, const char *src); +int min(int a, int b); +int max(int a, int b); +int bitcount(unsigned long a); + /* flashrom.c */ extern int verbose_screen; extern int verbose_logfile; @@ -251,13 +258,9 @@ int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, uns int erase_flash(struct flashctx *flash); int probe_flash(struct registered_programmer *pgm, int startchip, struct flashctx *fill_flash, int force); int read_flash_to_file(struct flashctx *flash, const char *filename); -int min(int a, int b); -int max(int a, int b); -void tolower_string(char *str); char *extract_param(const char *const *haystack, const char *needle, const char *delim); int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len); int need_erase(const uint8_t *have, const uint8_t *want, unsigned int len, enum write_granularity gran); -char *strcat_realloc(char *dest, const char *src); void print_version(void); void print_buildinfo(void); void print_banner(void); diff --git a/flashrom.c b/flashrom.c index f8978f1..5a07e79 100644 --- a/flashrom.c +++ b/flashrom.c @@ -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 diff --git a/helpers.c b/helpers.c new file mode 100644 index 0000000..02cad43 --- /dev/null +++ b/helpers.c @@ -0,0 +1,60 @@ +/* + * This file is part of the flashrom project. + * + * Copyright (C) 2009-2010 Carl-Daniel Hailfinger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <ctype.h> +#include <stdlib.h> +#include <string.h> +#include "flash.h" + +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; +}