[10] | 1 | // ********************************************************************* |
---|
| 2 | // Copyright 2000-2004, Princeton University. All rights reserved. |
---|
| 3 | // By using this software the USER indicates that he or she has read, |
---|
| 4 | // understood and will comply with the following: |
---|
| 5 | // |
---|
| 6 | // --- Princeton University hereby grants USER nonexclusive permission |
---|
| 7 | // to use, copy and/or modify this software for internal, noncommercial, |
---|
| 8 | // research purposes only. Any distribution, including commercial sale |
---|
| 9 | // or license, of this software, copies of the software, its associated |
---|
| 10 | // documentation and/or modifications of either is strictly prohibited |
---|
| 11 | // without the prior consent of Princeton University. Title to copyright |
---|
| 12 | // to this software and its associated documentation shall at all times |
---|
| 13 | // remain with Princeton University. Appropriate copyright notice shall |
---|
| 14 | // be placed on all software copies, and a complete copy of this notice |
---|
| 15 | // shall be included in all copies of the associated documentation. |
---|
| 16 | // No right is granted to use in advertising, publicity or otherwise |
---|
| 17 | // any trademark, service mark, or the name of Princeton University. |
---|
| 18 | // |
---|
| 19 | // |
---|
| 20 | // --- This software and any associated documentation is provided "as is" |
---|
| 21 | // |
---|
| 22 | // PRINCETON UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS |
---|
| 23 | // OR IMPLIED, INCLUDING THOSE OF MERCHANTABILITY OR FITNESS FOR A |
---|
| 24 | // PARTICULAR PURPOSE, OR THAT USE OF THE SOFTWARE, MODIFICATIONS, OR |
---|
| 25 | // ASSOCIATED DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, |
---|
| 26 | // TRADEMARKS OR OTHER INTELLECTUAL PROPERTY RIGHTS OF A THIRD PARTY. |
---|
| 27 | // |
---|
| 28 | // Princeton University shall not be liable under any circumstances for |
---|
| 29 | // any direct, indirect, special, incidental, or consequential damages |
---|
| 30 | // with respect to any claim by USER or any third party on account of |
---|
| 31 | // or arising from the use, or inability to use, this software or its |
---|
| 32 | // associated documentation, even if Princeton University has been advised |
---|
| 33 | // of the possibility of those damages. |
---|
| 34 | // ********************************************************************* |
---|
| 35 | |
---|
| 36 | #include <stdio.h> |
---|
| 37 | #include <stdarg.h> |
---|
| 38 | #include <stdlib.h> |
---|
| 39 | #include <unistd.h> |
---|
| 40 | #include <sys/time.h> |
---|
| 41 | #include <sys/resource.h> |
---|
| 42 | |
---|
| 43 | int _global_debug_leveli = 0; |
---|
| 44 | |
---|
| 45 | int _global_check_level = 0; |
---|
| 46 | |
---|
| 47 | void fatal(const char * fun, const char * file, int lineno, const char * fmt, ...) { |
---|
| 48 | va_list ap; |
---|
| 49 | fprintf(stderr, "***"); |
---|
| 50 | if (fun) |
---|
| 51 | fprintf(stderr, " in %s", fun); |
---|
| 52 | if (file) |
---|
| 53 | fprintf(stderr, " at %s", file); |
---|
| 54 | if (lineno) |
---|
| 55 | fprintf(stderr, ":%d", lineno); |
---|
| 56 | fprintf(stderr, " "); |
---|
| 57 | va_start(ap, fmt); |
---|
| 58 | vfprintf(stderr, fmt, ap); |
---|
| 59 | va_end(ap); |
---|
| 60 | fflush(stderr); |
---|
| 61 | exit(1); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void warning(const char * fun, const char * file, int lineno, const char * fmt, ...) { |
---|
| 65 | va_list ap; |
---|
| 66 | fprintf(stderr, "***"); |
---|
| 67 | if (fun) |
---|
| 68 | fprintf(stderr, " in %s", fun); |
---|
| 69 | if (file) |
---|
| 70 | fprintf(stderr, " at %s", file); |
---|
| 71 | if (lineno) |
---|
| 72 | fprintf(stderr, ":%d", lineno); |
---|
| 73 | fprintf(stderr, " "); |
---|
| 74 | |
---|
| 75 | va_start(ap, fmt); |
---|
| 76 | vfprintf(stderr, fmt, ap); |
---|
| 77 | va_end(ap); |
---|
| 78 | fflush(stderr); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | double get_cpu_time(void) { |
---|
| 82 | double res; |
---|
| 83 | struct rusage usage; |
---|
| 84 | getrusage(RUSAGE_SELF, &usage); |
---|
| 85 | res = usage.ru_utime.tv_usec + usage.ru_stime.tv_usec; |
---|
| 86 | res *= 1e-6; |
---|
| 87 | res += usage.ru_utime.tv_sec + usage.ru_stime.tv_sec; |
---|
| 88 | return res; |
---|
| 89 | } |
---|