Skip to content

Commit

Permalink
format time to live
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Oct 14, 2023
1 parent f11ed36 commit b6d966a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
65 changes: 60 additions & 5 deletions magick/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,12 +955,10 @@ static ssize_t FormatPixelSize(const MagickSizeType size,
length;

ssize_t
count,
i,
j;

ssize_t
count;

static const char
*bi_units[] =
{
Expand Down Expand Up @@ -996,6 +994,64 @@ static ssize_t FormatPixelSize(const MagickSizeType size,
return(count);
}

static void FormatTimeToLive(const MagickSizeType ttl,char *timeString)
{
MagickSizeType
days,
hours,
minutes,
months,
seconds,
weeks,
years;

years=ttl/31536000;
seconds=ttl % 31536000;
if (seconds == 0)
{
(void) FormatLocaleString(timeString,MagickPathExtent,"%lld years",years);
return;
}
months=seconds/2592000;
seconds=seconds % 2592000;
if (seconds == 0)
{
(void) FormatLocaleString(timeString,MagickPathExtent,"%lld months",
months);
return;
}
weeks=seconds/604800;
seconds=seconds % 604800;
if (seconds == 0)
{
(void) FormatLocaleString(timeString,MagickPathExtent,"%lld weeks",weeks);
return;
}
days=seconds/86400;
seconds=seconds % 86400;
if (seconds == 0)
{
(void) FormatLocaleString(timeString,MagickPathExtent,"%lld days",days);
return;
}
hours=seconds/3600;
seconds=seconds % 3600;
if (seconds == 0)
{
(void) FormatLocaleString(timeString,MagickPathExtent,"%lld hours",hours);
return;
}
minutes=seconds/60;
seconds=seconds % 60;
if (seconds == 0)
{
(void) FormatLocaleString(timeString,MagickPathExtent,"%lld minutes",
minutes);
return;
}
(void) FormatLocaleString(timeString,MagickPathExtent,"%lld seconds",seconds);
}

MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file,
ExceptionInfo *magick_unused(exception))
{
Expand Down Expand Up @@ -1030,8 +1086,7 @@ MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file,
(void) FormatMagickSize(resource_info.disk_limit,MagickTrue,disk_limit);
(void) CopyMagickString(time_limit,"unlimited",MaxTextExtent);
if (resource_info.time_limit != MagickResourceInfinity)
(void) FormatLocaleString(time_limit,MaxTextExtent,"%.20g",(double)
((MagickOffsetType) resource_info.time_limit));
FormatTimeToLive(resource_info.time_limit,time_limit);
(void) FormatLocaleFile(file,"Resource limits:\n");
(void) FormatLocaleFile(file," Width: %s\n",width_limit);
(void) FormatLocaleFile(file," Height: %s\n",height_limit);
Expand Down
2 changes: 1 addition & 1 deletion magick/timer-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static inline time_t ParseMagickTimeToLive(const char *time_to_live)
if (LocaleNCompare(q,"week",4) == 0)
ttl*=604800;
if (LocaleNCompare(q,"month",5) == 0)
ttl*=2628000;
ttl*=2592000;
if (LocaleNCompare(q,"year",4) == 0)
ttl*=31536000;
}
Expand Down
2 changes: 2 additions & 0 deletions wand/mogrify.c
Original file line number Diff line number Diff line change
Expand Up @@ -7180,6 +7180,8 @@ WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
limit=MagickResourceInfinity;
if (LocaleCompare("unlimited",argv[i+2]) != 0)
limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
if (type == TimeResource)
limit=(MagickSizeType) ParseMagickTimeToLive(argv[i+2]);
(void) SetMagickResourceLimit(type,limit);
break;
}
Expand Down

0 comments on commit b6d966a

Please sign in to comment.