summaryrefslogtreecommitdiff
path: root/magick/utility-private.h
blob: 66ee934c56f95bffd1ba65d050fd39890e835bf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
  Copyright (C) 2003 - 2020 GraphicsMagick Group
  Copyright (C) 2002 ImageMagick Studio
  Copyright 1991-1999 E. I. du Pont de Nemours and Company

  This program is covered by multiple licenses, which are described in
  Copyright.txt. You should have received a copy of Copyright.txt with this
  package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.

  GraphicsMagick Utility Methods.
*/

/*
  Force argument into range accepted by <ctype.h> functions.
*/
#define CTYPE_ARG(value) ((int) ((unsigned char) (value)))

#if !defined(HAVE_STRLCAT)
#  define strlcat(dst,src,size) MagickStrlCat(dst,src,size)
#endif

#if !defined(HAVE_STRLCPY)
#  define strlcpy(dst,src,size) MagickStrlCpy(dst,src,size)
#endif

extern double MagickFmin(const double x, const double y) MAGICK_FUNC_CONST;
extern double MagickFmax(const double x, const double y) MAGICK_FUNC_CONST;

extern MagickExport MagickPassFail MagickAtoFChk(const char *str, double *value);
extern MagickExport MagickPassFail MagickAtoIChk(const char *str, int *value);
extern MagickExport MagickPassFail MagickAtoUIChk(const char *str, unsigned int *value);
extern MagickExport MagickPassFail MagickAtoLChk(const char *str, long *value);
extern MagickExport MagickPassFail MagickAtoULChk(const char *str, unsigned long *value);
extern MagickExport long MagickDoubleToLong(const double dval/*, ExceptionInfo *exception*/) MAGICK_FUNC_CONST;

extern MagickExport size_t
  MagickStripSpacesFromString(char *string),
  MagickStripString(char *string);

/*
  Compute a value which is the next kilobyte power of 2 larger than
  the requested value or 256 whichever is larger.

  The objective is to round up the size quickly (and in repeatable
  steps) in order to reduce the number of memory copies due to realloc
  for strings which grow rapidly, while producing a reasonable size
  for smaller strings.
*/
#define MagickRoundUpStringLength(size)                                 \
  do {                                                                  \
    size_t                                                              \
      _rounded,                                                         \
      _target;                                                          \
                                                                        \
    _target=(Max(size,256));                                            \
    for (_rounded=256U; _rounded < _target; _rounded *= 2);             \
    size=_rounded;                                                      \
} while(0)

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 2
 * fill-column: 78
 * End:
 */