if (*filename == '\0')
file=AcquireUniqueFileResource(filename);
else
- file=open(filename,O_RDWR | O_CREAT | O_EXCL | O_BINARY,S_MODE);
+ file=open_utf8(filename,O_RDWR | O_CREAT | O_EXCL | O_BINARY,S_MODE);
if (file == -1)
{
ThrowFileException(exception,BlobError,"UnableToWriteBlob",filename);
*length=0;
file=fileno(stdin);
if (LocaleCompare(filename,"-") != 0)
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
if (file == -1)
{
ThrowFileException(exception,BlobError,"UnableToOpenFile",filename);
assert(image->signature == MagickSignature);
assert(filename != (const char *) NULL);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
if (file == -1)
{
ThrowFileException(&image->exception,BlobError,"UnableToOpenBlob",
if (LocaleCompare(filename,"-") == 0)
file=fileno(stdout);
else
- file=open(filename,O_RDWR | O_CREAT | O_EXCL | O_BINARY,S_MODE);
+ file=open_utf8(filename,O_RDWR | O_CREAT | O_EXCL | O_BINARY,S_MODE);
if (file == -1)
{
ThrowFileException(exception,BlobError,"UnableToWriteBlob",filename);
/*
Inject into image stream.
*/
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
if (file == -1)
{
(void) RelinquishUniqueFileResource(filename);
#endif
*mode=(*type);
mode[1]='\0';
- image->blob->file=(FILE *) popen(filename+1,mode);
+ image->blob->file=(FILE *) popen_utf8(filename+1,mode);
if (image->blob->file == (FILE *) NULL)
{
ThrowFileException(exception,BlobError,"UnableToOpenBlob",filename);
#if defined(S_ISFIFO)
if ((status == MagickTrue) && S_ISFIFO(image->blob->properties.st_mode))
{
- image->blob->file=(FILE *) OpenMagickStream(filename,type);
+ image->blob->file=(FILE *) fopen_utf8(filename,type);
if (image->blob->file == (FILE *) NULL)
{
ThrowFileException(exception,BlobError,"UnableToOpenBlob",filename);
else
if (*type == 'r')
{
- image->blob->file=(FILE *) OpenMagickStream(filename,type);
+ image->blob->file=(FILE *) fopen_utf8(filename,type);
if (image->blob->file != (FILE *) NULL)
{
size_t
else
#endif
{
- image->blob->file=(FILE *) OpenMagickStream(filename,type);
+ image->blob->file=(FILE *) fopen_utf8(filename,type);
if (image->blob->file != (FILE *) NULL)
{
image->blob->type=FileStream;
{
case ReadMode:
{
- file=open(cache_info->cache_filename,O_RDONLY | O_BINARY);
+ file=open_utf8(cache_info->cache_filename,O_RDONLY | O_BINARY,0);
break;
}
case WriteMode:
{
- file=open(cache_info->cache_filename,O_WRONLY | O_CREAT | O_BINARY |
- O_EXCL,S_MODE);
+ file=open_utf8(cache_info->cache_filename,O_WRONLY | O_CREAT |
+ O_BINARY | O_EXCL,S_MODE);
if (file == -1)
- file=open(cache_info->cache_filename,O_WRONLY | O_BINARY,S_MODE);
+ file=open_utf8(cache_info->cache_filename,O_WRONLY | O_BINARY,S_MODE);
break;
}
case IOMode:
default:
{
- file=open(cache_info->cache_filename,O_RDWR | O_CREAT | O_BINARY |
+ file=open_utf8(cache_info->cache_filename,O_RDWR | O_CREAT | O_BINARY |
O_EXCL,S_MODE);
if (file == -1)
- file=open(cache_info->cache_filename,O_RDWR | O_BINARY,S_MODE);
+ file=open_utf8(cache_info->cache_filename,O_RDWR | O_BINARY,S_MODE);
break;
}
}
/*
Copy source file to destination.
*/
- destination_file=open(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
+ destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
if (destination_file == -1)
return(MagickFalse);
- source_file=open(source,O_RDONLY | O_BINARY);
+ source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
if (source_file == -1)
{
(void) close(destination_file);
XFileBrowserWidget(display,windows,"Delete",filename);
if (*filename == '\0')
break;
- status=remove(filename) != 0 ? MagickTrue : MagickFalse;
+ status=remove_utf8(filename) != 0 ? MagickTrue : MagickFalse;
if (status != MagickFalse)
XNoticeWidget(display,windows,"Unable to delete image file:",filename);
break;
status=XConfirmWidget(display,windows,"Really delete tile",filename);
if (status <= 0)
break;
- status=remove(filename) != 0 ? MagickTrue : MagickFalse;
+ status=remove_utf8(filename) != 0 ? MagickTrue : MagickFalse;
if (status != MagickFalse)
{
XNoticeWidget(display,windows,"Unable to delete image file:",
return(MagickFalse);
}
log_info->append=IsPathAccessible(filename);
- log_info->file=OpenMagickStream(filename,"ab");
+ log_info->file=fopen_utf8(filename,"ab");
filename=(char *) RelinquishMagickMemory(filename);
if (log_info->file == (FILE *) NULL)
{
#include "MagickCore/thread_.h"
#include "MagickCore/thread-private.h"
#include "MagickCore/utility.h"
+#include "MagickCore/utility-private.h"
/*
Define declarations.
*/
#endif
if (file != -1)
(void) close(file);
- (void) remove(filename);
+ (void) remove_utf8(filename);
SetStringInfoLength(chaos,strlen(filename));
SetStringInfoDatum(chaos,(unsigned char *) filename);
ConcatenateStringInfo(entropy,chaos);
filename=AcquireString("/dev/urandom");
device=StringToStringInfo(filename);
device=DestroyStringInfo(device);
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
filename=DestroyString(filename);
if (file != -1)
{
filename=AcquireString("/dev/random");
device=StringToStringInfo(filename);
device=DestroyStringInfo(device);
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
filename=DestroyString(filename);
if (file == -1)
{
filename=AcquireString("/dev/srandom");
device=StringToStringInfo(filename);
device=DestroyStringInfo(device);
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
}
if (file != -1)
{
path=(const char *) GetNextKeyInSplayTree(temporary_resources);
while (path != (const char *) NULL)
{
- (void) remove(path);
+ (void) remove_utf8(path);
path=(const char *) GetNextKeyInSplayTree(temporary_resources);
}
}
static void *DestroyTemporaryResources(void *temporary_resource)
{
- (void) remove((char *) temporary_resource);
+ (void) remove_utf8((char *) temporary_resource);
temporary_resource=DestroyString((char *) temporary_resource);
return((void *) NULL);
}
*p++=portable_filename[c];
}
key=DestroyStringInfo(key);
- file=open(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW,S_MODE);
+ file=open_utf8(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW,S_MODE);
if ((file >= 0) || (errno != EEXIST))
break;
}
}
(void) CopyMagickString(cache_path,path,MaxTextExtent);
AppendImageFormat("cache",cache_path);
- (void) remove(cache_path);
- return(remove(path) == 0 ? MagickTrue : MagickFalse);
+ (void) remove_utf8(cache_path);
+ return(remove_utf8(path) == 0 ? MagickTrue : MagickFalse);
}
\f
/*
#include "MagickCore/resource_.h"
#include "MagickCore/signature-private.h"
#include "MagickCore/string_.h"
+#include "MagickCore/utility-private.h"
\f
/*
Static declarations.
*map;
assert(filename != (const char *) NULL);
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
if (file == -1)
return((StringInfo *) NULL);
offset=(MagickOffsetType) lseek(file,0,SEEK_END);
#endif
}
+static inline FILE *popen_utf8(const char *command,const char *type)
+{
+#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
+ return(fopen(command,type));
+#else
+ FILE
+ *file;
+
+ int
+ status;
+
+ WCHAR
+ *type_wide,
+ *command_wide;
+
+ command_wide=(WCHAR *) NULL;
+ count=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
+ command_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*command_wide));
+ if (command_wide == (WCHAR *) NULL)
+ return(-1);
+ 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);
+ }
+ 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);
+ return(file);
+#endif
+}
+
static inline int remove_utf8(const char *path)
{
#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
destination_file=AcquireUniqueFileResource(destination);
if (destination_file == -1)
return(MagickFalse);
- source_file=open(source,O_RDONLY | O_BINARY);
+ source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
if (source_file == -1)
{
(void) close(destination_file);
% o attributes: the path attributes are returned here.
%
*/
-
-#if defined(MAGICKCORE_HAVE__WFOPEN)
-static size_t UTF8ToUTF16(const unsigned char *utf8,wchar_t *utf16)
-{
- register const unsigned char
- *p;
-
- if (utf16 != (wchar_t *) NULL)
- {
- register wchar_t
- *q;
-
- wchar_t
- c;
-
- /*
- Convert UTF-8 to UTF-16.
- */
- q=utf16;
- for (p=utf8; *p != '\0'; p++)
- {
- if ((*p & 0x80) == 0)
- *q=(*p);
- else
- if ((*p & 0xE0) == 0xC0)
- {
- c=(*p);
- *q=(c & 0x1F) << 6;
- p++;
- if ((*p & 0xC0) != 0x80)
- return(0);
- *q|=(*p & 0x3F);
- }
- else
- if ((*p & 0xF0) == 0xE0)
- {
- c=(*p);
- *q=c << 12;
- p++;
- if ((*p & 0xC0) != 0x80)
- return(0);
- c=(*p);
- *q|=(c & 0x3F) << 6;
- p++;
- if ((*p & 0xC0) != 0x80)
- return(0);
- *q|=(*p & 0x3F);
- }
- else
- return(0);
- q++;
- }
- *q++='\0';
- return(q-utf16);
- }
- /*
- Compute UTF-16 string length.
- */
- for (p=utf8; *p != '\0'; p++)
- {
- if ((*p & 0x80) == 0)
- ;
- else
- if ((*p & 0xE0) == 0xC0)
- {
- p++;
- if ((*p & 0xC0) != 0x80)
- return(0);
- }
- else
- if ((*p & 0xF0) == 0xE0)
- {
- p++;
- if ((*p & 0xC0) != 0x80)
- return(0);
- p++;
- if ((*p & 0xC0) != 0x80)
- return(0);
- }
- else
- return(0);
- }
- return(p-utf8);
-}
-
-static wchar_t *ConvertUTF8ToUTF16(const unsigned char *source)
-{
- size_t
- length;
-
- wchar_t
- *utf16;
-
- length=UTF8ToUTF16(source,(wchar_t *) NULL);
- if (length == 0)
- {
- register ssize_t
- i;
-
- /*
- Not UTF-8, just copy.
- */
- length=strlen((const char *) source);
- utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16));
- if (utf16 == (wchar_t *) NULL)
- return((wchar_t *) NULL);
- for (i=0; i <= (ssize_t) length; i++)
- utf16[i]=source[i];
- return(utf16);
- }
- utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16));
- if (utf16 == (wchar_t *) NULL)
- return((wchar_t *) NULL);
- length=UTF8ToUTF16(source,utf16);
- return(utf16);
-}
-#endif
-
MagickExport MagickBooleanType GetPathAttributes(const char *path,
void *attributes)
{
errno=EINVAL;
return(MagickFalse);
}
-#if !defined(MAGICKCORE_HAVE__WSTAT)
- status=stat(path,(struct stat *) attributes) == 0 ? MagickTrue : MagickFalse;
-#else
- {
- wchar_t
- *unicode_path;
-
- unicode_path=ConvertUTF8ToUTF16((const unsigned char *) path);
- if (unicode_path == (wchar_t *) NULL)
- return(MagickFalse);
- status=wstat(unicode_path,(struct stat *) attributes) == 0 ? MagickTrue :
- MagickFalse;
- unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path);
- }
-#endif
+ status=stat_utf8(path,(struct stat *) attributes) == 0 ? MagickTrue :
+ MagickFalse;
return(status);
}
\f
return(status);
if (S_ISREG(attributes.st_mode) == 0)
return(MagickFalse);
- if (access(path,F_OK) != 0)
+ if (access_utf8(path,F_OK) != 0)
return(MagickFalse);
return(MagickTrue);
}
% %
% %
% %
-% O p e n M a g i c k S t r e a m %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% OpenMagickStream() opens the file at the specified path and return the
-% associated stream.
-%
-% The path of the OpenMagickStream method is:
-%
-% FILE *OpenMagickStream(const char *path,const char *mode)
-%
-% A description of each parameter follows.
-%
-% o path: the file path.
-%
-% o mode: the file mode.
-%
-*/
-MagickExport FILE *OpenMagickStream(const char *path,const char *mode)
-{
- FILE
- *file;
-
- if ((path == (const char *) NULL) || (mode == (const char *) NULL))
- {
- errno=EINVAL;
- return((FILE *) NULL);
- }
- file=(FILE *) NULL;
-#if defined(MAGICKCORE_HAVE__WFOPEN)
- {
- wchar_t
- *unicode_mode,
- *unicode_path;
-
- unicode_path=ConvertUTF8ToUTF16((const unsigned char *) path);
- if (unicode_path == (wchar_t *) NULL)
- return((FILE *) NULL);
- unicode_mode=ConvertUTF8ToUTF16((const unsigned char *) mode);
- if (unicode_mode == (wchar_t *) NULL)
- {
- unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path);
- return((FILE *) NULL);
- }
- file=_wfopen(unicode_path,unicode_mode);
- unicode_mode=(wchar_t *) RelinquishMagickMemory(unicode_mode);
- unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path);
- }
-#endif
- if (file == (FILE *) NULL)
- file=fopen(path,mode);
- return(file);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
% S y s t e m C o m m a n d %
% %
% %
extern MagickExport char
*Base64Encode(const unsigned char *,const size_t,size_t *);
-extern MagickExport FILE
- *OpenMagickStream(const char *,const char *);
-
extern MagickExport int
SystemCommand(const MagickBooleanType,const MagickBooleanType,const char *,
ExceptionInfo *);
#include "MagickWand/MagickWand.h"
#include "MagickWand/mogrify-private.h"
#include "MagickCore/string-private.h"
+#include "MagickCore/utility-private.h"
/*
Define declarations.
*/
/*
Open output file.
*/
- output=OpenMagickStream(argv[argc-1],"wb");
+ output=fopen_utf8(argv[argc-1],"wb");
if (output == (FILE *) NULL)
{
ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
}
for (i=2; i < (ssize_t) (argc-1); i++)
{
- input=OpenMagickStream(argv[i],"rb");
+ input=fopen_utf8(argv[i],"rb");
if (input == (FILE *) NULL)
ThrowFileException(exception,FileOpenError,"UnableToOpenFile",argv[i]);
for (c=fgetc(input); c != EOF; c=fgetc(input))
(void) fputc((char) c,output);
(void) fclose(input);
- (void) remove(argv[i]);
+ (void) remove_utf8(argv[i]);
}
(void) fclose(output);
return(MagickTrue);
#include "MagickCore/monitor-private.h"
#include "MagickCore/thread-private.h"
#include "MagickCore/string-private.h"
+#include "MagickCore/utility-private.h"
\f
/*
Constant declaration.
{
if (IsPathAccessible(path) == MagickFalse)
return(MagickFalse);
- if (access(path,W_OK) != 0)
+ if (access_utf8(path,W_OK) != 0)
return(MagickFalse);
return(MagickTrue);
}
image_info->synchronize=MagickTrue;
status&=WriteImages(image_info,image,image->filename,exception);
if ((status == MagickFalse) && (*backup_filename != '\0'))
- (void) remove(backup_filename);
+ (void) remove_utf8(backup_filename);
RemoveAllImageStack();
continue;
}
#include "MagickCore/string_.h"
#include "MagickCore/module.h"
#include "MagickCore/utility.h"
+#include "MagickCore/utility-private.h"
\f
typedef struct
{
(void) CopyMagickString(clone_info->filename+i,".PAL",(size_t)
(MaxTextExtent-i));
- if((clone_info->file=OpenMagickStream(clone_info->filename,"rb"))==NULL)
+ if((clone_info->file=fopen_utf8(clone_info->filename,"rb"))==NULL)
{
(void) CopyMagickString(clone_info->filename+i,".pal",(size_t)
(MaxTextExtent-i));
- if((clone_info->file=OpenMagickStream(clone_info->filename,"rb"))==NULL)
+ if((clone_info->file=fopen_utf8(clone_info->filename,"rb"))==NULL)
{
clone_info->filename[i]='\0';
- if((clone_info->file=OpenMagickStream(clone_info->filename,"rb"))==NULL)
+ if((clone_info->file=fopen_utf8(clone_info->filename,"rb"))==NULL)
{
clone_info=DestroyImageInfo(clone_info);
clone_info=NULL;
#include "MagickCore/string_.h"
#include "MagickCore/module.h"
#include "MagickCore/transform.h"
+#include "MagickCore/utility-private.h"
#if defined(MAGICKCORE_ZLIB_DELEGATE)
#include "zlib.h"
#endif
{
fclose(clone_info->file);
clone_info->file = NULL;
- (void) unlink(clone_info->filename);
+ (void) remove_utf8(clone_info->filename);
}
CacheBlock = AcquireQuantumMemory((size_t)((Size<16384)?Size:16384),sizeof(unsigned char *));
fclose(clone_info->file);
clone_info->file = NULL;
UnlinkFile:
- (void) unlink(clone_info->filename);
+ (void) remove_utf8(clone_info->filename);
return NULL;
}
{
fclose(clone_info->file);
clone_info->file = NULL;
- (void) unlink(clone_info->filename);
+ (void) remove_utf8(clone_info->filename);
}
}
}
{
fclose(clone_info->file);
clone_info->file = NULL;
- (void) unlink(clone_info->filename);
+ (void) remove_utf8(clone_info->filename);
}
DestroyImageInfo(clone_info);
clone_info = NULL;
#include "MagickCore/module.h"
#include "MagickCore/transform.h"
#include "MagickCore/utility.h"
+#include "MagickCore/utility-private.h"
\f
/*
Forward declarations.
/*
Copy source file to destination.
*/
- destination_file=open(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
+ destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
if (destination_file == -1)
return(MagickFalse);
- source_file=open(source,O_RDONLY | O_BINARY);
+ source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
if (source_file == -1)
{
(void) close(destination_file);
#include "MagickCore/module.h"
#include "MagickCore/transform.h"
#include "MagickCore/utility.h"
+#include "MagickCore/utility-private.h"
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
file=(FILE *) NULL;
unique_file=AcquireUniqueFileResource(read_info->filename);
if (unique_file != -1)
- file=OpenMagickStream(read_info->filename,"wb");
+ file=fopen_utf8(read_info->filename,"wb");
if ((unique_file == -1) || (file == (FILE *) NULL))
{
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
char
*message;
- (void) remove(read_info->filename);
+ (void) remove_utf8(read_info->filename);
read_info=DestroyImageInfo(read_info);
message=GetExceptionMessage(errno);
(void) ThrowMagickException(&image->exception,GetMagickModule(),
#include "MagickCore/module.h"
#include "MagickCore/transform.h"
#include "MagickCore/utility.h"
+#include "MagickCore/utility-private.h"
\f
typedef struct
{
/* Obtain temporary file */
AcquireUniqueFilename(postscript_file);
- ps_file=OpenMagickStream(postscript_file,"wb");
+ ps_file=fopen_utf8(postscript_file,"wb");
if (ps_file == (FILE *) NULL)
goto FINISH;