Re: read/write as binary
Yasuhiro MATSUMOTO <[email protected]> Fri, 28 Feb 2014 09:42:21 +0900
| Newsgroups | gmane.comp.ipod.gtkpod |
|---|---|
| Message-ID | <CAJc+XFMZ=0MPusok-dQ96RddWPVKyyqPttmdUBspxofid3fAgg@mail.gmail.com> |
--===============8414548340192557841==
Content-Type: multipart/alternative; boundary=001a1134f2befabeb604f36cb5b0
--001a1134f2befabeb604f36cb5b0
Content-Type: text/plain; charset=UTF-8
[snip]
> [from URL above:]
> > --- a/src/itdb_device.c
> > +++ b/src/itdb_device.c
> > @@ -1047,7 +1047,7 @@ gboolean itdb_device_read_sysinfo (Itdb_Device
*device)
> > gchar *ptr;
> > gint len = strlen (buf);
> > /* suppress newline at end of line */
> > - if ((len>0) && (buf[len-1]==0x0a))
> > + if ((len>0) && (buf[len-1]==0x0a || buf[len-1]==0x0d))
>
> I don't know what this data is for, but (going with the comment)
> shouldn't you strip newlines and carriage returns? So something like
> (untested):
>
> while(len>0 && (buf[len-1]==0x0a || buf[len-1]==0x0d))
> {
> buf[len-1]=0;
> --len;
> }
>
> And, again speaking from ignorance: it's not clear why the fopen() on
> line 1041 of this file doesn't get the "rb" treatment like the other
> fopen() calls.
Yes, you are right. This should be triming carriage return.
And this part doesn't need to be modified. So patch become below.
diff --git a/src/itdb_artwork.c b/src/itdb_artwork.c
index c595d70..14dc960 100644
--- a/src/itdb_artwork.c
+++ b/src/itdb_artwork.c
@@ -653,7 +653,7 @@ get_pixel_data (Itdb_Device *device,
Itdb_Thumb_Ipod_Item *thumb)
goto error;
}
- f = fopen (filename, "r");
+ f = fopen (filename, "rb");
if (f == NULL) {
g_print ("Failed to open %s: %s\n",
filename, strerror (errno));
@@ -1108,7 +1108,7 @@ gboolean itdb_device_write_sysinfo (Itdb_Device
*device, GError **error)
if (devicedir)
{
gchar *sysfile = g_build_filename (devicedir, "SysInfo", NULL);
- FILE *sysinfo = fopen (sysfile, "w");
+ FILE *sysinfo = fopen (sysfile, "wb");
if (sysinfo)
{
if (device->sysinfo)
@@ -1538,7 +1538,7 @@ static guint endianess_check_path (const gchar *path,
const gchar *hdr)
if (path)
{
- int fd = open (path, O_RDONLY);
+ int fd = open (path, O_RDONLY | O_BINARY);
if (fd != -1)
{
gchar buf[4];
diff --git a/src/itdb_tzinfo.c b/src/itdb_tzinfo.c
index 3c29947..a34eb36 100644
--- a/src/itdb_tzinfo.c
+++ b/src/itdb_tzinfo.c
@@ -98,7 +98,7 @@ static gboolean itdb_device_read_raw_timezone (const char
*prefs_path,
return FALSE;
}
- f = fopen (prefs_path, "r");
+ f = fopen (prefs_path, "rb");
if (f == NULL) {
return FALSE;
}
diff --git a/src/ithumb-writer.c b/src/ithumb-writer.c
index 6b47aa6..a1e8dae 100644
--- a/src/ithumb-writer.c
+++ b/src/ithumb-writer.c
@@ -1262,7 +1262,7 @@ static gboolean ithumb_rearrange_thumbnail_file
(gpointer _key,
goto out;
}
- fd = open (filename, O_RDWR, 0);
+ fd = open (filename, O_RDWR | O_BINARY, 0);
if (fd == -1)
{
*result = FALSE;
--
- Yasuhiro Matsumoto
--001a1134f2befabeb604f36cb5b0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div><div><div>[snip]</div><div>> [from URL above:=
]</div><div>> > --- a/src/itdb_device.c</div><div>> > +++ b/src=
/itdb_device.c</div><div>> > @@ -1047,7 +1047,7 @@ gboolean itdb_devi=
ce_read_sysinfo (Itdb_Device *device)</div>
<div>> > gchar *ptr;</div><div>> > gint len =3D strlen (buf);</=
div><div>> > /* suppress newline at end of line */</div><div>> >=
; - if ((len>0) && (buf[len-1]=3D=3D0x0a))</div><div>> > +=
if ((len>0) && (buf[len-1]=3D=3D0x0a || buf[len-1]=3D=3D0x0d))<=
/div>
<div>>=C2=A0</div><div>> I don't know what this data is for, but =
(going with the comment)</div><div>> shouldn't you strip newlines an=
d carriage returns? =C2=A0So something like</div><div>> (untested):</div=
><div>
>=C2=A0</div><div>> =C2=A0 while(len>0 && (buf[len-1]=3D=
=3D0x0a || buf[len-1]=3D=3D0x0d))</div><div>> =C2=A0 =C2=A0 {</div><div>=
> =C2=A0 =C2=A0 =C2=A0 buf[len-1]=3D0;</div><div>> =C2=A0 =C2=A0 =C2=
=A0 --len;</div><div>> =C2=A0 =C2=A0 }=C2=A0</div><div>></div><div>&g=
t; And, again speaking from ignorance: it's not clear why the fopen() o=
n</div>
<div>> line 1041 of this file doesn't get the "rb" treatme=
nt like the other</div><div>> fopen() calls.</div><div><br></div><div>Ye=
s, you are right. This should be triming carriage return.</div><div>And thi=
s part doesn't need to be modified. So patch become below.</div>
<div><br></div><div>diff --git a/src/itdb_artwork.c b/src/itdb_artwork.c</d=
iv><div>index c595d70..14dc960 100644</div><div>--- a/src/itdb_artwork.c</d=
iv><div>+++ b/src/itdb_artwork.c</div><div>@@ -653,7 +653,7 @@ get_pixel_da=
ta (Itdb_Device *device, Itdb_Thumb_Ipod_Item *thumb)</div>
<div>=C2=A0<span class=3D"" style=3D"white-space:pre"> </span> =C2=A0 =C2=
=A0goto error;</div><div>=C2=A0<span class=3D"" style=3D"white-space:pre"> =
</span>}</div><div>=C2=A0</div><div>-<span class=3D"" style=3D"white-space:=
pre"> </span>f =3D fopen (filename, "r");</div>
<div>+<span class=3D"" style=3D"white-space:pre"> </span>f =3D fopen (filen=
ame, "rb");</div><div>=C2=A0<span class=3D"" style=3D"white-space=
:pre"> </span>if (f =3D=3D NULL) {</div><div>=C2=A0<span class=3D"" style=
=3D"white-space:pre"> </span>g_print ("Failed to open %s: %s\n",=
</div>
<div>=C2=A0<span class=3D"" style=3D"white-space:pre"> </span> filename, =
strerror (errno));</div><div>@@ -1108,7 +1108,7 @@ gboolean itdb_device_wri=
te_sysinfo (Itdb_Device *device, GError **error)</div><div>=C2=A0 =C2=A0 =
=C2=A0if (devicedir)</div>
<div>=C2=A0 =C2=A0 =C2=A0{</div><div>=C2=A0<span class=3D"" style=3D"white-=
space:pre"> </span>gchar *sysfile =3D g_build_filename (devicedir, "Sy=
sInfo", NULL);</div><div>-<span class=3D"" style=3D"white-space:pre"> =
</span>FILE *sysinfo =3D fopen (sysfile, "w");</div>
<div>+<span class=3D"" style=3D"white-space:pre"> </span>FILE *sysinfo =3D =
fopen (sysfile, "wb");</div><div>=C2=A0<span class=3D"" style=3D"=
white-space:pre"> </span>if (sysinfo)</div><div>=C2=A0<span class=3D"" styl=
e=3D"white-space:pre"> </span>{</div>
<div>=C2=A0<span class=3D"" style=3D"white-space:pre"> </span> =C2=A0 =C2=
=A0if (device->sysinfo)</div><div>@@ -1538,7 +1538,7 @@ static guint end=
ianess_check_path (const gchar *path, const gchar *hdr)</div><div>=C2=A0</d=
iv><div>=C2=A0 =C2=A0 =C2=A0if (path)</div>
<div>=C2=A0 =C2=A0 =C2=A0{</div><div>-<span class=3D"" style=3D"white-space=
:pre"> </span>int fd =3D open (path, O_RDONLY);</div><div>+<span class=3D""=
style=3D"white-space:pre"> </span>int fd =3D open (path, O_RDONLY | O_BINA=
RY);</div><div>=C2=A0<span class=3D"" style=3D"white-space:pre"> </span>if =
(fd !=3D -1)</div>
<div>=C2=A0<span class=3D"" style=3D"white-space:pre"> </span>{</div><div>=
=C2=A0<span class=3D"" style=3D"white-space:pre"> </span> =C2=A0 =C2=A0gcha=
r buf[4];</div><div>diff --git a/src/itdb_tzinfo.c b/src/itdb_tzinfo.c</div=
><div>index 3c29947..a34eb36 100644</div>
<div>--- a/src/itdb_tzinfo.c</div><div>+++ b/src/itdb_tzinfo.c</div><div>@@=
-98,7 +98,7 @@ static gboolean itdb_device_read_raw_timezone (const char *=
prefs_path,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return FALSE;</div>=
<div>=C2=A0 =C2=A0 =C2=A0}</div><div>
=C2=A0</div><div>- =C2=A0 =C2=A0f =3D fopen (prefs_path, "r");</d=
iv><div>+ =C2=A0 =C2=A0f =3D fopen (prefs_path, "rb");</div><div>=
=C2=A0 =C2=A0 =C2=A0if (f =3D=3D NULL) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0return FALSE;</div><div>=C2=A0 =C2=A0 =C2=A0}</div><div>diff --gi=
t a/src/ithumb-writer.c b/src/ithumb-writer.c</div>
<div>index 6b47aa6..a1e8dae 100644</div><div>--- a/src/ithumb-writer.c</div=
><div>+++ b/src/ithumb-writer.c</div><div>@@ -1262,7 +1262,7 @@ static gboo=
lean ithumb_rearrange_thumbnail_file (gpointer _key,</div><div>=C2=A0<span =
class=3D"" style=3D"white-space:pre"> </span>goto out;</div>
<div>=C2=A0 =C2=A0 =C2=A0}</div><div>=C2=A0</div><div>- =C2=A0 =C2=A0fd =3D=
open (filename, O_RDWR, 0);</div><div>+ =C2=A0 =C2=A0fd =3D open (filename=
, O_RDWR | O_BINARY, 0);</div><div>=C2=A0 =C2=A0 =C2=A0if (fd =3D=3D -1)</d=
iv><div>=C2=A0 =C2=A0 =C2=A0{</div><div>=C2=A0<span class=3D"" style=3D"whi=
te-space:pre"> </span>*result =3D FALSE;</div>
<div><br></div><div><br></div><div>--=C2=A0</div><div>- Yasuhiro Matsumoto<=
/div></div></div></div><div><br></div></div>
--001a1134f2befabeb604f36cb5b0--
--===============8414548340192557841==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
--===============8414548340192557841==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Gtkpod-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-devel
--===============8414548340192557841==--