| 1 |
/* Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/). All Rights Reserved. |
| 2 |
This software is licensed as OpenSource, under the Apache License, Version 2.0. |
| 3 |
This license is available at: http://opensource.org/licenses/Apache-2.0. */ |
| 4 |
|
| 5 |
#ifndef CTUTIL_H |
| 6 |
#define CTUTIL_H |
| 7 |
|
| 8 |
#include "ctlshare.h" |
| 9 |
|
| 10 |
#define CTU_VERSION CTL_MAKE_VERSION(2, 0, 3) |
| 11 |
|
| 12 |
#include <stddef.h> /* For size_t */ |
| 13 |
#include <stdio.h> /* For size_t */ |
| 14 |
#include <time.h> /* For struct tm */ |
| 15 |
|
| 16 |
#ifdef __cplusplus |
| 17 |
extern "C" { |
| 18 |
#endif |
| 19 |
|
| 20 |
/* CoreType Utilities Library |
| 21 |
========================== |
| 22 |
This library contains miscellaneous utility functions that are applicable |
| 23 |
across many applications and are therefore separated out into a library. */ |
| 24 |
|
| 25 |
typedef int(CTL_CDECL *ctuCmpFunc)(const void *first, const void *second, void *ctx); |
| 26 |
void ctuQSort(void *base, size_t count, size_t size, ctuCmpFunc cmp, void *ctx); |
| 27 |
|
| 28 |
/* Sort array. |
| 29 |
|
| 30 |
CTUQSort() is modeled on the ANSI C library qsort() function and all |
| 31 |
arguments and semantics, except the "ctx" arguments, match those of the |
| 32 |
standard function. The "ctx" arguments provides the facility for the client |
| 33 |
to pass a context containing auxiliary data to the comparison function. |
| 34 |
|
| 35 |
This function is intended to be used in situations where auxiliary data is |
| 36 |
required by the comparison function but can't be provided by global |
| 37 |
variables for reentrancy reasons. */ |
| 38 |
|
| 39 |
typedef int(CTL_CDECL *ctuMatchFunc)(const void *key, const void *value, void *ctx); |
| 40 |
int ctuLookup(const void *key, const void *base, size_t count, size_t size, |
| 41 |
ctuMatchFunc match, size_t *index, void *ctx); |
| 42 |
|
| 43 |
/* Search sorted array for key. |
| 44 |
|
| 45 |
CTULookup() is modeled on the ANSI C library bsearch() function. However, it |
| 46 |
differs from the standard function in that it returns an element index, via |
| 47 |
the "index" parameter, and not an element pointer. It also returns the |
| 48 |
result of the search. If an element in the array matches the key, the |
| 49 |
function returns 1 and the "index" parameter is set to the matching element. |
| 50 |
If no matching element is found, the function returns 0 and the "index" |
| 51 |
parameter is set to the element where the key should be inserted. The "ctx" |
| 52 |
arguments provides the facility for the client to pass a context containing |
| 53 |
auxiliary data to the comparison function. |
| 54 |
|
| 55 |
This function is intended to be used for inserting new elements into a |
| 56 |
sorted list without duplicating identical elements. */ |
| 57 |
|
| 58 |
typedef unsigned char ctuLongDateTime[8]; |
| 59 |
|
| 60 |
/* Apple's LongDateTime is a 64-bit number representing the number of seconds |
| 61 |
since 1 Jan 1904 00:00:00 local time. This value is stored in an 8 byte |
| 62 |
array, most significant byte first. |
| 63 |
|
| 64 |
The conversions performed by the functions in this library are use the long |
| 65 |
data type, which is assumed to hold at least 32-bits, and do not check for |
| 66 |
overflow. This means that the conversions are only valid for dates up to 6 |
| 67 |
Feb 2040 06:28:15; 32-bit overflow occurs on the next second. |
| 68 |
*/ |
| 69 |
|
| 70 |
void ctuANSITime2LongDateTime(struct tm *ansi, ctuLongDateTime ldt); |
| 71 |
|
| 72 |
/* ctuANSITime2LongDateTime() converts ANSI standard date/time format to Apple |
| 73 |
LongDateTime format. |
| 74 |
|
| 75 |
The struct tm fields: tm_wday, tm_yday, and tm_dst are ignored by the |
| 76 |
conversion process. No validation is performed on the input data. */ |
| 77 |
|
| 78 |
void ctuLongDateTime2ANSITime(struct tm *ansi, ctuLongDateTime ldt); |
| 79 |
|
| 80 |
/* ctuLongDateTime2ANSITime() converts Apple LongDateTime format to ANSI |
| 81 |
standard date/time format. */ |
| 82 |
|
| 83 |
int ctuCountBits(long value); |
| 84 |
|
| 85 |
/* ctuCountBits() counts the number of bits set in the value argument. */ |
| 86 |
|
| 87 |
double ctuStrtod(const char *s, char **endptr); |
| 88 |
|
| 89 |
/* ctuStrtod() operates like the standard library function strtod() except that |
| 90 |
it behaves as though it was using the C locale and thus the decimal point |
| 91 |
character is always a period and not comma. */ |
| 92 |
|
| 93 |
void ctuDtostr(char *buf, size_t bufLen, double value, int width, int precision); |
| 94 |
|
| 95 |
/* ctuDtostr() converts the "value" parameter into a string and stores the |
| 96 |
result into the buffer pointed to by the "buf" parameter. The conversion is |
| 97 |
performed using the "%g" print format and if the "width" or "precision" |
| 98 |
parameters are non-0 they are used to control the minimum field width and |
| 99 |
precision, respectively. This function behaves as though it was using the C |
| 100 |
locale and thus the decimal point character is always a period and not |
| 101 |
comma. */ |
| 102 |
|
| 103 |
void ctuGetVersion(ctlVersionCallbacks *cb); |
| 104 |
|
| 105 |
/* ctuGetVersion() returns the library version number and name via the client |
| 106 |
callbacks passed with the "cb" parameter (see ctlshare.h). */ |
| 107 |
|
| 108 |
#if !defined(_UCRT) && !defined(__cplusplus) |
| 109 |
float roundf(float x); |
| 110 |
#endif |
| 111 |
|
| 112 |
#ifdef __cplusplus |
| 113 |
} |
| 114 |
#endif |
| 115 |
|
| 116 |
#endif /* CTUTIL_H */ |