1 /*
2  *
3  * honggfuzz - utilities
4  * -----------------------------------------
5  *
6  * Author: Robert Swiecki <swiecki@google.com>
7  *
8  * Copyright 2010-2015 by Google Inc. All Rights Reserved.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License"); you may
11  * not use this file except in compliance with the License. You may obtain
12  * a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19  * implied. See the License for the specific language governing
20  * permissions and limitations under the License.
21  *
22  */
23 
24 #ifndef _HF_UTIL_H_
25 #define _HF_UTIL_H_
26 
27 #include <stdarg.h>
28 #include <stdint.h>
29 
30 #define MX_LOCK(m) util_mutexLock(m, __func__, __LINE__)
31 #define MX_UNLOCK(m) util_mutexUnlock(m, __func__, __LINE__)
32 
33 extern void *util_Malloc(size_t sz);
34 
35 extern uint64_t util_rndGet(uint64_t min, uint64_t max);
36 
37 extern void util_rndBuf(uint8_t * buf, size_t sz);
38 
39 extern int util_ssnprintf(char *str, size_t size, const char *format, ...);
40 
41 extern int util_vssnprintf(char *str, size_t size, const char *format, va_list ap);
42 
43 extern void util_getLocalTime(const char *fmt, char *buf, size_t len, time_t tm);
44 
45 extern void util_nullifyStdio(void);
46 
47 extern bool util_redirectStdin(const char *inputFile);
48 
49 extern uint64_t util_hash(const char *buf, size_t len);
50 
51 extern int64_t util_timeNowMillis(void);
52 
53 extern uint16_t util_ToFromBE16(uint16_t val);
54 extern uint16_t util_ToFromLE16(uint16_t val);
55 extern uint32_t util_ToFromBE32(uint32_t val);
56 extern uint32_t util_ToFromLE32(uint32_t val);
57 extern uint64_t util_getUINT32(const uint8_t * buf);
58 extern uint64_t util_getUINT64(const uint8_t * buf);
59 
60 extern void util_mutexLock(pthread_mutex_t * mutex, const char *func, int line);
61 extern void util_mutexUnlock(pthread_mutex_t * mutex, const char *func, int line);
62 
63 extern int64_t fastArray64Search(uint64_t * array, size_t arraySz, uint64_t key);
64 
65 extern bool util_isANumber(const char *s);
66 
67 #endif
68