GIÁO TRÌNH HỆ ĐIỀU HÀNH UNIX - LINUX - Trang 157

1
5

/*
* liberr.h
*/

#ifndef _LIBERR_H
#define _LIBERR_H
#include <stdarg.h>
/* in ra một thông báo lỗi tới việcgọi stderr và return hàm gọi */
void err_quit(const char *fmt, … );
/* in ra một thông điệp lỗi cho logfile và trả về hàm gọi */
void log_ret(char *logfile, const char *fmt, …);
/* in ra một thông điệp lỗi cho logfile và thoát */
void log_quit( char *logfile, const char *fmt , …);
/* in ra một thông báo lỗi và trả lại hàm gọi */
void err_prn(const char *fmt, va_list ap, char *logfile);
#endif //_LIBERR_H

Mã ngun cho file liberr.h

#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include "liberr.h"
#define MAXLINELEN 500
void err_ret(const char *fmt, ...)
{

va_list ap;

va_start(ap, fmt);

err_prn(fmt, ap, NULL);

va_end(ap);

return;

}
void err_quit(const char *fmt, ...)
{

va_list ap;

va_start(ap, fmt);

err_prn(fmt, ap, NULL);

va_end(ap);

exit(1);

}
void log_ret(char *logfile, const char *fmt, ...)
{

va_list ap;

va_start(ap, fmt);

err_prn(fmt,ap, logfile);

va_end(ap);

return;

}