2525#ifndef CUTILS_H
2626#define CUTILS_H
2727
28+ #include <stdbool.h>
2829#include <stdlib.h>
2930#include <string.h>
3031#include <inttypes.h>
@@ -54,14 +55,6 @@ extern "C" {
5455#include <pthread.h>
5556#endif
5657
57- #if defined(__SANITIZE_ADDRESS__ )
58- # define __ASAN__ 1
59- #elif defined(__has_feature )
60- # if __has_feature (address_sanitizer )
61- # define __ASAN__ 1
62- # endif
63- #endif
64-
6558#if defined(_MSC_VER ) && !defined(__clang__ )
6659# define likely (x ) (x)
6760# define unlikely (x ) (x)
@@ -70,10 +63,6 @@ extern "C" {
7063# define __maybe_unused
7164# define __attribute__ (x )
7265# define __attribute (x )
73- # include <intrin.h>
74- static void * __builtin_frame_address (unsigned int level ) {
75- return (void * )((char * )_AddressOfReturnAddress () - sizeof (int * ) - level * sizeof (int * ));
76- }
7766#else
7867# define likely (x ) __builtin_expect(!!(x), 1)
7968# define unlikely (x ) __builtin_expect(!!(x), 0)
@@ -124,19 +113,10 @@ static void *__builtin_frame_address(unsigned int level) {
124113#define minimum_length (n ) static n
125114#endif
126115
127- typedef int BOOL ;
128-
129- #ifndef FALSE
130- enum {
131- FALSE = 0 ,
132- TRUE = 1 ,
133- };
134- #endif
135-
136- void pstrcpy (char * buf , int buf_size , const char * str );
137- char * pstrcat (char * buf , int buf_size , const char * s );
138- int strstart (const char * str , const char * val , const char * * ptr );
139- int has_suffix (const char * str , const char * suffix );
116+ void js__pstrcpy (char * buf , int buf_size , const char * str );
117+ char * js__pstrcat (char * buf , int buf_size , const char * s );
118+ int js__strstart (const char * str , const char * val , const char * * ptr );
119+ int js__has_suffix (const char * str , const char * suffix );
140120
141121static inline uint8_t is_be (void ) {
142122 union {
@@ -440,7 +420,7 @@ typedef struct DynBuf {
440420 uint8_t * buf ;
441421 size_t size ;
442422 size_t allocated_size ;
443- BOOL error ; /* true if a memory allocation error occurred */
423+ bool error ; /* true if a memory allocation error occurred */
444424 DynBufReallocFunc * realloc_func ;
445425 void * opaque ; /* for realloc_func */
446426} DynBuf ;
@@ -468,12 +448,12 @@ static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
468448int __attribute__((format (printf , 2 , 3 ))) dbuf_printf (DynBuf * s ,
469449 FORMAT_STRING (const char * fmt ), ...);
470450void dbuf_free (DynBuf * s );
471- static inline BOOL dbuf_error (DynBuf * s ) {
451+ static inline bool dbuf_error (DynBuf * s ) {
472452 return s -> error ;
473453}
474454static inline void dbuf_set_error (DynBuf * s )
475455{
476- s -> error = TRUE ;
456+ s -> error = true ;
477457}
478458
479459/*---- UTF-8 and UTF-16 handling ----*/
@@ -497,17 +477,17 @@ size_t utf8_decode_buf16(uint16_t *dest, size_t dest_len, const char *src, size_
497477size_t utf8_encode_buf8 (char * dest , size_t dest_len , const uint8_t * src , size_t src_len );
498478size_t utf8_encode_buf16 (char * dest , size_t dest_len , const uint16_t * src , size_t src_len );
499479
500- static inline BOOL is_surrogate (uint32_t c )
480+ static inline bool is_surrogate (uint32_t c )
501481{
502482 return (c >> 11 ) == (0xD800 >> 11 ); // 0xD800-0xDFFF
503483}
504484
505- static inline BOOL is_hi_surrogate (uint32_t c )
485+ static inline bool is_hi_surrogate (uint32_t c )
506486{
507487 return (c >> 10 ) == (0xD800 >> 10 ); // 0xD800-0xDBFF
508488}
509489
510- static inline BOOL is_lo_surrogate (uint32_t c )
490+ static inline bool is_lo_surrogate (uint32_t c )
511491{
512492 return (c >> 10 ) == (0xDC00 >> 10 ); // 0xDC00-0xDFFF
513493}
0 commit comments