You'll anger the gods with gchar
Adam Stokes
On May 2, 2011, at 6:32 PM, Russell Bryant <russell(a)russellbryant.net> wrote:
Instead of implementing a custom version of asprintf(), use an
equivalent function provided by glib.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/CMakeLists.txt | 2 --
src/include/config.h.in | 1 -
src/include/matahari/services.h | 2 +-
src/include/matahari/utilities.h | 11 -----------
src/lib/services.c | 10 +++++-----
src/lib/services_linux.c | 6 +++---
src/lib/services_private.h | 2 +-
src/lib/utilities.c | 32 --------------------------------
8 files changed, 10 insertions(+), 56 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b55f339..18bc6df 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -33,8 +33,6 @@ file(GLOB SCHEMAS "${CMAKE_CURRENT_SOURCE_DIR}/*.xml")
include (CheckIncludeFiles)
check_include_files (string.h HAVE_STRING_H)
check_include_files (sys/ioctl.h HAVE_SYS_IOCTL_H)
-include (CheckFunctionExists)
-check_function_exists (asprintf HAVE_ASPRINTF)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/matahari.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/matahari.h)
diff --git a/src/include/config.h.in b/src/include/config.h.in
index 9f2989c..e67866b 100644
--- a/src/include/config.h.in
+++ b/src/include/config.h.in
@@ -1,3 +1,2 @@
#cmakedefine HAVE_STRING_H 1
#cmakedefine HAVE_SYS_IOCTL_H 1
-#cmakedefine HAVE_ASPRINTF 1
diff --git a/src/include/matahari/services.h b/src/include/matahari/services.h
index 0a48bb8..edfd716 100644
--- a/src/include/matahari/services.h
+++ b/src/include/matahari/services.h
@@ -85,7 +85,7 @@ enum op_status {
typedef struct svc_action_private_s svc_action_private_t;
typedef struct svc_action_s
{
- char *id;
+ gchar *id;
char *rsc;
char *action;
int interval;
diff --git a/src/include/matahari/utilities.h b/src/include/matahari/utilities.h
index e48be25..545d274 100644
--- a/src/include/matahari/utilities.h
+++ b/src/include/matahari/utilities.h
@@ -36,17 +36,6 @@ extern const char *mh_hostname(void);
extern void mh_abort(const char *file, const char *function, int line,
const char *assert_condition, int do_core, int do_fork);
-#ifndef HAVE_ASPRINTF
-/**
- * Custom implementation of asprintf()
- *
- * This version of asprintf() is only used when the build system doesn't find
- * asprintf() on the system. For more information on how to use asprintf(),
- * see its man page.
- */
-extern int asprintf(char **ret, const char *fmt, ...);
-#endif
-
#define DIMOF(a) ((int) (sizeof(a) / sizeof(0[a])))
#ifndef __GNUC__
diff --git a/src/lib/services.c b/src/lib/services.c
index fc20165..87a40c7 100644
--- a/src/lib/services.c
+++ b/src/lib/services.c
@@ -47,7 +47,7 @@ svc_action_t *services_action_create(
op->timeout = timeout;
op->rclass = strdup("lsb");
op->agent = strdup(name);
- asprintf(&op->id, "%s_%s_%d", name, action, interval);
+ op->id = g_strdup_printf("%s_%s_%d", name, action, interval);
services_os_set_exec(op);
@@ -70,8 +70,8 @@ svc_action_t *resources_action_create(
op->agent = strdup(agent);
op->provider = strdup(provider);
op->params = params;
- asprintf(&op->id, "%s_%s_%d", name, action, interval);
- asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT,
+ op->id = g_strdup_printf("%s_%s_%d", name, action, interval);
+ op->opaque->exec = g_strdup_printf("%s/resource.d/%s/%s", OCF_ROOT,
provider, agent);
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(action);
@@ -85,8 +85,8 @@ void services_action_free(svc_action_t *op)
return;
}
- free(op->id);
- free(op->opaque->exec);
+ g_free(op->id);
+ g_free(op->opaque->exec);
free(op->opaque->args[0]);
free(op->opaque->args[1]);
diff --git a/src/lib/services_linux.c b/src/lib/services_linux.c
index 3a54386..84c4cb8 100644
--- a/src/lib/services_linux.c
+++ b/src/lib/services_linux.c
@@ -433,21 +433,21 @@ void
services_os_set_exec(svc_action_t* op)
{
if(strcmp("enable", op->action) == 0) {
- op->opaque->exec = strdup("/sbin/chkconfig");
+ op->opaque->exec = g_strdup("/sbin/chkconfig");
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(op->agent);
op->opaque->args[2] = strdup("on");
op->opaque->args[3] = NULL;
} else if(strcmp("disable", op->action) == 0) {
- op->opaque->exec = strdup("/sbin/chkconfig");
+ op->opaque->exec = g_strdup("/sbin/chkconfig");
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(op->agent);
op->opaque->args[2] = strdup("off");
op->opaque->args[3] = NULL;
} else {
- asprintf(&op->opaque->exec, "%s/%s", LSB_ROOT,
op->agent);
+ op->opaque->exec = g_strdup_printf("%s/%s", LSB_ROOT,
op->agent);
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(op->action);
op->opaque->args[2] = NULL;
diff --git a/src/lib/services_private.h b/src/lib/services_private.h
index 2b30228..68bd5f5 100644
--- a/src/lib/services_private.h
+++ b/src/lib/services_private.h
@@ -1,6 +1,6 @@
struct svc_action_private_s
{
- char *exec;
+ gchar *exec;
char *args[4];
gboolean cancel;
diff --git a/src/lib/utilities.c b/src/lib/utilities.c
index 1151c00..973bba4 100644
--- a/src/lib/utilities.c
+++ b/src/lib/utilities.c
@@ -394,35 +394,3 @@ mh_uuid(void)
mh_trace("Got uuid: %s", uuid);
return uuid;
}
-
-#ifndef HAVE_ASPRINTF
-int
-asprintf(char **ret, const char *fmt, ...)
-{
- va_list ap;
- int len;
- char buf[1];
-
- /*
- * Ask vsnprintf() how many characters it would write if the buffer
- * were big enough.
- */
- va_start(ap, fmt);
- len = vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
-
- /*
- * Now go allocate a buffer that is big enough.
- */
- *ret = malloc(len + 1);
-
- /*
- * Now vsnprintf() the string into the final result buffer.
- */
- va_start(ap, fmt);
- vsnprintf(*ret, len + 1, fmt, ap);
- va_end(ap);
-
- return len;
-}
-#endif /* HAVE_ASPRINTF */
--
1.7.4.4
_______________________________________________
Matahari mailing list
Matahari(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/matahari