]> granicus.if.org Git - imagemagick/blobdiff - magick/nt-base.c
(no commit message)
[imagemagick] / magick / nt-base.c
index b21a0d7e89d911e8029bfcd346094fdd7e0f46fb..166fc6f04b94b1be35a3d641bd4ed3b12cab9eab 100644 (file)
@@ -17,7 +17,7 @@
 %                                December 1996                                %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2011 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.  You may  %
@@ -39,7 +39,7 @@
   Include declarations.
 */
 #include "magick/studio.h"
-#if defined(__WINDOWS__)
+#if defined(MAGICKCORE_WINDOWS_SUPPORT)
 #include "magick/client.h"
 #include "magick/log.h"
 #include "magick/magick.h"
@@ -73,16 +73,16 @@ static char
   *lt_slsearchpath = (char *) NULL;
 #endif
 
-static GhostscriptVectors
-  ghostscript_vectors;
+static GhostInfo
+  ghost_info;
 
 static void
-  *ghostscript_handle = (void *) NULL;
+  *ghost_handle = (void *) NULL;
 \f
 /*
   External declarations.
 */
-#if !defined(__WINDOWS__)
+#if !defined(MAGICKCORE_WINDOWS_SUPPORT)
 extern "C" BOOL WINAPI
   DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
 #endif
@@ -236,6 +236,73 @@ MagickExport int Exit(int status)
   return(0);
 }
 \f
+#if !defined(__MINGW32__)
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   g e t t i m e o f d a y                                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  The gettimeofday() method get the time of day.
+%
+%  The format of the gettimeofday method is:
+%
+%      int gettimeofday(struct timeval *time_value,struct timezone *time_zone)
+%
+%  A description of each parameter follows:
+%
+%    o time_value: the time value.
+%
+%    o time_zone: the time zone.
+%
+*/
+MagickExport int gettimeofday (struct timeval *time_value,
+  struct timezone *time_zone)
+{
+#define EpochFiletime  MagickLLConstant(116444736000000000)
+
+  static int
+    is_tz_set;
+
+  if (time_value != (struct timeval *) NULL)
+    {
+      FILETIME
+        file_time;
+
+      __int64
+        time;
+
+      LARGE_INTEGER
+        date_time;
+
+      GetSystemTimeAsFileTime(&file_time);
+      date_time.LowPart=file_time.dwLowDateTime;
+      date_time.HighPart=file_time.dwHighDateTime;
+      time=date_time.QuadPart;
+      time-=EpochFiletime;
+      time/=10;
+      time_value->tv_sec=(ssize_t) (time / 1000000);
+      time_value->tv_usec=(ssize_t) (time % 1000000);
+    }
+  if (time_zone != (struct timezone *) NULL)
+    {
+      if (is_tz_set == 0)
+        {
+          _tzset();
+          is_tz_set++;
+        }
+      time_zone->tz_minuteswest=_timezone/60;
+      time_zone->tz_dsttime=_daylight;
+    }
+  return(0);
+}
+#endif
+\f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -349,7 +416,8 @@ MagickExport int NTCloseLibrary(void *handle)
 
 static BOOL ControlHandler(DWORD type)
 {
-  AsynchronousDestroyMagickResources();
+  (void) type;
+  AsynchronousResourceComponentTerminus();
   return(FALSE);
 }
 
@@ -411,12 +479,12 @@ MagickExport double NTElapsedTime(void)
 %
 %  The format of the NTErrorHandler method is:
 %
-%      void NTErrorHandler(const ExceptionType error,const char *reason,
+%      void NTErrorHandler(const ExceptionType severity,const char *reason,
 %        const char *description)
 %
 %  A description of each parameter follows:
 %
-%    o error: Specifies the numeric error category.
+%    o severity: Specifies the numeric error category.
 %
 %    o reason: Specifies the reason to display before terminating the
 %      program.
@@ -424,13 +492,14 @@ MagickExport double NTElapsedTime(void)
 %    o description: Specifies any description to the reason.
 %
 */
-MagickExport void NTErrorHandler(const ExceptionType error,const char *reason,
-  const char *description)
+MagickExport void NTErrorHandler(const ExceptionType severity,
+  const char *reason,const char *description)
 {
   char
     buffer[3*MaxTextExtent],
     *message;
 
+  (void) severity;
   if (reason == (char *) NULL)
     {
       MagickCoreTerminus();
@@ -533,6 +602,9 @@ MagickExport MagickBooleanType NTGatherRandomData(const size_t length,
   status=CryptReleaseContext(handle,0);
   if (status == 0)
     return(MagickFalse);
+#else
+  (void) random;
+  (void) length;
 #endif
   return(MagickTrue);
 }
@@ -714,7 +786,7 @@ MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
   HMODULE
     handle;
 
-  long
+  ssize_t
     length;
 
   *path='\0';
@@ -738,8 +810,8 @@ MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  NTGhostscriptDLL() returns the path to the most recent Ghostscript DLL.  The
-%  method returns TRUE on success otherwise FALSE.
+%  NTGhostscriptDLL() returns the path to the most recent Ghostscript version
+%  DLL.  The method returns TRUE on success otherwise FALSE.
 %
 %  The format of the NTGhostscriptDLL method is:
 %
@@ -771,15 +843,15 @@ static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
     status;
 
   /*
-    Get a registry value: Key = root\\key, named value = name.
-   */
+    Get a registry value: key = root\\key, named value = name.
+  */
   if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
     return(1);  /* no match */
   p=(BYTE *) value;
   type=REG_SZ;
   extent=(*length);
   if (p == (BYTE *) NULL)
-    p=(&byte);  /* won't return ERROR_MORE_DATA if value is NULL */
+    p=(&byte);  /* ERROR_MORE_DATA only if value is NULL */
   status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
   RegCloseKey(hkey);
   if (status == ERROR_SUCCESS)
@@ -790,12 +862,12 @@ static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
   if (status == ERROR_MORE_DATA)
     {
       *length=extent;
-      return(-1);  /* buffer wasn't large enough */
+      return(-1);  /* buffer not large enough */
     }
   return(1);  /* not found */
 }
 
-static int NTGhostscriptFind(const char **product_family,int *major_version,
+static int NTLocateGhostscript(const char **product_family,int *major_version,
   int *minor_version)
 {
   int
@@ -820,7 +892,7 @@ static int NTGhostscriptFind(const char **product_family,int *major_version,
   *product_family=NULL;
   *major_version=5;
   *minor_version=49; /* min version of Ghostscript is 5.50 */
-  for (i=0; i < (sizeof(products)/sizeof(products[0])); i++)
+  for (i=0; i < (ssize_t) (sizeof(products)/sizeof(products[0])); i++)
   {
     char
       key[MaxTextExtent];
@@ -829,9 +901,16 @@ static int NTGhostscriptFind(const char **product_family,int *major_version,
       hkey,
       root;
 
+    REGSAM
+      mode;
+
     (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
     root=HKEY_LOCAL_MACHINE;
-    if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) == ERROR_SUCCESS)
+    mode=KEY_READ;
+#if defined(KEY_WOW64_32KEY)
+    mode|=KEY_WOW64_32KEY;
+#endif
+    if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
       {
         DWORD
           extent;
@@ -859,12 +938,13 @@ static int NTGhostscriptFind(const char **product_family,int *major_version,
               *product_family=products[i];
               *major_version=major;
               *minor_version=minor;
-              status=MagickTrue;
+              status=TRUE;
             }
-          }
        }
-    }
-  if (status == MagickFalse)
+       (void) RegCloseKey(hkey);
+     }
+  }
+  if (status == FALSE)
     {
       *major_version=0;
       *minor_version=0;
@@ -885,7 +965,7 @@ static int NTGhostscriptGetString(const char *name,char *value,
     extent;
 
   static const char
-    *product_family = NULL;
+    *product_family = (const char *) NULL;
 
   static int
     major_version=0,
@@ -908,16 +988,16 @@ static int NTGhostscriptGetString(const char *name,char *value,
   /*
     Get a string from the installed Ghostscript.
   */
-  value[0]='\0';
+  *value='\0';
   if (product_family == NULL)
-    (void) NTGhostscriptFind(&product_family,&major_version,&minor_version);
+    (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
   if (product_family == NULL)
     return(FALSE);
   (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
     product_family,major_version,minor_version);
-  for (i=0; i < sizeof(hkeys)/sizeof(hkeys[0]); i++)
+  for (i=0; i < (ssize_t) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
   {
-    extent=length;
+    extent=(int) length;
     if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
       {
         (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
@@ -932,13 +1012,14 @@ static int NTGhostscriptGetString(const char *name,char *value,
 
 MagickExport int NTGhostscriptDLL(char *path,int length)
 {
-  char
-    dll_path[MaxTextExtent];
+  static char
+    dll[MaxTextExtent] = { "" };
 
   *path='\0';
-  if (NTGhostscriptGetString("GS_DLL",dll_path,sizeof(dll_path)) == 0)
+  if ((*dll == '\0') &&
+      (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
     return(FALSE);
-  (void) CopyMagickString(path,dll_path,length);
+  (void) CopyMagickString(path,dll,length);
   return(TRUE);
 }
 \f
@@ -953,21 +1034,21 @@ MagickExport int NTGhostscriptDLL(char *path,int length)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  NTGhostscriptDLLVectors() returns a GhostscriptVectors structure that
-%  contain function vectors to invoke Ghostscript DLL functions. A null
-%  pointer is returned if there is an error when loading the DLL or
-%  retrieving the function vectors.
+%  NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
+%  function vectors to invoke Ghostscript DLL functions. A null pointer is
+%  returned if there is an error when loading the DLL or retrieving the
+%  function vectors.
 %
 %  The format of the NTGhostscriptDLLVectors method is:
 %
-%      const GhostscriptVectors *NTGhostscriptDLLVectors(void)
+%      const GhostInfo *NTGhostscriptDLLVectors(void)
 %
 */
-MagickExport const GhostscriptVectors *NTGhostscriptDLLVectors(void)
+MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
 {
   if (NTGhostscriptLoadDLL() == FALSE)
-    return((GhostscriptVectors *) NULL);
-  return(&ghostscript_vectors);
+    return((GhostInfo *) NULL);
+  return(&ghost_info);
 }
 \f
 /*
@@ -998,27 +1079,24 @@ MagickExport const GhostscriptVectors *NTGhostscriptDLLVectors(void)
 */
 MagickExport int NTGhostscriptEXE(char *path,int length)
 {
-  char
+  register char
     *p;
 
   static char
-    executable[MaxTextExtent] = { "" };
+    program[MaxTextExtent] = { "" };
 
-  if (*executable != '\0')
-    {
-      (void) CopyMagickString(path,executable,length);
-      return(TRUE);
-    }
   (void) CopyMagickString(path,"gswin32c.exe",length);
-  if (NTGhostscriptGetString("GS_DLL",executable,sizeof(executable)) == FALSE)
+  if ((*program == '\0') &&
+      (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
     return(FALSE);
-  p=strrchr(executable, '\\');
-  if (p == (char *) NULL)
-    return(FALSE);
-  p++;
-  *p='\0';
-  (void) CopyMagickString(p,path,sizeof(executable)-strlen(executable));
-  (void) CopyMagickString(path,executable,length);
+  p=strrchr(program,'\\');
+  if (p != (char *) NULL)
+    {
+      p++;
+      *p='\0';
+      (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
+    }
+  (void) CopyMagickString(path,program,length);
   return(TRUE);
 }
 \f
@@ -1092,37 +1170,33 @@ MagickExport int NTGhostscriptFonts(char *path,int length)
 %
 %      int NTGhostscriptLoadDLL(void)
 %
-%%
 */
 MagickExport int NTGhostscriptLoadDLL(void)
 {
   char
     path[MaxTextExtent];
 
-  if (ghostscript_handle != (void *) NULL)
+  if (ghost_handle != (void *) NULL)
     return(TRUE);
   if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
     return(FALSE);
-  ghostscript_handle=lt_dlopen(path);
-  if (ghostscript_handle == (void *) NULL)
+  ghost_handle=lt_dlopen(path);
+  if (ghost_handle == (void *) NULL)
     return(FALSE);
-  (void) ResetMagickMemory((void *) &ghostscript_vectors,0,
-    sizeof(GhostscriptVectors));
-  ghostscript_vectors.exit=(int (MagickDLLCall *)(gs_main_instance*))
-    lt_dlsym(ghostscript_handle,"gsapi_exit");
-  ghostscript_vectors.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,
-    int,char **)) (lt_dlsym(ghostscript_handle,"gsapi_init_with_args"));
-  ghostscript_vectors.new_instance=(int (MagickDLLCall *)(gs_main_instance **,
-    void *)) (lt_dlsym(ghostscript_handle,"gsapi_new_instance"));
-  ghostscript_vectors.run_string=(int (MagickDLLCall *)(gs_main_instance *,
-    const char *,int,int *)) (lt_dlsym(ghostscript_handle,"gsapi_run_string"));
-  ghostscript_vectors.delete_instance=(void (MagickDLLCall *) (gs_main_instance
-    *)) (lt_dlsym(ghostscript_handle,"gsapi_delete_instance"));
-  if ((ghostscript_vectors.exit == NULL) ||
-      (ghostscript_vectors.init_with_args == NULL) ||
-      (ghostscript_vectors.new_instance == NULL) ||
-      (ghostscript_vectors.run_string == NULL) ||
-      (ghostscript_vectors.delete_instance == NULL))
+  (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
+  ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
+    lt_dlsym(ghost_handle,"gsapi_exit");
+  ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
+    char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
+  ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
+    lt_dlsym(ghost_handle,"gsapi_new_instance"));
+  ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
+    int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
+  ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
+    lt_dlsym(ghost_handle,"gsapi_delete_instance"));
+  if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
+      (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
+      (ghost_info.delete_instance == NULL))
     return(FALSE);
   return(TRUE);
 }
@@ -1151,12 +1225,11 @@ MagickExport int NTGhostscriptUnLoadDLL(void)
   int
     status;
 
-  if (ghostscript_handle == (void *) NULL)
+  if (ghost_handle == (void *) NULL)
     return(FALSE);
-  status=lt_dlclose(ghostscript_handle);
-  ghostscript_handle=(void *) NULL;
-  (void) ResetMagickMemory((void *) &ghostscript_vectors,0,
-    sizeof(GhostscriptVectors));
+  status=lt_dlclose(ghost_handle);
+  ghost_handle=(void *) NULL;
+  (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
   return(status);
 }
 \f
@@ -1220,6 +1293,7 @@ MagickExport void *NTMapMemory(char *address,size_t length,int protection,
   void
     *map;
 
+  (void) address;
   access_mode=0;
   file_handle=INVALID_HANDLE_VALUE;
   low_length=(DWORD) (length & 0xFFFFFFFFUL);
@@ -1703,7 +1777,7 @@ MagickExport unsigned char *NTResourceToBlob(const char *id)
 %
 %  The format of the NTSeekDirectory method is:
 %
-%      void NTSeekDirectory(DIR *entry,long position)
+%      void NTSeekDirectory(DIR *entry,ssize_t position)
 %
 %  A description of each parameter follows:
 %
@@ -1713,8 +1787,9 @@ MagickExport unsigned char *NTResourceToBlob(const char *id)
 %      stream.
 %
 */
-MagickExport void NTSeekDirectory(DIR *entry,long position)
+MagickExport void NTSeekDirectory(DIR *entry,ssize_t position)
 {
+  (void) position;
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(entry != (DIR *) NULL);
 }
@@ -1784,6 +1859,7 @@ MagickExport int NTSetSearchPath(const char *path)
 */
 MagickExport int NTSyncMemory(void *address,size_t length,int flags)
 {
+  (void) flags;
   if (FlushViewOfFile(address,length) == MagickFalse)
     return(-1);
   return(0);
@@ -1805,7 +1881,7 @@ MagickExport int NTSyncMemory(void *address,size_t length,int flags)
 %
 %  The format of the NTSystemCommand method is:
 %
-%      int NTSystemCommand(const char *command)
+%      int NTSystemCommand(MagickFalse,const char *command)
 %
 %  A description of each parameter follows:
 %
@@ -1881,14 +1957,14 @@ MagickExport int NTSystemCommand(const char *command)
 %
 %  The format of the exit method is:
 %
-%      long NTSystemConfiguration(int name)
+%      ssize_t NTSystemConfiguration(int name)
 %
 %  A description of each parameter follows:
 %
 %    o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
 %
 */
-MagickExport long NTSystemConfiguration(int name)
+MagickExport ssize_t NTSystemConfiguration(int name)
 {
   switch (name)
   {
@@ -1925,12 +2001,12 @@ MagickExport long NTSystemConfiguration(int name)
             status;
 
           GlobalMemoryStatus(&status);
-          return((long) status.dwTotalPhys/system_info.dwPageSize);
+          return((ssize_t) status.dwTotalPhys/system_info.dwPageSize);
         }
       status.dwLength=sizeof(status);
       if (module(&status) == 0)
         return(0L);
-      return((long) status.ullTotalPhys/system_info.dwPageSize);
+      return((ssize_t) status.ullTotalPhys/system_info.dwPageSize);
     }
     case _SC_OPEN_MAX:
       return(2048);
@@ -1956,14 +2032,14 @@ MagickExport long NTSystemConfiguration(int name)
 %
 %  The format of the NTTellDirectory method is:
 %
-%      long NTTellDirectory(DIR *entry)
+%      ssize_t NTTellDirectory(DIR *entry)
 %
 %  A description of each parameter follows:
 %
 %    o entry: Specifies a pointer to a DIR structure.
 %
 */
-MagickExport long NTTellDirectory(DIR *entry)
+MagickExport ssize_t NTTellDirectory(DIR *entry)
 {
   assert(entry != (DIR *) NULL);
   return(0);
@@ -2042,6 +2118,7 @@ MagickExport int NTTruncateFile(int file,off_t length)
 */
 MagickExport int NTUnmapMemory(void *map,size_t length)
 {
+  (void) length;
   if (UnmapViewOfFile(map) == 0)
     return(-1);
   return(0);
@@ -2122,12 +2199,12 @@ MagickExport double NTUserTime(void)
 %
 %  The format of the NTWarningHandler method is:
 %
-%      void NTWarningHandler(const ExceptionType warning,const char *reason,
+%      void NTWarningHandler(const ExceptionType severity,const char *reason,
 %        const char *description)
 %
 %  A description of each parameter follows:
 %
-%    o warning: Specifies the numeric warning category.
+%    o severity: Specifies the numeric warning category.
 %
 %    o reason: Specifies the reason to display before terminating the
 %      program.
@@ -2135,12 +2212,13 @@ MagickExport double NTUserTime(void)
 %    o description: Specifies any description to the reason.
 %
 */
-MagickExport void NTWarningHandler(const ExceptionType warning,
+MagickExport void NTWarningHandler(const ExceptionType severity,
   const char *reason,const char *description)
 {
   char
     buffer[2*MaxTextExtent];
 
+  (void) severity;
   if (reason == (char *) NULL)
     return;
   if (description == (char *) NULL)