Code

C++ cleanup on patch.
[inkscape.git] / src / io / uristream.cpp
index e06498d527ddc5d84e8f9bb7072130f6781a4785..05d7f020af8d1e2066d388f795357eb1b4c98d8f 100644 (file)
@@ -13,6 +13,8 @@
 
 #include "uristream.h"
 #include "sys.h"
+#include <string>
+#include <cstring>
 
 #ifdef WIN32
 // For now to get at is_os_wide().
@@ -105,19 +107,19 @@ UriInputStream::UriInputStream(Inkscape::URI &source)
                     throw (StreamException): uri(source)
 {
     //get information from uri
-    char *schemestr = (char *) uri.getScheme();
+    char const *schemestr = uri.getScheme();
     scheme = SCHEME_FILE;
     if (!schemestr || strncmp("file", schemestr, 4)==0)
         scheme = SCHEME_FILE;
     else if (strncmp("data", schemestr, 4)==0)
         scheme = SCHEME_DATA;
     //printf("in schemestr:'%s' scheme:'%d'\n", schemestr, scheme);
-    char *cpath = NULL;
+    gchar *cpath = NULL;
 
     switch (scheme) {
 
         case SCHEME_FILE:
-            cpath     = (char *) uri.toNativeFilename();
+            cpath = uri.toNativeFilename();
             //printf("in cpath:'%s'\n", cpath);
             inf = fopen_utf8name(cpath, FILE_READ);
             //inf = fopen(cpath, "rb");
@@ -317,18 +319,18 @@ UriOutputStream::UriOutputStream(Inkscape::URI &destination)
                                              scheme(SCHEME_FILE)
 {
     //get information from uri
-    char *schemestr = (char *) uri.getScheme();
+    char const *schemestr = uri.getScheme();
     if (!schemestr || strncmp("file", schemestr, 4)==0)
         scheme = SCHEME_FILE;
     else if (strncmp("data", schemestr, 4)==0)
         scheme = SCHEME_DATA;
     //printf("out schemestr:'%s' scheme:'%d'\n", schemestr, scheme);
-    char *cpath = NULL;
+    gchar *cpath = NULL;
 
     switch (scheme) {
 
         case SCHEME_FILE:
-            cpath     = (char *) uri.toNativeFilename();
+            cpath = uri.toNativeFilename();
             //printf("out path:'%s'\n", cpath);
             outf = fopen_utf8name(cpath, FILE_WRITE);
             //outf = fopen(cpath, "wb");
@@ -427,7 +429,10 @@ void UriOutputStream::put(int ch) throw(StreamException)
             if (!outf)
                 return;
             uch = (unsigned char)(ch & 0xff);
-            fputc(uch, outf);
+            if (fputc(uch, outf) == EOF) {
+                Glib::ustring err = "ERROR writing to file ";
+                throw StreamException(err);
+            }
             //fwrite(uch, 1, 1, outf);
         break;