% September 2002 %
% %
% %
-% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2017 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 %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
*/
#include "MagickCore/studio.h"
#include "MagickCore/cache.h"
+#include "MagickCore/cache-private.h"
#include "MagickCore/configure.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
-#include "MagickCore/hashmap.h"
+#include "MagickCore/linked-list.h"
#include "MagickCore/log.h"
#include "MagickCore/image.h"
#include "MagickCore/image-private.h"
#include "MagickCore/utility.h"
#include "MagickCore/utility-private.h"
\f
+/*
+ Define declarations.
+*/
+#define MagickPathTemplate "XXXXXXXXXXXX"
+\f
/*
Typedef declarations.
*/
const MagickSizeType size)
{
char
- resource_current[MaxTextExtent],
- resource_limit[MaxTextExtent],
- resource_request[MaxTextExtent];
+ resource_current[MagickFormatExtent],
+ resource_limit[MagickFormatExtent],
+ resource_request[MagickFormatExtent];
MagickBooleanType
status;
limit;
status=MagickFalse;
- (void) FormatMagickSize(size,MagickFalse,"B",resource_request);
+ (void) FormatMagickSize(size,MagickFalse,"B",MagickFormatExtent,
+ resource_request);
if (resource_semaphore == (SemaphoreInfo *) NULL)
ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
status=(resource_info.area_limit == MagickResourceInfinity) ||
(size < limit) ? MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse,
- "B",resource_current);
- (void) FormatMagickSize(resource_info.area_limit,MagickFalse,
- "B",resource_limit);
+ "P",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"P",
+ MagickFormatExtent,resource_limit);
break;
}
case MemoryResource:
((MagickSizeType) resource_info.memory < limit) ? MagickTrue :
MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.memory,MagickTrue,
- "B",resource_current);
- (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,
- "B",resource_limit);
+ "B",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B",
+ MagickFormatExtent,resource_limit);
break;
}
case MapResource:
status=(resource_info.map_limit == MagickResourceInfinity) ||
((MagickSizeType) resource_info.map < limit) ? MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue,
- "B",resource_current);
- (void) FormatMagickSize(resource_info.map_limit,MagickTrue,
- "B",resource_limit);
+ "B",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B",
+ MagickFormatExtent,resource_limit);
break;
}
case DiskResource:
((MagickSizeType) resource_info.disk < limit) ? MagickTrue :
MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue,
- "B",resource_current);
- (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,
- "B",resource_limit);
+ "B",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B",
+ MagickFormatExtent,resource_limit);
break;
}
case FileResource:
((MagickSizeType) resource_info.file < limit) ?
MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse,
- "B",resource_current);
+ "B",MagickFormatExtent,resource_current);
(void) FormatMagickSize((MagickSizeType) resource_info.file_limit,
- MagickFalse,"B",resource_limit);
+ MagickFalse,"B",MagickFormatExtent,resource_limit);
break;
}
case HeightResource:
status=(resource_info.area_limit == MagickResourceInfinity) ||
(size < limit) ? MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.height,MagickFalse,
- "P",resource_current);
- (void) FormatMagickSize(resource_info.height_limit,MagickFalse,
- "P",resource_limit);
+ "P",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P",
+ MagickFormatExtent,resource_limit);
break;
}
case ThreadResource:
((MagickSizeType) resource_info.thread < limit) ?
MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse,
- "B",resource_current);
+ "B",MagickFormatExtent,resource_current);
(void) FormatMagickSize((MagickSizeType) resource_info.thread_limit,
- MagickFalse,"B",resource_limit);
+ MagickFalse,"B",MagickFormatExtent,resource_limit);
break;
}
case ThrottleResource:
((MagickSizeType) resource_info.throttle < limit) ?
MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.throttle,
- MagickFalse,"B",resource_current);
+ MagickFalse,"B",MagickFormatExtent,resource_current);
(void) FormatMagickSize((MagickSizeType) resource_info.throttle_limit,
- MagickFalse,"B",resource_limit);
+ MagickFalse,"B",MagickFormatExtent,resource_limit);
break;
}
case TimeResource:
((MagickSizeType) resource_info.time < limit) ?
MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse,
- "B",resource_current);
+ "B",MagickFormatExtent,resource_current);
(void) FormatMagickSize((MagickSizeType) resource_info.time_limit,
- MagickFalse,"B",resource_limit);
+ MagickFalse,"B",MagickFormatExtent,resource_limit);
break;
}
case WidthResource:
status=(resource_info.area_limit == MagickResourceInfinity) ||
(size < limit) ? MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse,
- "P",resource_current);
- (void) FormatMagickSize(resource_info.width_limit,MagickFalse,
- "P",resource_limit);
+ "P",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P",
+ MagickFormatExtent,resource_limit);
break;
}
default:
struct stat
attributes;
- (void) FormatLocaleString(path,MaxTextExtent,"magick-%.20gXXXXXXXXXXXX",
- (double) getpid());
+ (void) FormatLocaleString(path,MagickPathExtent,"magick-%.20g"
+ MagickPathTemplate,(double) getpid());
exception=AcquireExceptionInfo();
directory=(char *) GetImageRegistry(StringRegistryType,"temporary-path",
exception);
directory=GetEnvironmentValue("MAGICK_TMPDIR");
if (directory == (char *) NULL)
directory=GetEnvironmentValue("TMPDIR");
-#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__)
+#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__) || defined(__CYGWIN__)
if (directory == (char *) NULL)
directory=GetEnvironmentValue("TMP");
if (directory == (char *) NULL)
#endif
if (directory == (char *) NULL)
return(MagickTrue);
- value=GetPolicyValue("temporary-path");
+ value=GetPolicyValue("resource:temporary-path");
if (value != (char *) NULL)
- (void) CloneString(&directory,value);
- if (strlen(directory) > (MaxTextExtent-25))
+ {
+ (void) CloneString(&directory,value);
+ value=DestroyString(value);
+ }
+ if (strlen(directory) > (MagickPathExtent-25))
{
directory=DestroyString(directory);
return(MagickFalse);
return(MagickFalse);
}
if (directory[strlen(directory)-1] == *DirectorySeparator)
- (void) FormatLocaleString(path,MaxTextExtent,"%smagick-%.20gXXXXXXXXXXXX",
- directory,(double) getpid());
+ (void) FormatLocaleString(path,MagickPathExtent,
+ "%smagick-%.20g" MagickPathTemplate,directory,(double) getpid());
else
- (void) FormatLocaleString(path,MaxTextExtent,
- "%s%smagick-%.20gXXXXXXXXXXXX",directory,DirectorySeparator,
+ (void) FormatLocaleString(path,MagickPathExtent,
+ "%s%smagick-%.20g" MagickPathTemplate,directory,DirectorySeparator,
(double) getpid());
directory=DestroyString(directory);
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
*/
(void) GetPathTemplate(path);
key=GetRandomKey(random_info,6);
- p=path+strlen(path)-12;
+ p=path+strlen(path)-strlen(MagickPathTemplate);
datum=GetStringInfoDatum(key);
for (i=0; i < (ssize_t) GetStringInfoLength(key); i++)
{
file=mkstemp(path);
if (file != -1)
{
+#if defined(MAGICKCORE_HAVE_FCHMOD)
(void) fchmod(file,0600);
+#endif
#if defined(__OS2__)
setmode(file,O_BINARY);
#endif
break;
}
#endif
- key=GetRandomKey(random_info,12);
- p=path+strlen(path)-12;
+ key=GetRandomKey(random_info,strlen(MagickPathTemplate));
+ p=path+strlen(path)-strlen(MagickPathTemplate);
datum=GetStringInfoDatum(key);
for (i=0; i < (ssize_t) GetStringInfoLength(key); i++)
{
ExceptionInfo *magick_unused(exception))
{
char
- area_limit[MaxTextExtent],
- disk_limit[MaxTextExtent],
- height_limit[MaxTextExtent],
- map_limit[MaxTextExtent],
- memory_limit[MaxTextExtent],
- time_limit[MaxTextExtent],
- width_limit[MaxTextExtent];
+ area_limit[MagickFormatExtent],
+ disk_limit[MagickFormatExtent],
+ height_limit[MagickFormatExtent],
+ map_limit[MagickFormatExtent],
+ memory_limit[MagickFormatExtent],
+ time_limit[MagickFormatExtent],
+ width_limit[MagickFormatExtent];
+
+ magick_unreferenced(exception);
if (file == (const FILE *) NULL)
file=stdout;
ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
(void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P",
- width_limit);
+ MagickFormatExtent,width_limit);
(void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P",
- height_limit);
- (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"B",area_limit);
+ MagickFormatExtent,height_limit);
+ (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"P",
+ MagickFormatExtent,area_limit);
(void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B",
- memory_limit);
- (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B",map_limit);
- (void) CopyMagickString(disk_limit,"unlimited",MaxTextExtent);
+ MagickFormatExtent,memory_limit);
+ (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B",
+ MagickFormatExtent,map_limit);
+ (void) CopyMagickString(disk_limit,"unlimited",MagickFormatExtent);
if (resource_info.disk_limit != MagickResourceInfinity)
- (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B",disk_limit);
- (void) CopyMagickString(time_limit,"unlimited",MaxTextExtent);
+ (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B",
+ MagickFormatExtent,disk_limit);
+ (void) CopyMagickString(time_limit,"unlimited",MagickFormatExtent);
if (resource_info.time_limit != MagickResourceInfinity)
- (void) FormatLocaleString(time_limit,MaxTextExtent,"%.20g",(double)
+ (void) FormatLocaleString(time_limit,MagickFormatExtent,"%.20g",(double)
((MagickOffsetType) resource_info.time_limit));
(void) FormatLocaleFile(file,"Resource limits:\n");
(void) FormatLocaleFile(file," Width: %s\n",width_limit);
const MagickSizeType size)
{
char
- resource_current[MaxTextExtent],
- resource_limit[MaxTextExtent],
- resource_request[MaxTextExtent];
+ resource_current[MagickFormatExtent],
+ resource_limit[MagickFormatExtent],
+ resource_request[MagickFormatExtent];
- (void) FormatMagickSize(size,MagickFalse,"B",resource_request);
+ (void) FormatMagickSize(size,MagickFalse,"B",MagickFormatExtent,
+ resource_request);
if (resource_semaphore == (SemaphoreInfo *) NULL)
ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
{
resource_info.width=(MagickOffsetType) size;
(void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse,
- "P",resource_current);
- (void) FormatMagickSize(resource_info.width_limit,MagickFalse,
- "P",resource_limit);
+ "P",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P",
+ MagickFormatExtent,resource_limit);
break;
}
case HeightResource:
{
- resource_info.width=(MagickOffsetType) size;
- (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse,
- "P",resource_current);
- (void) FormatMagickSize(resource_info.width_limit,MagickFalse,
- "P",resource_limit);
+ resource_info.height=(MagickOffsetType) size;
+ (void) FormatMagickSize((MagickSizeType) resource_info.height,MagickFalse,
+ "P",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P",
+ MagickFormatExtent,resource_limit);
break;
}
case AreaResource:
{
resource_info.area=(MagickOffsetType) size;
(void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse,
- "B",resource_current);
- (void) FormatMagickSize(resource_info.area_limit,MagickFalse,
- "B",resource_limit);
+ "B",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"B",
+ MagickFormatExtent,resource_limit);
break;
}
case MemoryResource:
{
resource_info.memory-=size;
(void) FormatMagickSize((MagickSizeType) resource_info.memory,
- MagickTrue,"B",resource_current);
- (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,
- "B",resource_limit);
+ MagickTrue,"B",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B",
+ MagickFormatExtent,resource_limit);
break;
}
case MapResource:
{
resource_info.map-=size;
(void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue,
- "B",resource_current);
- (void) FormatMagickSize(resource_info.map_limit,MagickTrue,
- "B",resource_limit);
+ "B",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B",
+ MagickFormatExtent,resource_limit);
break;
}
case DiskResource:
{
resource_info.disk-=size;
(void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue,
- "B",resource_current);
- (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,
- "B",resource_limit);
+ "B",MagickFormatExtent,resource_current);
+ (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B",
+ MagickFormatExtent,resource_limit);
break;
}
case FileResource:
{
resource_info.file-=size;
(void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse,
- "B",resource_current);
+ "B",MagickFormatExtent,resource_current);
(void) FormatMagickSize((MagickSizeType) resource_info.file_limit,
- MagickFalse,"B",resource_limit);
+ MagickFalse,"B",MagickFormatExtent,resource_limit);
break;
}
case ThreadResource:
{
(void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse,
- "B",resource_current);
+ "B",MagickFormatExtent,resource_current);
(void) FormatMagickSize((MagickSizeType) resource_info.thread_limit,
- MagickFalse,"B",resource_limit);
+ MagickFalse,"B",MagickFormatExtent,resource_limit);
break;
}
case ThrottleResource:
{
(void) FormatMagickSize((MagickSizeType) resource_info.throttle,
- MagickFalse,"B",resource_current);
+ MagickFalse,"B",MagickFormatExtent,resource_current);
(void) FormatMagickSize((MagickSizeType) resource_info.throttle_limit,
- MagickFalse,"B",resource_limit);
+ MagickFalse,"B",MagickFormatExtent,resource_limit);
break;
}
case TimeResource:
{
resource_info.time-=size;
(void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse,
- "B",resource_current);
+ "B",MagickFormatExtent,resource_current);
(void) FormatMagickSize((MagickSizeType) resource_info.time_limit,
- MagickFalse,"B",resource_limit);
+ MagickFalse,"B",MagickFormatExtent,resource_limit);
break;
}
default:
MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path)
{
char
- cache_path[MaxTextExtent];
+ cache_path[MagickPathExtent];
MagickBooleanType
status;
ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
if (temporary_resources != (SplayTreeInfo *) NULL)
- status=DeleteNodeFromSplayTree(temporary_resources, (const void *) path);
+ status=DeleteNodeFromSplayTree(temporary_resources,(const void *) path);
UnlockSemaphoreInfo(resource_semaphore);
- (void) CopyMagickString(cache_path,path,MaxTextExtent);
+ (void) CopyMagickString(cache_path,path,MagickPathExtent);
AppendImageFormat("cache",cache_path);
(void) ShredFile(cache_path);
if (status == MagickFalse)
case WidthResource:
{
resource_info.width_limit=limit;
- value=GetPolicyValue("width");
+ value=GetPolicyValue("resource:width");
if (value != (char *) NULL)
resource_info.width_limit=MagickMin(limit,StringToSizeType(value,
100.0));
case HeightResource:
{
resource_info.height_limit=limit;
- value=GetPolicyValue("height");
+ value=GetPolicyValue("resource:height");
if (value != (char *) NULL)
resource_info.height_limit=MagickMin(limit,StringToSizeType(value,
100.0));
case AreaResource:
{
resource_info.area_limit=limit;
- value=GetPolicyValue("area");
+ value=GetPolicyValue("resource:area");
if (value != (char *) NULL)
resource_info.area_limit=MagickMin(limit,StringToSizeType(value,100.0));
break;
case MemoryResource:
{
resource_info.memory_limit=limit;
- value=GetPolicyValue("memory");
+ value=GetPolicyValue("resource:memory");
if (value != (char *) NULL)
resource_info.memory_limit=MagickMin(limit,StringToSizeType(value,
100.0));
case MapResource:
{
resource_info.map_limit=limit;
- value=GetPolicyValue("map");
+ value=GetPolicyValue("resource:map");
if (value != (char *) NULL)
resource_info.map_limit=MagickMin(limit,StringToSizeType(value,100.0));
break;
case DiskResource:
{
resource_info.disk_limit=limit;
- value=GetPolicyValue("disk");
+ value=GetPolicyValue("resource:disk");
if (value != (char *) NULL)
resource_info.disk_limit=MagickMin(limit,StringToSizeType(value,100.0));
break;
case FileResource:
{
resource_info.file_limit=limit;
- value=GetPolicyValue("file");
+ value=GetPolicyValue("resource:file");
if (value != (char *) NULL)
resource_info.file_limit=MagickMin(limit,StringToSizeType(value,100.0));
break;
case ThreadResource:
{
resource_info.thread_limit=limit;
- value=GetPolicyValue("thread");
+ value=GetPolicyValue("resource:thread");
if (value != (char *) NULL)
resource_info.thread_limit=MagickMin(limit,StringToSizeType(value,
100.0));
if (resource_info.thread_limit > GetOpenMPMaximumThreads())
resource_info.thread_limit=GetOpenMPMaximumThreads();
- else if (resource_info.thread_limit == 0)
- resource_info.thread_limit=1;
+ else
+ if (resource_info.thread_limit == 0)
+ resource_info.thread_limit=1;
break;
}
case ThrottleResource:
{
resource_info.throttle_limit=limit;
- value=GetPolicyValue("throttle");
+ value=GetPolicyValue("resource:throttle");
if (value != (char *) NULL)
- resource_info.throttle_limit=MagickMin(limit,StringToSizeType(value,
+ resource_info.throttle_limit=MagickMax(limit,StringToSizeType(value,
100.0));
- if (resource_info.throttle_limit > GetOpenMPMaximumThreads())
- resource_info.throttle_limit=GetOpenMPMaximumThreads();
break;
}
case TimeResource:
{
resource_info.time_limit=limit;
- value=GetPolicyValue("time");
+ value=GetPolicyValue("resource:time");
if (value != (char *) NULL)
resource_info.time_limit=MagickMin(limit,StringToSizeType(value,100.0));
+ ResetPixelCacheEpoch();
break;
}
default: