## util

util

## Synopsis

    #define             VIPS_PI
    #define             VIPS_RAD                            (R)
    #define             VIPS_DEG                            (A)
    #define             VIPS_MAX                            (A,
                                                             B)
    #define             VIPS_MIN                            (A,
                                                             B)
    #define             VIPS_ABS                            (X)
    #define             VIPS_CLIP                           (A,
                                                             V,
                                                             B)
    #define             VIPS_NUMBER                         (R)
    #define             VIPS_SWAP                           (TYPE,
                                                             A,
                                                             B)
    #define             VIPS_UNROLL                         (N,
                                                             OPER)
    #define             VIPS_RINT                           (R)
    #define             VIPS_CLIP_UCHAR                     (V,
                                                             SEQ)
    #define             VIPS_CLIP_CHAR                      (V,
                                                             SEQ)
    #define             VIPS_CLIP_USHORT                    (V,
                                                             SEQ)
    #define             VIPS_CLIP_SHORT                     (V,
                                                             SEQ)
    #define             VIPS_CLIP_UINT                      (V,
                                                             SEQ)
    #define             VIPS_CLIP_NONE                      (V,
                                                             SEQ)
    #define             VIPS_PATH_MAX
    const char *        vips_enum_string                    (GType enm,
                                                             int value);
    const char *        vips_enum_nick                      (GType enm,
                                                             int value);
    int                 vips_enum_from_nick                 (const char *domain,
                                                             GType type,
                                                             const char *str);
    gboolean            vips_slist_equal                    (GSList *l1,
                                                             GSList *l2);
    void *              vips_slist_map2                     (GSList *list,
                                                             VipsSListMap2Fn fn,
                                                             void *a,
                                                             void *b);
    void *              vips_slist_map2_rev                 (GSList *list,
                                                             VipsSListMap2Fn fn,
                                                             void *a,
                                                             void *b);
    void *              vips_slist_map4                     (GSList *list,
                                                             VipsSListMap4Fn fn,
                                                             void *a,
                                                             void *b,
                                                             void *c,
                                                             void *d);
    void *              vips_slist_fold2                    (GSList *list,
                                                             void *start,
                                                             VipsSListFold2Fn fn,
                                                             void *a,
                                                             void *b);
    GSList *            vips_slist_filter                   (GSList *list,
                                                             VipsSListMap2Fn fn,
                                                             void *a,
                                                             void *b);
    void                vips_slist_free_all                 (GSList *list);
    void *              vips_map_equal                      (void *a,
                                                             void *b);
    void *              vips_hash_table_map                 (GHashTable *hash,
                                                             VipsSListMap2Fn fn,
                                                             void *a,
                                                             void *b);
    char *              vips_strncpy                        (char *dest,
                                                             const char *src,
                                                             int n);
    char *              vips_strrstr                        (const char *haystack,
                                                             const char *needle);
    gboolean            vips_ispostfix                      (const char *a,
                                                             const char *b);
    gboolean            vips_isprefix                       (const char *a,
                                                             const char *b);
    char *              vips_break_token                    (char *str,
                                                             const char *brk);
    int                 vips_vsnprintf                      (char *str,
                                                             size_t size,
                                                             const char *format,
                                                             va_list ap);
    int                 vips_snprintf                       (char *str,
                                                             size_t size,
                                                             const char *format,
                                                             ...);
    void                vips_filename_split                 (const char *path,
                                                             char *name,
                                                             char *mode);
    const char *        vips_skip_dir                       (const char *filename);
    void                vips_filename_suffix                (const char *path,
                                                             char *suffix);
    int                 vips_filename_suffix_match          (const char *path,
                                                             const char *suffixes[]);
    char *              vips_getnextoption                  (char **in);
    char *              vips_getsuboption                   (const char *buf);
    gint64              vips_file_length                    (int fd);
    int                 vips__write                         (int fd,
                                                             const void *buf,
                                                             size_t count);
    FILE *              vips__file_open_read                (const char *filename,
                                                             const char *fallback_dir,
                                                             gboolean text_mode);
    FILE *              vips__file_open_write               (const char *filename,
                                                             gboolean text_mode);
    char *              vips__file_read                     (FILE *fp,
                                                             const char *name,
                                                             unsigned int *length_out);
    char *              vips__file_read_name                (const char *name,
                                                             const char *fallback_dir,
                                                             unsigned int *length_out);
    int                 vips__file_write                    (void *data,
                                                             size_t size,
                                                             size_t nmemb,
                                                             FILE *stream);
    int                 vips__get_bytes                     (const char *filename,
                                                             unsigned char buf[],
                                                             int len);
    GValue *            vips__gvalue_ref_string_new         (const char *text);
    void                vips__gslist_gvalue_free            (GSList *list);
    GSList *            vips__gslist_gvalue_copy            (const GSList *list);
    GSList *            vips__gslist_gvalue_merge           (GSList *a,
                                                             const GSList *b);
    char *              vips__gslist_gvalue_get             (const GSList *list);
    int                 vips__seek                          (int fd,
                                                             gint64 pos);
    int                 vips__ftruncate                     (int fd,
                                                             gint64 pos);
    int                 vips_existsf                        (const char *name,
                                                             ...);
    int                 vips_mkdirf                         (const char *name,
                                                             ...);
    FILE *              vips_popenf                         (const char *fmt,
                                                             const char *mode,
                                                             ...);
    enum                VipsToken;
    const char *        vips__token_get                     (const char *buffer,
                                                             VipsToken *token,
                                                             char *string,
                                                             int size);
    const char *        vips__token_must                    (const char *buffer,
                                                             VipsToken *token,
                                                             char *string,
                                                             int size);
    const char *        vips__token_need                    (const char *buffer,
                                                             VipsToken need_token,
                                                             char *string,
                                                             int size);
    const char *        vips__find_rightmost_brackets       (const char *p);
    int                 vips_ispoweroftwo                   (int p);
    int                 vips_amiMSBfirst                    (void);
    char *              vips__temp_name                     (const char *format);
    void                vips__change_suffix                 (const char *name,
                                                             char *out,
                                                             int mx,
                                                             const char *new_suff,
                                                             const char **olds,
                                                             int nolds);

## Description

## Details

### VIPS_PI

    #define VIPS_PI (3.14159265358979323846)

### VIPS_RAD()

    #define VIPS_RAD( R ) (((R) / 360.0) * 2.0 * VIPS_PI)

### VIPS_DEG()

    #define VIPS_DEG( A ) (((A) / (2.0 * VIPS_PI)) * 360.0)

### VIPS_MAX()

    #define VIPS_MAX( A, B ) ((A) > (B) ? (A) : (B))

### VIPS_MIN()

    #define VIPS_MIN( A, B ) ((A) < (B) ? (A) : (B))

### VIPS_ABS()

    #define VIPS_ABS( X ) (((X) >= 0) ? (X) : -(X))

### VIPS_CLIP()

    #define VIPS_CLIP( A, V, B ) VIPS_MAX( (A), VIPS_MIN( (B), (V) ) )

### VIPS_NUMBER()

    #define VIPS_NUMBER( R ) ((int) (sizeof(R) / sizeof(R[0])))

### VIPS_SWAP()

    #define             VIPS_SWAP( TYPE, A, B )

### VIPS_UNROLL()

    #define             VIPS_UNROLL( N, OPER )

### VIPS_RINT()

    #define VIPS_RINT( R ) ((int) ((R) > 0 ? ((R) + 0.5) : ((R) - 0.5)))

### VIPS_CLIP_UCHAR()

    #define             VIPS_CLIP_UCHAR( V, SEQ )

### VIPS_CLIP_CHAR()

    #define             VIPS_CLIP_CHAR( V, SEQ )

### VIPS_CLIP_USHORT()

    #define             VIPS_CLIP_USHORT( V, SEQ )

### VIPS_CLIP_SHORT()

    #define             VIPS_CLIP_SHORT( V, SEQ )

### VIPS_CLIP_UINT()

    #define             VIPS_CLIP_UINT( V, SEQ )

### VIPS_CLIP_NONE()

    #define VIPS_CLIP_NONE( V, SEQ ) {}

### VIPS_PATH_MAX

    #define VIPS_PATH_MAX (4096)

### vips_enum_string ()

    const char *        vips_enum_string                    (GType enm,
                                                             int value);

### vips_enum_nick ()

    const char *        vips_enum_nick                      (GType enm,
                                                             int value);

### vips_enum_from_nick ()

    int                 vips_enum_from_nick                 (const char *domain,
                                                             GType type,
                                                             const char *str);

### vips_slist_equal ()

    gboolean            vips_slist_equal                    (GSList *l1,
                                                             GSList *l2);

### vips_slist_map2 ()

    void *              vips_slist_map2                     (GSList *list,
                                                             VipsSListMap2Fn fn,
                                                             void *a,
                                                             void *b);

### vips_slist_map2_rev ()

    void *              vips_slist_map2_rev                 (GSList *list,
                                                             VipsSListMap2Fn fn,
                                                             void *a,
                                                             void *b);

### vips_slist_map4 ()

    void *              vips_slist_map4                     (GSList *list,
                                                             VipsSListMap4Fn fn,
                                                             void *a,
                                                             void *b,
                                                             void *c,
                                                             void *d);

### vips_slist_fold2 ()

    void *              vips_slist_fold2                    (GSList *list,
                                                             void *start,
                                                             VipsSListFold2Fn fn,
                                                             void *a,
                                                             void *b);

### vips_slist_filter ()

    GSList *            vips_slist_filter                   (GSList *list,
                                                             VipsSListMap2Fn fn,
                                                             void *a,
                                                             void *b);

### vips_slist_free_all ()

    void                vips_slist_free_all                 (GSList *list);

### vips_map_equal ()

    void *              vips_map_equal                      (void *a,
                                                             void *b);

### vips_hash_table_map ()

    void *              vips_hash_table_map                 (GHashTable *hash,
                                                             VipsSListMap2Fn fn,
                                                             void *a,
                                                             void *b);

### vips_strncpy ()

    char *              vips_strncpy                        (char *dest,
                                                             const char *src,
                                                             int n);

### vips_strrstr ()

    char *              vips_strrstr                        (const char *haystack,
                                                             const char *needle);

### vips_ispostfix ()

    gboolean            vips_ispostfix                      (const char *a,
                                                             const char *b);

### vips_isprefix ()

    gboolean            vips_isprefix                       (const char *a,
                                                             const char *b);

### vips_break_token ()

    char *              vips_break_token                    (char *str,
                                                             const char *brk);

### vips_vsnprintf ()

    int                 vips_vsnprintf                      (char *str,
                                                             size_t size,
                                                             const char *format,
                                                             va_list ap);

### vips_snprintf ()

    int                 vips_snprintf                       (char *str,
                                                             size_t size,
                                                             const char *format,
                                                             ...);

### vips_filename_split ()

    void                vips_filename_split                 (const char *path,
                                                             char *name,
                                                             char *mode);

### vips_skip_dir ()

    const char *        vips_skip_dir                       (const char *filename);

### vips_filename_suffix ()

    void                vips_filename_suffix                (const char *path,
                                                             char *suffix);

### vips_filename_suffix_match ()

    int                 vips_filename_suffix_match          (const char *path,
                                                             const char *suffixes[]);

### vips_getnextoption ()

    char *              vips_getnextoption                  (char **in);

### vips_getsuboption ()

    char *              vips_getsuboption                   (const char *buf);

### vips_file_length ()

    gint64              vips_file_length                    (int fd);

### vips__write ()

    int                 vips__write                         (int fd,
                                                             const void *buf,
                                                             size_t count);

### vips__file_open_read ()

    FILE *              vips__file_open_read                (const char *filename,
                                                             const char *fallback_dir,
                                                             gboolean text_mode);

### vips__file_open_write ()

    FILE *              vips__file_open_write               (const char *filename,
                                                             gboolean text_mode);

### vips__file_read ()

    char *              vips__file_read                     (FILE *fp,
                                                             const char *name,
                                                             unsigned int *length_out);

### vips__file_read_name ()

    char *              vips__file_read_name                (const char *name,
                                                             const char *fallback_dir,
                                                             unsigned int *length_out);

### vips__file_write ()

    int                 vips__file_write                    (void *data,
                                                             size_t size,
                                                             size_t nmemb,
                                                             FILE *stream);

### vips__get_bytes ()

    int                 vips__get_bytes                     (const char *filename,
                                                             unsigned char buf[],
                                                             int len);

### vips__gvalue_ref_string_new ()

    GValue *            vips__gvalue_ref_string_new         (const char *text);

### vips__gslist_gvalue_free ()

    void                vips__gslist_gvalue_free            (GSList *list);

### vips__gslist_gvalue_copy ()

    GSList *            vips__gslist_gvalue_copy            (const GSList *list);

### vips__gslist_gvalue_merge ()

    GSList *            vips__gslist_gvalue_merge           (GSList *a,
                                                             const GSList *b);

### vips__gslist_gvalue_get ()

    char *              vips__gslist_gvalue_get             (const GSList *list);

### vips__seek ()

    int                 vips__seek                          (int fd,
                                                             gint64 pos);

### vips__ftruncate ()

    int                 vips__ftruncate                     (int fd,
                                                             gint64 pos);

### vips_existsf ()

    int                 vips_existsf                        (const char *name,
                                                             ...);

### vips_mkdirf ()

    int                 vips_mkdirf                         (const char *name,
                                                             ...);

### vips_popenf ()

    FILE *              vips_popenf                         (const char *fmt,
                                                             const char *mode,
                                                             ...);

### enum VipsToken

    typedef enum {
     	VIPS_TOKEN_LEFT = 1,
    	VIPS_TOKEN_RIGHT,
    	VIPS_TOKEN_STRING,
    	VIPS_TOKEN_EQUALS,
    	VIPS_TOKEN_COMMA
    } VipsToken;

Tokens returned by the vips lexical analyzer, see `vips__token_get()`. This is used to parse option strings for arguments.

Left and right brackets can be any of (, {, [, <.

Strings may be in double quotes, and may contain escaped quote characters, for example string, "string" and "str\"ing".

`VIPS_TOKEN_LEFT` | left bracket
`VIPS_TOKEN_RIGHT` | right bracket
`VIPS_TOKEN_STRING` | string constant
`VIPS_TOKEN_EQUALS` | equals sign
`VIPS_TOKEN_COMMA` | comma

### vips__token_get ()

    const char *        vips__token_get                     (const char *buffer,
                                                             VipsToken *token,
                                                             char *string,
                                                             int size);

### vips__token_must ()

    const char *        vips__token_must                    (const char *buffer,
                                                             VipsToken *token,
                                                             char *string,
                                                             int size);

### vips__token_need ()

    const char *        vips__token_need                    (const char *buffer,
                                                             VipsToken need_token,
                                                             char *string,
                                                             int size);

### vips__find_rightmost_brackets ()

    const char *        vips__find_rightmost_brackets       (const char *p);

### vips_ispoweroftwo ()

    int                 vips_ispoweroftwo                   (int p);

### vips_amiMSBfirst ()

    int                 vips_amiMSBfirst                    (void);

### vips__temp_name ()

    char *              vips__temp_name                     (const char *format);

### vips__change_suffix ()

    void                vips__change_suffix                 (const char *name,
                                                             char *out,
                                                             int mx,
                                                             const char *new_suff,
                                                             const char **olds,
                                                             int nolds);