[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] Remove osdep.c/qemu-img code duplication
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH] Remove osdep.c/qemu-img code duplication |
Date: |
Wed, 02 Apr 2008 19:40:24 +0200 |
User-agent: |
Thunderbird 1.5.0.8 (X11/20060911) |
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 <address@hidden>
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 <malloc.h>
#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 <windows.h>
#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;
- [Qemu-devel] [PATCH] Remove osdep.c/qemu-img code duplication,
Kevin Wolf <=