[libvirt-php][PATCH 06/11] src: Introduce util.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



So far there is just one function shared across our code:
get_datetime().

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/Makefile.am   |  2 +-
 src/config.m4     |  2 +-
 src/libvirt-php.c | 26 --------------------------
 src/util.c        | 41 +++++++++++++++++++++++++++++++++++++++++
 src/util.h        |  2 ++
 5 files changed, 45 insertions(+), 28 deletions(-)
 create mode 100644 src/util.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 39a47e9..a12e729 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,7 +18,7 @@ LIBVIRT_PHP_SYMBOL_FILE = \
 php_plugindir = $(extensiondir)
 php_plugin_LTLIBRARIES = libvirt-php.la
 libvirt_php_la_SOURCES = \
-	util.h	\
+	util.c util.h	\
 	vncfunc.c \
 	sockets.c \
 	libvirt-php.c libvirt-php.h
diff --git a/src/config.m4 b/src/config.m4
index fd76286..ad8adb4 100644
--- a/src/config.m4
+++ b/src/config.m4
@@ -45,7 +45,7 @@ if test "$PHP_LIBVIRT" != "no"; then
     PHP_EVAL_LIBLINE($LIBXML_LIBRARY, LIBVIRT_SHARED_LIBADD)
 
     PHP_SUBST(LIBVIRT_SHARED_LIBADD)
-    PHP_NEW_EXTENSION(libvirt, libvirt-php.c sockets.c vncfunc.c, $ext_shared)
+    PHP_NEW_EXTENSION(libvirt, libvirt-php.c sockets.c vncfunc.c util.c, $ext_shared)
   else
     AC_MSG_ERROR(pkg-config not found)
   fi
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index b9256db..70405f2 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -862,32 +862,6 @@ PHP_RSHUTDOWN_FUNCTION(libvirt)
 }
 
 /*
- * Private function name:   get_datetime
- * Since version:           0.4.2
- * Description:             Function can be used to get date and time in the `YYYY-mm-dd HH:mm:ss` format, internally used for logging when debug logging is enabled using libvirt_set_logfile() API function.
- * Arguments:               None
- * Returns:                 Date/time string in `YYYY-mm-dd HH:mm:ss` format
- */
-char *get_datetime(void)
-{
-    /* Caution: Function cannot use DPRINTF() macro otherwise the neverending loop will be met! */
-    char *outstr = NULL;
-    time_t t;
-    struct tm *tmp;
-
-    t = time(NULL);
-    tmp = localtime(&t);
-    if (tmp == NULL)
-        return NULL;
-
-    outstr = (char *)malloc(32 * sizeof(char));
-    if (strftime(outstr, 32, "%Y-%m-%d %H:%M:%S", tmp) == 0)
-        return NULL;
-
-    return outstr;
-}
-
-/*
  * Private function name:   set_logfile
  * Since version:           0.4.2
  * Description:             Function to set the log file. You can set log file to NULL to disable logging (default). Useful for debugging purposes.
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..7d2b457
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,41 @@
+/*
+ * util.c: common, generic utility functions
+ *
+ * See COPYING for the license of this software
+ *
+ * Written by:
+ *      Michal Privoznik <mprivozn@xxxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <time.h>
+
+#include "util.h"
+
+/*
+ * Private function name:   get_datetime
+ * Since version:           0.4.2
+ * Description:             Function can be used to get date and time in the `YYYY-mm-dd HH:mm:ss` format, internally used for logging when debug logging is enabled using libvirt_set_logfile() API function.
+ * Arguments:               None
+ * Returns:                 Date/time string in `YYYY-mm-dd HH:mm:ss` format
+ */
+char *get_datetime(void)
+{
+    /* Caution: Function cannot use DPRINTF() macro otherwise the neverending loop will be met! */
+    char *outstr = NULL;
+    time_t t;
+    struct tm *tmp;
+
+    t = time(NULL);
+    tmp = localtime(&t);
+    if (tmp == NULL)
+        return NULL;
+
+    outstr = (char *)malloc(32 * sizeof(char));
+    if (strftime(outstr, 32, "%Y-%m-%d %H:%M:%S", tmp) == 0)
+        return NULL;
+
+    return outstr;
+}
diff --git a/src/util.h b/src/util.h
index 119d573..e907a49 100644
--- a/src/util.h
+++ b/src/util.h
@@ -60,4 +60,6 @@ extern int gdebug;
                ((uint32_t)var[2] <<  8) +   \
                ((uint32_t)var[3]))
 
+char *get_datetime(void);
+
 #endif /* __UTIL_H__ */
-- 
2.8.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]