1/* Copyright (c) 1993-2002 2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de) 3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de) 4 * Copyright (c) 1987 Oliver Laumann 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2, or (at your option) 9 * any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program (see the file COPYING); if not, write to the 18 * Free Software Foundation, Inc., 19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 20 * 21 **************************************************************** 22 * $Id: logfile.h,v 1.11 1994/05/31 12:33:27 jnweiger Exp $ FAU 23 */ 24 25struct logfile 26{ 27 struct logfile *next; 28 FILE *fp; /* a hopefully uniq filepointer to the log file */ 29 char *name; /* the name. used to reopen, when stat fails. */ 30 int opencount; /* synchronize logfopen() and logfclose() */ 31 int writecount; /* increments at logfwrite(), counts write() and fflush() */ 32 int flushcount; /* increments at logfflush(), zeroed at logfwrite() */ 33 struct stat *st; /* how the file looks like */ 34}; 35 36/* 37 * open a logfile, The second argument must be NULL, when the named file 38 * is already a logfile or must be a appropriatly opened file pointer 39 * otherwise. 40 * example: l = logfopen(name, islogfile(name) : NULL ? fopen(name, "a")); 41 */ 42struct logfile *logfopen __P((char *name, FILE *fp)); 43 44/* 45 * lookup a logfile by name. This is useful, so that we can provide 46 * logfopen with a nonzero second argument, exactly when needed. 47 * islogfile(NULL); returns nonzero if there are any open logfiles at all. 48 */ 49int islogfile __P((char *name)); 50 51/* 52 * logfclose does free() 53 */ 54int logfclose __P((struct logfile *)); 55int logfwrite __P((struct logfile *, char *, int)); 56 57/* 58 * logfflush should be called periodically. If no argument is passed, 59 * all logfiles are flushed, else the specified file 60 * the number of flushed filepointers is returned 61 */ 62int logfflush __P((struct logfile *ifany)); 63 64/* 65 * a reopen function may be registered here, in case you want to bring your 66 * own (more secure open), it may come along with a private data pointer. 67 * this function is called, whenever logfwrite/logfflush detect that the 68 * file has been (re)moved, truncated or changed by someone else. 69 * if you provide NULL as parameter to logreopen_register, the builtin 70 * reopen function will be reactivated. 71 */ 72void logreopen_register __P((int (*fn) __P((char *, int, struct logfile *)) )); 73 74/* 75 * Your custom reopen function is required to reuse the exact 76 * filedescriptor. 77 * See logfile.c for further specs and an example. 78 * 79 * lf_move_fd may help you here, if you do not have dup2(2). 80 * It closes fd and opens wantfd to access whatever fd accessed. 81 */ 82int lf_move_fd __P((int fd, int wantfd)); 83