]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/utility-private.h
(no commit message)
[imagemagick] / MagickCore / utility-private.h
index 5f5886fe0134596aed79ad148a8c857ce0eac66d..df0160d838acfca94f8fb846e974a5949ed93cd5 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
+  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
   dedicated to making software imaging solutions freely available.
 
   You may not use this file except in compliance with the License.
 extern "C" {
 #endif
 
+#include "MagickCore/memory_.h"
+#include "MagickCore/nt-base.h"
+#include "MagickCore/nt-base-private.h"
+
 extern MagickPrivate char
   **GetPathComponents(const char *,size_t *),
   **ListFiles(const char *,const char *,size_t *);
@@ -60,7 +64,7 @@ static inline int access_utf8(const char *path,int mode)
      return(-1);
    count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
    status=_waccess(path_wide,mode);
-   path_wide=RelinquishMagickMemory(path_wide);
+   path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
    return(status);
 #endif
 }
@@ -74,7 +78,7 @@ static inline FILE *fopen_utf8(const char *path,const char *mode)
      *file;
 
    int
-     status;
+     count;
 
    WCHAR
      *mode_wide,
@@ -84,24 +88,29 @@ static inline FILE *fopen_utf8(const char *path,const char *mode)
    count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
    path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
    if (path_wide == (WCHAR *) NULL)
-     return(-1);
+     return((FILE *) NULL);
    count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
    count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0);
    mode_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*mode_wide));
    if (mode_wide == (WCHAR *) NULL)
      {
-       path_wide=RelinquishMagickMemory(path_wide);
-       return(-1);
+       path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
+       return((FILE *) NULL);
      }
    count=MultiByteToWideChar(CP_UTF8,0,mode,-1,mode_wide,count);
-   file=_wfopen(path_wide,mode_width);
-   mode_wide=RelinquishMagickMemory(mode_wide);
-   path_wide=RelinquishMagickMemory(path_wide);
+   file=_wfopen(path_wide,mode_wide);
+   mode_wide=(WCHAR *) RelinquishMagickMemory(mode_wide);
+   path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
    return(file);
 #endif
 }
 
-static inline int open_utf8(const char *path,int flags,int mode)
+#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
+typedef int
+  mode_t;
+#endif
+
+static inline int open_utf8(const char *path,int flags,mode_t mode)
 {
 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
   return(open(path,flags,mode));
@@ -120,7 +129,7 @@ static inline int open_utf8(const char *path,int flags,int mode)
      return(-1);
    count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
    status=_wopen(path_wide,flags,mode);
-   path_wide=RelinquishMagickMemory(path_wide);
+   path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
    return(status);
 #endif
 }
@@ -128,13 +137,13 @@ static inline int open_utf8(const char *path,int flags,int mode)
 static inline FILE *popen_utf8(const char *command,const char *type)
 {
 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
-  return(fopen(command,type));
+  return(popen(command,type));
 #else
    FILE
      *file;
 
    int
-     status;
+     count;
 
    WCHAR
      *type_wide,
@@ -144,19 +153,19 @@ static inline FILE *popen_utf8(const char *command,const char *type)
    count=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
    command_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*command_wide));
    if (command_wide == (WCHAR *) NULL)
-     return(-1);
+     return((FILE *) NULL);
    count=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,count);
    count=MultiByteToWideChar(CP_UTF8,0,type,-1,NULL,0);
    type_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*type_wide));
    if (type_wide == (WCHAR *) NULL)
      {
-       command_wide=RelinquishMagickMemory(command_wide);
-       return(-1);
+       command_wide=(WCHAR *) RelinquishMagickMemory(command_wide);
+       return((FILE *) NULL);
      }
    count=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,count);
-   file=_wpopen(path_wide,type_width);
-   type_wide=RelinquishMagickMemory(type_wide);
-   path_wide=RelinquishMagickMemory(path_wide);
+   file=_wpopen(command_wide,type_wide);
+   type_wide=(WCHAR *) RelinquishMagickMemory(type_wide);
+   command_wide=(WCHAR *) RelinquishMagickMemory(command_wide);
    return(file);
 #endif
 }
@@ -180,7 +189,42 @@ static inline int remove_utf8(const char *path)
      return(-1);
    count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
    status=_wremove(path_wide);
-   path_wide=RelinquishMagickMemory(path_wide);
+   path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
+   return(status);
+#endif
+}
+
+static inline int rename_utf8(const char *source,const char *destination)
+{
+#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
+  return(rename(source,destination));
+#else
+   int
+     count,
+     status;
+
+   WCHAR
+     *destination_wide,
+     *source_wide;
+
+   source_wide=(WCHAR *) NULL;
+   count=MultiByteToWideChar(CP_UTF8,0,source,-1,NULL,0);
+   source_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*source_wide));
+   if (source_wide == (WCHAR *) NULL)
+     return(-1);
+   count=MultiByteToWideChar(CP_UTF8,0,source,-1,source_wide,count);
+   count=MultiByteToWideChar(CP_UTF8,0,destination,-1,NULL,0);
+   destination_wide=(WCHAR *) AcquireQuantumMemory(count,
+     sizeof(*destination_wide));
+   if (destination_wide == (WCHAR *) NULL)
+     {
+       source_wide=(WCHAR *) RelinquishMagickMemory(source_wide);
+       return(-1);
+     }
+   count=MultiByteToWideChar(CP_UTF8,0,destination,-1,destination_wide,count);
+   status=_wrename(source_wide,destination_wide);
+   destination_wide=(WCHAR *) RelinquishMagickMemory(destination_wide);
+   source_wide=(WCHAR *) RelinquishMagickMemory(source_wide);
    return(status);
 #endif
 }
@@ -203,8 +247,8 @@ static inline int stat_utf8(const char *path,struct stat *attributes)
    if (path_wide == (WCHAR *) NULL)
      return(-1);
    count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
-   status=_wstat(path_wide,attributes);
-   path_wide=RelinquishMagickMemory(path_wide);
+   status=_wstat64(path_wide,attributes);
+   path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
    return(status);
 #endif
 }