[gtk+] xsettings: Use glib byte order functions



commit d7ea5b526617d9e29c85927f38e80d38196a41e3
Author: Benjamin Otte <otte redhat com>
Date:   Sat Feb 2 19:10:02 2013 +0100

    xsettings: Use glib byte order functions

 gdk/x11/xsettings-client.c |   16 ++++++----------
 gdk/x11/xsettings-common.c |    7 -------
 gdk/x11/xsettings-common.h |    3 ---
 3 files changed, 6 insertions(+), 20 deletions(-)
---
diff --git a/gdk/x11/xsettings-client.c b/gdk/x11/xsettings-client.c
index f4b0e38..fb97f95 100644
--- a/gdk/x11/xsettings-client.c
+++ b/gdk/x11/xsettings-client.c
@@ -95,8 +95,6 @@ ignore_errors (Display *display, XErrorEvent *event)
   return True;
 }
 
-static char local_byte_order = '\0';
-
 #define BYTES_LEFT(buffer) ((buffer)->data + (buffer)->len - (buffer)->pos)
 
 static XSettingsResult
@@ -111,10 +109,10 @@ fetch_card16 (XSettingsBuffer *buffer,
   x = *(CARD16 *)buffer->pos;
   buffer->pos += 2;
   
-  if (buffer->byte_order == local_byte_order)
-    *result = x;
+  if (buffer->byte_order == MSBFirst)
+    *result = GUINT16_FROM_BE (x);
   else
-    *result = (x << 8) | (x >> 8);
+    *result = GUINT16_FROM_LE (x);
 
   return XSETTINGS_SUCCESS;
 }
@@ -145,10 +143,10 @@ fetch_card32 (XSettingsBuffer *buffer,
   x = *(CARD32 *)buffer->pos;
   buffer->pos += 4;
   
-  if (buffer->byte_order == local_byte_order)
-    *result = x;
+  if (buffer->byte_order == MSBFirst)
+    *result = GUINT32_FROM_BE (x);
   else
-    *result = (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
+    *result = GUINT32_FROM_LE (x);
   
   return XSETTINGS_SUCCESS;
 }
@@ -180,8 +178,6 @@ parse_settings (unsigned char *data,
   CARD32 i;
   XSettingsSetting *setting = NULL;
   
-  local_byte_order = xsettings_byte_order ();
-
   buffer.pos = buffer.data = data;
   buffer.len = len;
   
diff --git a/gdk/x11/xsettings-common.c b/gdk/x11/xsettings-common.c
index 6f66a40..9c2f677 100644
--- a/gdk/x11/xsettings-common.c
+++ b/gdk/x11/xsettings-common.c
@@ -149,10 +149,3 @@ xsettings_list_lookup (XSettingsList *list,
     
   return g_hash_table_lookup (list, name);
 }
-
-char
-xsettings_byte_order (void)
-{
-  CARD32 myint = 0x01020304;
-  return (*(char *)&myint == 1) ? MSBFirst : LSBFirst;
-}
diff --git a/gdk/x11/xsettings-common.h b/gdk/x11/xsettings-common.h
index 2773226..ac14495 100644
--- a/gdk/x11/xsettings-common.h
+++ b/gdk/x11/xsettings-common.h
@@ -32,7 +32,6 @@ extern "C" {
 
 /* Renames for GDK inclusion */
 
-#define xsettings_byte_order             _gdk_x11_xsettings_byte_order
 #define xsettings_client_destroy         _gdk_x11_xsettings_client_destroy
 #define xsettings_client_get_setting     _gdk_x11_xsettings_client_get_setting
 #define xsettings_client_new             _gdk_x11_xsettings_client_new
@@ -110,8 +109,6 @@ XSettingsResult   xsettings_list_insert (XSettingsList    **list,
 XSettingsSetting *xsettings_list_lookup (XSettingsList     *list,
                                         const char        *name);
 
-char xsettings_byte_order (void);
-
 #define XSETTINGS_PAD(n,m) ((n + m - 1) & (~(m-1)))
 
 #ifdef __cplusplus


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