[Banshee-List] libipoddevice patches



Hi,

Here are two patches to fix 2 issues in libipoddevice:
* endianess.diff should hopefully make it possible to parse the
DeviceInfo file on big endian machines
* list.diff fixes a warning from gcc about the return value of
g_list_remove being ignored. I removed some seemingly useless code at
the same time (g_list_length(l) is 0 if and only if l is NULL if I read
glib code properly)

(both patches are only compile tested, so there might be some obvious
mistakes in them)

Christophe
Index: src/ipod-device-event-listener.c
===================================================================
RCS file: /cvs/gnome/libipoddevice/src/ipod-device-event-listener.c,v
retrieving revision 1.8
diff -u -r1.8 ipod-device-event-listener.c
--- src/ipod-device-event-listener.c	8 Nov 2005 22:04:53 -0000	1.8
+++ src/ipod-device-event-listener.c	15 Apr 2006 23:03:42 -0000
@@ -199,11 +199,7 @@
     
     g_list_free(listener->priv->ipodUdis);
     
-    g_list_remove(instances, listener);
-    if(g_list_length(instances) == 0) {
-        g_list_free(instances);
-        instances = NULL;
-    }
+    instances = g_list_remove(instances, listener);
 }
 
 static void 
Index: src/ipod-device.c
===================================================================
RCS file: /cvs/gnome/libipoddevice/src/ipod-device.c,v
retrieving revision 1.60
diff -u -r1.60 ipod-device.c
--- src/ipod-device.c	13 Apr 2006 23:38:13 -0000	1.60
+++ src/ipod-device.c	15 Apr 2006 23:03:23 -0000
@@ -824,20 +824,25 @@
     gshort length;
     gunichar2 *utf16;
     gchar *utf8;
-    
+    unsigned int i;
+
     if(fread(&length, 1, sizeof(gshort), fd) <= 0) {
         return NULL;
     } else if(length <= 0) {
         return NULL;
     }
     
+    length = GINT16_FROM_LE (length);
+
     utf16 = (gunichar2 *)g_malloc(length * sizeof(gunichar2));
     if(utf16 == NULL) {
         return NULL;
     } else if(fread(utf16, sizeof(gunichar2), length, fd) <= 0) {
         return NULL;
     }
-    
+    for (i = 0; i < length; i++) {
+	utf16[i] = GINT16_FROM_LE (utf16[i]);
+    }
     utf8 = g_utf16_to_utf8(utf16, length, NULL, NULL, NULL);
     
     g_free(utf16);
@@ -850,18 +855,25 @@
 ipod_device_write_device_info_string(gchar *str, FILE *fd)
 {
     gunichar2 *unistr;
-    gshort length;
+    glong length;
+    gshort length_le;
+    unsigned int i;
 
     if(str == NULL) {
         return;
     }
     
-    length = strlen(str);
-    unistr = g_utf8_to_utf16(str, length, NULL, NULL, NULL);
-    
+    unistr = g_utf8_to_utf16(str, -1, NULL, &length, NULL);
+    if (unistr == NULL) {
+	return;
+    }
+    for (i = 0; i < length; i++) {
+	unistr[i] = GINT16_TO_LE (unistr[i]);
+    }
+    length *= sizeof (gunichar2);
     length = length > 0x198 ? 0x198 : length;
-
-    if(fwrite(&length, 2, 1, fd) <= 0 
+    length_le = GINT16_TO_LE (length);
+    if(fwrite(&length_le, 2, 1, fd) <= 0 
         || fwrite(unistr, 2, length, fd) <= 0) {
         g_warning("Could not write to DeviceInfo file");
     }

Attachment: signature.asc
Description: Ceci est une partie de message =?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=



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