From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jh722-0002RJ-6d for qemu-devel@nongnu.org; Wed, 02 Apr 2008 13:45:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jh720-0002QY-JV for qemu-devel@nongnu.org; Wed, 02 Apr 2008 13:45:53 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jh720-0002QS-84 for qemu-devel@nongnu.org; Wed, 02 Apr 2008 13:45:52 -0400 Received: from mx2.suse.de ([195.135.220.15]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jh71z-0002LB-Lr for qemu-devel@nongnu.org; Wed, 02 Apr 2008 13:45:52 -0400 Received: from Relay2.suse.de (relay-ext.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 6CAA844572 for ; Wed, 2 Apr 2008 19:45:48 +0200 (CEST) Message-ID: <47F3C508.8040002@suse.de> Date: Wed, 02 Apr 2008 19:40:24 +0200 From: Kevin Wolf MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060500000701010509060403" Subject: [Qemu-devel] [PATCH] Remove osdep.c/qemu-img code duplication Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------060500000701010509060403 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit There are few helper functions (e.g. qemu_malloc) in osdep.c which are not OS dependent at all. Even the first CVS commit comment for osdep.c says "most functions are generic in fact". They are duplicated in qemu-img because osdep.c isn't used there. This patch moves those functions to cutils.c and removes the duplicates from qemu-img. Signed-off-by: Kevin Wolf --------------060500000701010509060403 Content-Type: text/x-patch; name="qemu-remove-duplication.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-remove-duplication.patch" Index: Makefile.target =================================================================== --- Makefile.target (Revision 4156) +++ Makefile.target (Arbeitskopie) @@ -430,6 +430,7 @@ endif OBJS+= libqemu.a +OBJS+= ../libqemu_common.a # Note: this is a workaround. The real fix is to avoid compiling # cpu_signal_handler() in cpu-exec.c. Index: osdep.c =================================================================== --- osdep.c (Revision 4156) +++ osdep.c (Arbeitskopie) @@ -45,21 +45,6 @@ #include #endif -void *get_mmap_addr(unsigned long size) -{ - return NULL; -} - -void qemu_free(void *ptr) -{ - free(ptr); -} - -void *qemu_malloc(size_t size) -{ - return malloc(size); -} - #if defined(_WIN32) void *qemu_memalign(size_t alignment, size_t size) { @@ -217,26 +202,6 @@ #endif -void *qemu_mallocz(size_t size) -{ - void *ptr; - ptr = qemu_malloc(size); - if (!ptr) - return NULL; - memset(ptr, 0, size); - return ptr; -} - -char *qemu_strdup(const char *str) -{ - char *ptr; - ptr = qemu_malloc(strlen(str) + 1); - if (!ptr) - return NULL; - strcpy(ptr, str); - return ptr; -} - int qemu_create_pidfile(const char *filename) { char buffer[128]; Index: osdep.h =================================================================== --- osdep.h (Revision 4156) +++ osdep.h (Arbeitskopie) @@ -47,17 +47,10 @@ #define qemu_printf printf -void *qemu_malloc(size_t size); -void *qemu_mallocz(size_t size); -void qemu_free(void *ptr); -char *qemu_strdup(const char *str); - void *qemu_memalign(size_t alignment, size_t size); void *qemu_vmalloc(size_t size); void qemu_vfree(void *ptr); -void *get_mmap_addr(unsigned long size); - int qemu_create_pidfile(const char *filename); #ifdef _WIN32 Index: cutils.c =================================================================== --- cutils.c (Revision 4156) +++ cutils.c (Arbeitskopie) @@ -95,3 +95,38 @@ t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; return t; } + +void *get_mmap_addr(unsigned long size) +{ + return NULL; +} + +void qemu_free(void *ptr) +{ + free(ptr); +} + +void *qemu_malloc(size_t size) +{ + return malloc(size); +} + +void *qemu_mallocz(size_t size) +{ + void *ptr; + ptr = qemu_malloc(size); + if (!ptr) + return NULL; + memset(ptr, 0, size); + return ptr; +} + +char *qemu_strdup(const char *str) +{ + char *ptr; + ptr = qemu_malloc(strlen(str) + 1); + if (!ptr) + return NULL; + strcpy(ptr, str); + return ptr; +} Index: qemu-common.h =================================================================== --- qemu-common.h (Revision 4156) +++ qemu-common.h (Arbeitskopie) @@ -86,6 +86,14 @@ int stristart(const char *str, const char *val, const char **ptr); time_t mktimegm(struct tm *tm); +void *qemu_malloc(size_t size); +void *qemu_mallocz(size_t size); +void qemu_free(void *ptr); +char *qemu_strdup(const char *str); + +void *get_mmap_addr(unsigned long size); + + /* Error handling. */ void hw_error(const char *fmt, ...) Index: qemu-img.c =================================================================== --- qemu-img.c (Revision 4156) +++ qemu-img.c (Arbeitskopie) @@ -30,41 +30,6 @@ #include #endif -void *get_mmap_addr(unsigned long size) -{ - return NULL; -} - -void qemu_free(void *ptr) -{ - free(ptr); -} - -void *qemu_malloc(size_t size) -{ - return malloc(size); -} - -void *qemu_mallocz(size_t size) -{ - void *ptr; - ptr = qemu_malloc(size); - if (!ptr) - return NULL; - memset(ptr, 0, size); - return ptr; -} - -char *qemu_strdup(const char *str) -{ - char *ptr; - ptr = qemu_malloc(strlen(str) + 1); - if (!ptr) - return NULL; - strcpy(ptr, str); - return ptr; -} - static void __attribute__((noreturn)) error(const char *fmt, ...) { va_list ap; --------------060500000701010509060403--