/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/util.h
C++ Header | 133 lines | 71 code | 44 blank | 18 comment | 0 complexity | 9f472afbceaf4da928185db77a52ed5a MD5 | raw file
1/* 2 util.h - general purpose utility routines 3 Copyright (C) 2007, 2008 siliconforks.com 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along 16 with this program; if not, write to the Free Software Foundation, Inc., 17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18*/ 19 20#ifndef UTIL_H_ 21#define UTIL_H_ 22 23#ifndef HAVE_VASPRINTF 24#include <stdarg.h> 25#endif 26#include <stdbool.h> 27#include <stdio.h> 28#include <stdlib.h> 29 30#include <sys/stat.h> 31 32#ifdef __cplusplus 33extern "C" { 34#endif 35 36extern const char * program; 37 38void fatal(const char * format, ...) 39 __attribute__((__noreturn__)) 40 __attribute__((__format__(printf, 1, 2))); 41 42void fatal_command_line(const char * format, ...) 43 __attribute__((__noreturn__)) 44 __attribute__((__format__(printf, 1, 2))); 45 46void fatal_source(const char * source_file, unsigned int line_number, const char * format, ...) 47 __attribute__((__noreturn__)) 48 __attribute__((__format__(printf, 3, 4))); 49 50void warn_source(const char * source_file, unsigned int line_number, const char * format, ...) 51 __attribute__((__format__(printf, 3, 4))); 52 53void version(void) 54 __attribute__((__noreturn__)); 55 56size_t addst(size_t x, size_t y); 57 58size_t mulst(size_t x, size_t y); 59 60void * xmalloc(size_t size); 61 62#define xnew(type, count) ((type *) xmalloc(mulst((count), sizeof(type)))) 63 64void * xrealloc(void * p, size_t size); 65 66char * xstrdup(const char * s); 67 68char * xstrndup(const char * s, size_t size); 69 70int xasprintf(char ** s, const char * format, ...) __attribute__((__format__(printf, 2, 3))); 71 72char * xgetcwd(void); 73 74FILE * xfopen(const char * file, const char * mode); 75 76void xstat(const char * file, struct stat * buf); 77 78void xlstat(const char * file, struct stat * buf); 79 80void xmkdir(const char * directory); 81 82void mkdir_if_necessary(const char * directory); 83 84void mkdirs(const char * path); 85 86bool str_starts_with(const char * string, const char * prefix); 87 88bool str_ends_with(const char * string, const char * suffix); 89 90char * make_path(const char * parent, const char * relative_path); 91 92char * make_canonical_path(const char * relative_path); 93 94char * make_basename(const char * path); 95 96char * make_dirname(const char * path); 97 98int is_same_file(const char * file1, const char * file2); 99 100int contains_file(const char * file1, const char * file2); 101 102void copy_stream(FILE * source, FILE * destination); 103 104void copy_file(const char * source_file, const char * destination_file); 105 106bool directory_is_empty(const char * directory); 107 108struct DirListEntry { 109 char * name; 110 struct DirListEntry * next; 111}; 112 113struct DirListEntry * make_recursive_dir_list(const char * directory); 114 115void free_dir_list(struct DirListEntry * list); 116 117#ifndef HAVE_STRNDUP 118char * strndup(const char * s, size_t size); 119#endif 120 121#ifndef HAVE_VASPRINTF 122int vasprintf(char ** s, const char * format, va_list a); 123#endif 124 125#ifndef HAVE_ASPRINTF 126int asprintf(char ** s, const char * format, ...) __attribute__((__format__(printf, 2, 3))); 127#endif 128 129#ifdef __cplusplus 130} 131#endif 132 133#endif /* UTIL_H_ */