Patch for kmlprint.c

Renaud Duhaut <[email protected]> 18 Jun 2003 14:51:32 +0200
Newsgroups gmane.comp.file-systems.intermezzo.devel
Message-ID <[email protected]>
Hello,
Is there anyone trying to use intermezzo utility
(kmlprint,kmlantireint,...) ??
kmlprint is broken, and nobody (almost) seems to care.
Just in case, the patch enclosed with this mail, will make kmlprint
properly working.
The problem was that "kml_unpack" wants to write the KML.This is a bad
idea when you just want to look at it, and open it read only (mmaped
with PROT_READ).What do you think of copying KML in memory (like this
patch do) ?
--- kmlprint.c.orig     2003-06-18 14:08:21.000000000 +0200
+++ kmlprint.c  2003-06-18 14:46:39.000000000 +0200
@@ -36,7 +36,7 @@

 int main(int argc, char **argv)
 {
-        char *buf, *end, *str, *ptr, *filename;
+        char *buf, *tmpbuf,*end, *str, *ptr, *filename;
         int fd, recno, brief = 0;
        struct stat st;
        struct kml_rec rec;
@@ -75,14 +75,22 @@
                exit(1);
        }

-       buf = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
-       if ( !buf ) {
+       tmpbuf = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+       if ( !tmpbuf ) {
                perror("mmap fails");
                exit(1);
        }

+       /* Copy the KML, because kml_unpack want to write */
+    buf = g_malloc(st.st_size);
+    memcpy(buf, tmpbuf, st.st_size);
+
+       munmap(tmpbuf,st.st_size);
+       close(fd);
+
        ptr = buf;
        end = buf + st.st_size;
+
        while ( ptr < end ) {
                int err;
                if (recno == -1)




-- 
Renaud Duhaut <[email protected]>



-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php