1 // Like the compiler, the static analyzer treats some functions differently if 2 // they come from a system header -- for example, it is assumed that system 3 // functions do not arbitrarily free() their parameters, and that some bugs 4 // found in system headers cannot be fixed by the user and should be 5 // suppressed. 6 #pragma clang system_header 7 8 #ifdef __cplusplus 9 #define restrict /*restrict*/ 10 #endif 11 12 typedef __typeof(sizeof(int)) size_t; 13 typedef long long __int64_t; 14 typedef __int64_t __darwin_off_t; 15 typedef __darwin_off_t fpos_t; 16 typedef int off_t; 17 typedef long ssize_t; 18 19 typedef struct _FILE FILE; 20 #define SEEK_SET 0 /* Seek from beginning of file. */ 21 #define SEEK_CUR 1 /* Seek from current position. */ 22 #define SEEK_END 2 /* Seek from end of file. */ 23 24 extern FILE *stdin; 25 extern FILE *stdout; 26 extern FILE *stderr; 27 // Include a variant of standard streams that occur in the pre-processed file. 28 extern FILE *__stdinp; 29 extern FILE *__stdoutp; 30 extern FILE *__stderrp; 31 32 int scanf(const char *restrict format, ...); 33 int fscanf(FILE *restrict, const char *restrict, ...); 34 int printf(const char *restrict format, ...); 35 int fprintf(FILE *restrict, const char *restrict, ...); 36 int getchar(void); 37 38 void setbuf(FILE *restrict, char *restrict); 39 int setvbuf(FILE *restrict, char *restrict, int, size_t); 40 41 FILE *funopen(const void *, 42 int (*)(void *, char *, int), 43 int (*)(void *, const char *, int), 44 fpos_t (*)(void *, fpos_t, int), 45 int (*)(void *)); 46 47 FILE *fopen(const char *restrict path, const char *restrict mode); 48 FILE *fdopen(int fd, const char *mode); 49 FILE *tmpfile(void); 50 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE *restrict stream); 51 FILE *popen(const char *command, const char *mode); 52 int fclose(FILE *fp); 53 int pclose(FILE *stream); 54 size_t fread(void *restrict, size_t, size_t, FILE *restrict); 55 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict); 56 int fgetc(FILE *stream); 57 char *fgets(char *restrict str, int count, FILE *restrict stream); 58 int fputc(int ch, FILE *stream); 59 int fputs(const char *restrict s, FILE *restrict stream); 60 int ungetc(int c, FILE *stream); 61 ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delimiter, FILE *restrict stream); 62 ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict stream); 63 int fseek(FILE *__stream, long int __off, int __whence); 64 int fseeko(FILE *__stream, off_t __off, int __whence); 65 long int ftell(FILE *__stream); 66 off_t ftello(FILE *__stream); 67 void rewind(FILE *__stream); 68 int fgetpos(FILE *restrict stream, fpos_t *restrict pos); 69 int fsetpos(FILE *stream, const fpos_t *pos); 70 void clearerr(FILE *stream); 71 int feof(FILE *stream); 72 int ferror(FILE *stream); 73 int fileno(FILE *stream); 74 int fflush(FILE *stream); 75 76 77 int getc(FILE *stream); 78 79 size_t strlen(const char *); 80 81 char *strcpy(char *restrict, const char *restrict); 82 char *strncpy(char *restrict dst, const char *restrict src, size_t n); 83 char *strsep(char **restrict stringp, const char *restrict delim); 84 void *memcpy(void *restrict dst, const void *restrict src, size_t n); 85 void *memset(void *s, int c, size_t n); 86 87 typedef unsigned long __darwin_pthread_key_t; 88 typedef __darwin_pthread_key_t pthread_key_t; 89 int pthread_setspecific(pthread_key_t, const void *); 90 91 int sqlite3_bind_text_my(int, const char*, int n, void(*)(void*)); 92 93 typedef void (*freeCallback) (void*); 94 typedef struct { 95 int i; 96 freeCallback fc; 97 } StWithCallback; 98 99 int dealocateMemWhenDoneByVal(void*, StWithCallback); 100 int dealocateMemWhenDoneByRef(StWithCallback*, const void*); 101 102 typedef struct CGContext *CGContextRef; 103 CGContextRef CGBitmapContextCreate(void *data/*, size_t width, size_t height, 104 size_t bitsPerComponent, size_t bytesPerRow, 105 CGColorSpaceRef space, 106 CGBitmapInfo bitmapInfo*/); 107 void *CGBitmapContextGetData(CGContextRef context); 108 109 // Include xpc. 110 typedef struct _xpc_connection_s * xpc_connection_t; 111 typedef void (*xpc_finalizer_t)(void *value); 112 void xpc_connection_set_context(xpc_connection_t connection, void *context); 113 void xpc_connection_set_finalizer_f(xpc_connection_t connection, xpc_finalizer_t finalizer); 114 void xpc_connection_resume(xpc_connection_t connection); 115 116 //The following are fake system header functions for generic testing. 117 void fakeSystemHeaderCallInt(int *); 118 void fakeSystemHeaderCallIntPtr(int **); 119 120 // Some data strauctures may hold onto the pointer and free it later. 121 void fake_insque(void *, void *); 122 typedef struct fake_rb_tree { void *opaque[8]; } fake_rb_tree_t; 123 void fake_rb_tree_init(fake_rb_tree_t *, const void *); 124 void *fake_rb_tree_insert_node(fake_rb_tree_t *, void *); 125 126 typedef struct __SomeStruct { 127 char * p; 128 } SomeStruct; 129 void fakeSystemHeaderCall(SomeStruct *); 130 131 typedef int pid_t; 132 pid_t fork(void); 133 pid_t vfork(void); 134 int execl(const char *path, const char *arg, ...); 135 int execle(const char *path, const char *arg, ...); 136 int execlp(const char *file, const char *arg, ...); 137 int execv(const char *path, char *const argv[]); 138 int execve(const char *path, char *const argv[], char *const envp[]); 139 int execvp(const char *file, char *const argv[]); 140 int execvpe(const char *file, char *const argv[], char *const envp[]); 141 142 void exit(int status) __attribute__ ((__noreturn__)); 143 void _exit(int status) __attribute__ ((__noreturn__)); 144 void _Exit(int status) __attribute__ ((__noreturn__)); 145 146 #define UINT32_MAX 4294967295U 147 #define INT64_MIN (-INT64_MAX-1) 148 #define __DBL_MAX__ 1.7976931348623157e+308 149 #define DBL_MAX __DBL_MAX__ 150 #ifndef NULL 151 #define __DARWIN_NULL 0 152 #define NULL __DARWIN_NULL 153 #endif 154 #define EOF (-1) 155 156 #define offsetof(t, d) __builtin_offsetof(t, d) 157 158 struct sigaction { 159 void (*sa_handler)(int); 160 }; 161 #define SIGINT 2 162 #define SIG_IGN (void (*)(int))1 163 164 int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict); 165