[evolution-data-server] do not assume time_t is long



commit fa37efaf26d366a3d0d5256283455a28025ddbde
Author: Antoine Jacoutot <antoine mtier org>
Date:   Wed Sep 11 15:57:57 2013 +0200

    do not assume time_t is long
    
    On Linux time_t is long, on OpenBSD time_t is long long... so printf
    statements using %lu on 32-bit platforms will break on !Linux.
    The only portable way to print a time_t is using a cast and casting to
    "long long" (gint64) is probably the most portable way.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707900

 addressbook/backends/file/e-book-backend-file.c    |    2 +-
 addressbook/backends/ldap/e-book-backend-ldap.c    |    4 ++--
 calendar/libedata-cal/e-cal-backend-intervaltree.c |    4 ++--
 camel/camel-lock.c                                 |    2 +-
 camel/camel-search-sql-sexp.c                      |   12 ++++++------
 camel/providers/local/camel-maildir-summary.c      |    2 +-
 camel/providers/pop3/camel-pop3-folder.c           |    4 ++--
 tests/libedata-cal/test-cal-backend-sexp.c         |    2 +-
 tests/libedata-cal/test-intervaltree.c             |    2 +-
 9 files changed, 17 insertions(+), 17 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index e936b7e..0201c5c 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -613,7 +613,7 @@ e_book_backend_file_create_unique_id (void)
         * it's doubtful 2^32 id's will be created in a second, so we
         * should be okay. */
        static guint c = 0;
-       return g_strdup_printf (PAS_ID_PREFIX "%08lX%08X", time (NULL), c++);
+       return g_strdup_printf (PAS_ID_PREFIX "%08lX%08X", (glong) time (NULL), c++);
 }
 
 static gchar *
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index 41e608a..62b5b3e 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -1283,11 +1283,11 @@ create_dn_from_contact (EContact *contact,
        }
 
        dn = g_strdup_printf (
-               "%s=%s%s%lu",
+               "%s=%s%s%" G_GINT64_FORMAT,
                get_dn_attribute_name (rootdn, contact),
                (cn_part && *cn_part) ? cn_part : "",
                (cn_part && *cn_part) ? "." : "",
-               time (NULL));
+               (gint64) time (NULL));
 
        g_free (cn_part);
        g_free (cn);
diff --git a/calendar/libedata-cal/e-cal-backend-intervaltree.c 
b/calendar/libedata-cal/e-cal-backend-intervaltree.c
index ec29393..8ef66e5 100644
--- a/calendar/libedata-cal/e-cal-backend-intervaltree.c
+++ b/calendar/libedata-cal/e-cal-backend-intervaltree.c
@@ -761,8 +761,8 @@ e_intervaltree_node_dump (EIntervalTree *tree,
        */
        if (node != tree->priv->nil) {
                g_print (
-                       "%*s[%ld - %ld] [%ld - %ld] red %d\n", indent, "", node->start,
-                       node->end, node->min, node->max, node->red);
+                       "%*s[%" G_GINT64_FORMAT "- %" G_GINT64_FORMAT "] [%" G_GINT64_FORMAT "- %" 
G_GINT64_FORMAT "] red %d\n", indent, "", (gint64) node->start,
+                       (gint64) node->end, (gint64) node->min, (gint64) node->max, node->red);
        } else {
                g_print ("%*s[ - ]\n", indent, "");
                return;
diff --git a/camel/camel-lock.c b/camel/camel-lock.c
index 9695541..628a91a 100644
--- a/camel/camel-lock.c
+++ b/camel/camel-lock.c
@@ -128,7 +128,7 @@ camel_lock_dot (const gchar *path,
                /* check for stale lock, kill it */
                if (g_stat (lock, &st) == 0) {
                        time_t now = time (NULL);
-                       (printf ("There is an existing lock %ld seconds old\n", now - st.st_ctime));
+                       printf ("There is an existing lock %" G_GINT64_FORMAT "seconds old\n", (gint64) now - 
(gint64) st.st_ctime);
                        if (st.st_ctime < now - CAMEL_LOCK_DOT_STALE) {
                                d (printf ("Removing it now\n"));
                                unlink (lock);
diff --git a/camel/camel-search-sql-sexp.c b/camel/camel-search-sql-sexp.c
index 382089b..774bba1 100644
--- a/camel/camel-search-sql-sexp.c
+++ b/camel/camel-search-sql-sexp.c
@@ -188,7 +188,7 @@ eval_eq (struct _CamelSExp *f,
                if (r1->type == CAMEL_SEXP_RES_INT)
                        g_string_append_printf (str, "%d", r1->value.number);
                else if (r1->type == CAMEL_SEXP_RES_TIME)
-                       g_string_append_printf (str, "%ld", r1->value.time);
+                       g_string_append_printf (str, "%" G_GINT64_FORMAT, (gint64) r1->value.time);
                else if (r1->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf (str, "%s", r1->value.string);
 
@@ -206,7 +206,7 @@ eval_eq (struct _CamelSExp *f,
                        if (r2->type == CAMEL_SEXP_RES_BOOL)
                                g_string_append_printf (str, "%d", r2->value.boolean);
                        else if (r2->type == CAMEL_SEXP_RES_TIME)
-                               g_string_append_printf (str, "%ld", r2->value.time);
+                               g_string_append_printf (str, "%" G_GINT64_FORMAT, (gint64) r2->value.time);
                        else if (r2->type == CAMEL_SEXP_RES_STRING) {
                                gchar *tmp = g_strdup_printf ("%c%s%c", ut ? '%':' ', r2->value.string, ut ? 
'%':' ');
                                gchar *safe = get_db_safe_string (tmp);
@@ -244,7 +244,7 @@ eval_lt (struct _CamelSExp *f,
                if (r1->type == CAMEL_SEXP_RES_INT)
                        g_string_append_printf (str, "%d", r1->value.number);
                else if (r1->type == CAMEL_SEXP_RES_TIME)
-                       g_string_append_printf (str, "%ld", r1->value.time);
+                       g_string_append_printf (str, "%" G_GINT64_FORMAT, (gint64) r1->value.time);
                else if (r1->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf (str, "%s", r1->value.string);
 
@@ -254,7 +254,7 @@ eval_lt (struct _CamelSExp *f,
                if (r2->type == CAMEL_SEXP_RES_BOOL)
                        g_string_append_printf (str, "%d", r2->value.boolean);
                else if (r2->type == CAMEL_SEXP_RES_TIME)
-                       g_string_append_printf (str, "%ld", r2->value.time);
+                       g_string_append_printf (str, "%" G_GINT64_FORMAT, (gint64) r2->value.time);
                else if (r2->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf (str, "%s", r2->value.string);
                camel_sexp_result_free (f, r1);
@@ -286,7 +286,7 @@ eval_gt (struct _CamelSExp *f,
                if (r1->type == CAMEL_SEXP_RES_INT)
                        g_string_append_printf (str, "%d", r1->value.number);
                else if (r1->type == CAMEL_SEXP_RES_TIME)
-                       g_string_append_printf (str, "%ld", r1->value.time);
+                       g_string_append_printf (str, "%" G_GINT64_FORMAT, (gint64) r1->value.time);
                else if (r1->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf (str, "%s", r1->value.string);
 
@@ -296,7 +296,7 @@ eval_gt (struct _CamelSExp *f,
                if (r2->type == CAMEL_SEXP_RES_BOOL)
                        g_string_append_printf (str, "%d", r2->value.boolean);
                else if (r2->type == CAMEL_SEXP_RES_TIME)
-                       g_string_append_printf (str, "%ld", r2->value.time);
+                       g_string_append_printf (str, "%" G_GINT64_FORMAT, (gint64) r2->value.time);
                else if (r2->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf (str, "%s", r2->value.string);
                camel_sexp_result_free (f, r1);
diff --git a/camel/providers/local/camel-maildir-summary.c b/camel/providers/local/camel-maildir-summary.c
index 6e6466f..bd053ae 100644
--- a/camel/providers/local/camel-maildir-summary.c
+++ b/camel/providers/local/camel-maildir-summary.c
@@ -419,7 +419,7 @@ static gchar *maildir_summary_next_uid_string (CamelFolderSummary *s)
                                g_free (uid);
                                g_usleep (2 * G_USEC_PER_SEC);
                        }
-                       uid = g_strdup_printf ("%ld.%d_%u.%s", time (NULL), getpid (), nextuid, 
mds->priv->hostname);
+                       uid = g_strdup_printf ("%" G_GINT64_FORMAT ".%d_%u.%s", (gint64) time (NULL), getpid 
(), nextuid, mds->priv->hostname);
                        name = g_strdup_printf ("%s/tmp/%s", cls->folder_path, uid);
                        retry++;
                } while (g_stat (name, &st) == 0 && retry < 3);
diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c
index 8390ef9..8807cf2 100644
--- a/camel/providers/pop3/camel-pop3-folder.c
+++ b/camel/providers/pop3/camel-pop3-folder.c
@@ -1268,8 +1268,8 @@ camel_pop3_delete_old (CamelFolder *folder,
                        gint day_lag = time_diff / (60 * 60 * 24);
 
                        d (printf (
-                               "%s(%d): message_time= [%ld]\n",
-                               __FILE__, __LINE__, message_time));
+                               "%s(%d): message_time= [%" G_GINT64_FORMAT "]\n",
+                               __FILE__, __LINE__, (gint64) message_time));
                        d (printf (
                                "%s(%d): day_lag=[%d] \t days_to_delete=[%d]\n",
                                __FILE__, __LINE__, day_lag, days_to_delete));
diff --git a/tests/libedata-cal/test-cal-backend-sexp.c b/tests/libedata-cal/test-cal-backend-sexp.c
index 4641d1f..957c534 100644
--- a/tests/libedata-cal/test-cal-backend-sexp.c
+++ b/tests/libedata-cal/test-cal-backend-sexp.c
@@ -9,7 +9,7 @@ test_query (const gchar *query)
        gboolean generator = e_cal_backend_sexp_evaluate_occur_times (sexp, &start, &end);
 
        if (generator) {
-               printf ("%s: %ld - %ld\n", query, start, end);
+               printf ("%s: %" G_GINT64_FORMAT "- %" G_GINT64_FORMAT "\n", query, (gint64) start, (gint64) 
end);
        } else {
                printf ("%s: no time prunning possible\n", query);
        }
diff --git a/tests/libedata-cal/test-intervaltree.c b/tests/libedata-cal/test-intervaltree.c
index 45d9d30..248cf7c 100644
--- a/tests/libedata-cal/test-intervaltree.c
+++ b/tests/libedata-cal/test-intervaltree.c
@@ -166,7 +166,7 @@ create_test_component (time_t start,
        e_cal_component_set_dtend (comp, &dtend);
        */
 
-       summary.value = g_strdup_printf ("%ld - %ld", start, end);
+       summary.value = g_strdup_printf ("%" G_GINT64_FORMAT "- %" G_GINT64_FORMAT, (gint64) start, (gint64) 
end);
        summary.altrep = NULL;
 
        e_cal_component_set_summary (comp, &summary);


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