OSDN Git Service

Re-organize console out and logging out
[openpts/openpts.git] / src / uuid_libuuid.c
index 943f73e..ef5cec2 100644 (file)
@@ -26,7 +26,7 @@
  * \brief UUID wrapper (libuuid part)
  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
  * @date 2010-11-29
- * cleanup 2011-10-07 SM
+ * cleanup 2011-12-31 SM
  *
  * Linux uses libuuid
  *
@@ -69,7 +69,7 @@ time_t uuid_time(uuid_t uu, struct timeval *tv) {
     myUUID.clock_seq_hi_and_reserved = uu[8];
 
     if ((myUUID.clock_seq_hi_and_reserved & 0xc0) != 0x80) {
-        ERROR("uuid_time() - bad UUID variant (0x%02x) found, can't extract timestamp\n",
+        LOG(LOG_ERR, "uuid_time() - bad UUID variant (0x%02x) found, can't extract timestamp\n",
             (myUUID.clock_seq_hi_and_reserved & 0xc0) >> 4);
         return (time_t)-1;
     }
@@ -94,6 +94,7 @@ PTS_UUID *newUuid() {
 
     uuid = xmalloc(sizeof(PTS_UUID));  // BYTE[16]
     if (uuid == NULL) {
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -107,6 +108,12 @@ PTS_UUID *newUuid() {
  * free UUID
  */
 void freeUuid(PTS_UUID *uuid) {
+    /* check */
+    if (uuid == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+
     xfree(uuid);
 }
 
@@ -119,16 +126,22 @@ PTS_UUID *getUuidFromString(char *str) {
     uuid_t uu;
     int rc;
 
+    /* check */
+    if (str == NULL) {
+        LOG(LOG_ERR, "null input");
+        return NULL;
+    }
+
     rc = uuid_parse(str, uu);
     if (rc != 0) {
-        ERROR("getUuidFromString() - uuid_parse fail, rc=%d, UUID='%s'\n",
+        LOG(LOG_ERR, "getUuidFromString() - uuid_parse fail, rc=%d, UUID='%s'",
             rc, str);
         return NULL;
     }
 
     uuid = xmalloc(sizeof(PTS_UUID));
     if (uuid == NULL) {
-        ERROR("\n");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memcpy(uuid, uu, 16);
@@ -143,8 +156,15 @@ char * getStringOfUuid(PTS_UUID *uuid) {
     char *str_uuid;
     uuid_t uu;
 
+    /* check */
+    if (uuid == NULL) {
+        LOG(LOG_ERR, "null input");
+        return NULL;
+    }
+
     str_uuid = xmalloc(37);
     if (str_uuid == NULL) {
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -196,7 +216,7 @@ PTS_DateTime * getDateTimeOfUuid(PTS_UUID *uuid) {
 
     /* check */
     if (uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return NULL;
     }
 
@@ -208,6 +228,7 @@ PTS_DateTime * getDateTimeOfUuid(PTS_UUID *uuid) {
 
     pdt = xmalloc(sizeof(PTS_DateTime));
     if (pdt == NULL) {
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memcpy(pdt, &time, (9*4));
@@ -230,6 +251,7 @@ PTS_DateTime * getDateTime() {
 
     pdt = xmalloc(sizeof(PTS_DateTime));
     if (pdt == NULL) {
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memcpy(pdt, &ttm, (9*4));