Index: catalog-web-exporter.c
===================================================================
--- catalog-web-exporter.c	(revision 1487)
+++ catalog-web-exporter.c	(working copy)
@@ -23,6 +23,8 @@
 #include <config.h>
 #include <string.h>
 #include <stdio.h>
+#include <fcntl.h>
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <time.h>
@@ -1747,20 +1749,26 @@
 	export__copy_to_destination (ce);
 }
 
+#define DEBUG(x) // x
 
 static void
 copy_exif_from_orig_and_reset_orientation (const char *src_filename,
 		     const char *dest_filename)
 {
-	JPEGData     *jdata_src, *jdata_dest;
-	ExifData     *edata_src;
 	char         *local_src_filename = NULL;
 	char         *local_dest_filename = NULL;
 	gboolean      is_local;
 
-	/* Due to shortcomings in libexif, this function may corrupt
-	   the MakerNotes in the exif data. */
 
+	// vars for setting tag in target file
+	guint16       tf = (guint16) 1; // top-left value of EXIF_TAG_ORIENTATION tag
+	int           res;              // result from call gth_minimal_exif_tag_write()
+
+	// vars for file copy
+	int           src, dest;        // file descriptors
+	char          *to, *from;       // pointers for memcpy
+	size_t        size;             // file size
+
 	is_local = is_local_file (dest_filename);
 
 	local_src_filename = obtain_local_file (src_filename);
@@ -1769,37 +1777,58 @@
 	if ((local_src_filename == NULL) || (local_dest_filename == NULL))
 		return;
 
-	jdata_src = jpeg_data_new_from_file (local_src_filename);
-	if (jdata_src == NULL)
+	// Open source file
+	if ((src = open(local_src_filename, O_RDONLY)) == -1){
+		fprintf(stderr, "catalog_web_exporter: Error opening file: %s\n", local_src_filename);
 		return;
+	}
 
-	edata_src = jpeg_data_get_exif_data (jdata_src);
-	if (edata_src == NULL) {
-		jpeg_data_unref (jdata_src);
+	// Open dest file
+	if ((dest = open(local_dest_filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) == -1){
+		fprintf(stderr, "catalog_web_exporter: Error opening file: %s\n", local_dest_filename);
 		return;
 	}
 
-	jdata_dest = jpeg_data_new_from_file (local_dest_filename);
-	if (jdata_dest == NULL)
-		return;
+	// Make room in dest file
+	size = lseek(src, 0, SEEK_END);
+	lseek(dest, size - 1, SEEK_SET);
+	write(dest, (void *) "x", 1);
 
-	/* The exif orientation tag, if present, must be reset to "top-left", 	 
-           because the jpeg was saved from a gthumb-generated pixbuf, and 	 
-           the pixbug image loader always rotates the pixbuf to account for 	 
-           the orientation tag. */
-	update_exif_orientation (edata_src);
+	// Memory map source file
+	if ((from = mmap(0, size, PROT_READ, MAP_SHARED, src, 0)) == (void *) -1){
+		fprintf(stderr, "catalog_web_exporter: Error mapping input file: %s\n", local_src_filename);
+	}
 
-	/* Update the exif data within the jpeg data, in memory. */
-	jpeg_data_set_exif_data (jdata_dest, edata_src);
+	// Memory map dest file
+	if ((to = mmap(0, size, PROT_WRITE, MAP_SHARED, dest, 0)) == (void *) -1){
+		fprintf(stderr, "catalog_web_exporter: Error mapping ouput file: %s\n", local_dest_filename);
+	}
 
-	/* Commit the jpeg data in memory to a file. */
-	jpeg_data_save_file (jdata_dest, local_dest_filename);
+	// Copy the file through the mapped memory
+	memcpy(to, from, size);
 
-	/* Remove the jpeg and exif data in memory. */
-	exif_data_unref (edata_src);
-	jpeg_data_unref (jdata_src);
-	jpeg_data_unref (jdata_dest);
+	// Unmap files
+	munmap(from, size);
+	munmap(to,   size);
 
+	// Make sure data is written to harddrive
+	fsync(dest);
+
+	// Close files
+	close(src);
+	close(dest);
+
+       /* The exif orientation tag, if present, must be reset to "top-left",    
+           because the jpeg was saved from a gthumb-generated pixbuf, and       
+           the pixbug image loader always rotates the pixbuf to account for     
+           the orientation tag. */
+
+	if ((res = gth_minimal_exif_tag_write(local_dest_filename, EXIF_TAG_ORIENTATION, &tf, 2, 0)) != PATCH_EXIF_OK){
+		fprintf(stderr, 
+		  "copy_exif_from_orig_and_reset_orientation called gth_minimal_exif_tag_write: error %d \"%s\" in %s\n", 
+		  res, gth_minimal_exif_tag_write_return_codes[res],local_dest_filename );
+	}
+
         if (!is_local)
 		copy_cache_file_to_remote_uri (local_dest_filename, dest_filename);
 
