|
1 | 1 | /* |
2 | | - * ghfcns.c |
3 | | - * eMailGanizer |
| 2 | + * Copyright (C) 2007-2013 Rich Waters <[email protected]> |
4 | 3 | * |
5 | | - * Created by Rich Waters on 9/3/10. |
6 | | - * Copyright 2010 GoodHumans. All rights reserved. |
| 4 | + * This file is part of lib_mysqludf_preg. |
7 | 5 | * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
8 | 23 | */ |
9 | 24 |
|
| 25 | +/** @file ghfcns.c |
| 26 | + * |
| 27 | + * @brief Provides some utility functions that are independent of mysql. |
| 28 | + * |
| 29 | + */ |
| 30 | + |
| 31 | + |
10 | 32 | #include <stdlib.h> |
11 | 33 | #include <stdio.h> |
12 | 34 | #include <string.h> |
| 35 | +#include <time.h> |
| 36 | +#include <stdarg.h> |
13 | 37 |
|
14 | 38 | #include "ghfcns.h" |
15 | 39 |
|
@@ -47,3 +71,34 @@ char *ghstrndup( char *s , size_t l ) |
47 | 71 | } |
48 | 72 |
|
49 | 73 |
|
| 74 | +/** |
| 75 | + * @fn void ghlogprintf( fmt, ... ) |
| 76 | + * |
| 77 | + * @brief log an error message to stderr in MySQL format |
| 78 | + * |
| 79 | + * @param fmt - a format string as per sprintf() |
| 80 | + * @param ... - varargs as per sprintf() |
| 81 | + * |
| 82 | + * @return void |
| 83 | + * |
| 84 | + * @details - This function writes the specified error message |
| 85 | + * to stderr prefixed by the current time in the same format |
| 86 | + * used by MySQL |
| 87 | + */ |
| 88 | +void ghlogprintf(char *fmt, ...) { |
| 89 | + va_list vargs; |
| 90 | + char buf[18]; |
| 91 | + time_t now; |
| 92 | + struct tm time_val; |
| 93 | + |
| 94 | + memset(&buf, 0, sizeof(buf)); |
| 95 | + |
| 96 | + now = time(NULL); |
| 97 | + localtime_r(&now, &time_val); |
| 98 | + strftime(&buf[0], sizeof(buf), "%y%m%d %H:%M:%S ", &time_val); |
| 99 | + fprintf(stderr, "%s", buf); |
| 100 | + |
| 101 | + va_start(vargs, fmt); |
| 102 | + vfprintf(stderr, fmt, vargs); |
| 103 | + va_end(vargs); |
| 104 | +} |
0 commit comments