|
@@ -4,9 +4,11 @@
|
|
|
*
|
|
|
* Created on 8 novembre 2018
|
|
|
*/
|
|
|
+#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
+#include <stdarg.h>
|
|
|
#include <unistd.h>
|
|
|
#include <fcntl.h>
|
|
|
#include <sys/types.h>
|
|
@@ -29,7 +31,7 @@ char* serrlib[] = {
|
|
|
};
|
|
|
Error error;
|
|
|
|
|
|
-/* --- Fonctions privée --- */
|
|
|
+/* --- Fonctions de la structure --- */
|
|
|
void end(){
|
|
|
time_t temps;
|
|
|
int fd;
|
|
@@ -56,6 +58,8 @@ void end(){
|
|
|
error.exit_status = NULL;
|
|
|
error.exit_msg = NULL;
|
|
|
error.add = NULL;
|
|
|
+ error.print = NULL;
|
|
|
+ error.printadd = NULL;
|
|
|
//On indique que la structure est non inialisée
|
|
|
error.init = 0;
|
|
|
}
|
|
@@ -78,8 +82,26 @@ void exit_msg(char* msg, int status){
|
|
|
error.exit_status(status);
|
|
|
}
|
|
|
|
|
|
-void add(char* msg){
|
|
|
- fprintf(stderr, "%s\n", msg);
|
|
|
+void add(const char* format, ...){
|
|
|
+ va_list arg;
|
|
|
+ va_start(arg, format);
|
|
|
+ vfprintf(stderr, format, arg);
|
|
|
+ va_end(arg);
|
|
|
+}
|
|
|
+
|
|
|
+void printerr(const char* format, ...){
|
|
|
+ va_list arg;
|
|
|
+ va_start(arg, format);
|
|
|
+ vdprintf(error.errfd, format, arg);
|
|
|
+ va_end(arg);
|
|
|
+}
|
|
|
+
|
|
|
+void printadd(const char* format, ...){
|
|
|
+ va_list arg;
|
|
|
+ va_start(arg, format);
|
|
|
+ vdprintf(error.errfd, format, arg);
|
|
|
+ vfprintf(stderr, format, arg);
|
|
|
+ va_end(arg);
|
|
|
}
|
|
|
|
|
|
/* --- Fonctions publiques --- */
|
|
@@ -146,6 +168,8 @@ void error_finit(const char* filename){
|
|
|
error.exit_status = exit_status;
|
|
|
error.exit_msg = exit_msg;
|
|
|
error.add = add;
|
|
|
+ error.print = printerr;
|
|
|
+ error.printadd = printadd;
|
|
|
//Ecriture 1er ligne
|
|
|
fprintf(stderr, "----- Log processus %d (timestamp : %ld) -----\n", getpid(), error.start);
|
|
|
//On indique que l'inialisation a eu lieu
|