error.c (1620B)
1 /* 2 wificurse - WiFi Jamming tool 3 Copyright (C) 2012 oblique 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 3 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 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #include <stdio.h> 20 #include <stdarg.h> 21 #include <string.h> 22 #include "error.h" 23 24 25 struct _error { 26 int errnum; 27 int line; 28 char *file; 29 char msg[1024]; 30 }; 31 32 static struct _error __thread _error; 33 34 35 void set_error(char *file, int line, int errnum, char *fmt, ...) { 36 va_list args; 37 38 _error.file = file; 39 _error.line = line; 40 _error.errnum = errnum; 41 va_start(args, fmt); 42 vsnprintf(_error.msg, sizeof(_error.msg), fmt, args); 43 va_end(args); 44 } 45 46 void print_error() { 47 char buf[1024]; 48 strerror_r(_error.errnum, buf, sizeof(buf)); 49 fprintf(stderr, "%s:%d: %s: %s\n", _error.file, _error.line, _error.msg, buf); 50 } 51 52 void _err_msg(char *file, int line, int errnum, char *fmt, ...) { 53 char buf[1024], msg[1024]; 54 va_list args; 55 56 va_start(args, fmt); 57 vsnprintf(msg, sizeof(msg), fmt, args); 58 va_end(args); 59 strerror_r(errnum, buf, sizeof(buf)); 60 fprintf(stderr, "%s:%d: %s: %s\n", file, line, msg, buf); 61 }