source: MondoRescue/branches/stable/mondo/src/lib/mr_file.c@ 1088

Last change on this file since 1088 was 1088, checked in by Bruno Cornec, 17 years ago

Addition of mr_file

  • Property svn:eol-style set to native
File size: 918 bytes
Line 
1/* mr_file.c
2 *
3 * $Id$
4 *
5 * File management for mondo
6 * Code (c)2006 Bruno Cornec <bruno@mondorescue.org>
7 *
8 * Provided under the GPLv2
9 */
10
11
12#include <stdio.h>
13#include "mr_err.h"
14#include "mr_msg.h"
15
16/*open and read file: each call must be coupled with mr_conf_close
17 function: return 0 if success*/
18FILE *mr_fopen(const char *path, const char *mode) {
19 FILE *fd = NULL;
20
21 if ((fd = fopen(path, mode)) == NULL) {
22 mr_msg(0,"Unable to open %s",path);
23 mr_exit(-1,"Exiting");
24 }
25 return(fd);
26}
27
28void mr_fprintf(FILE *fd, const char *fmt, ...) {
29
30 va_list args;
31
32 if (fd == NULL) {
33 mr_log_exit(-1,"fd is NULL.\nShould NOT happen.\nExiting");
34 }
35 va_start(args,fmt);
36 if (vfprintf(fd, fmt, args) < 0) {
37 mr_msg(0,"Unable to print '%s'",args);
38 }
39 va_end(args);
40}
41
42void fclose(FILE *fd) {
43
44 if (fd == NULL) {
45 mr_log_exit(-1,"fd is NULL.\nShould NOT happen.\nExiting");
46 }
47 (void)fclose(fd);
48 fd = NULL;
49}
Note: See TracBrowser for help on using the repository browser.