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

Last change on this file since 1091 was 1091, checked in by bruno, 12 years ago

mr_fclose improved + fixes for libmondo-archive.c

  • Property svn:eol-style set to native
File size: 962 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 mr_fclose(FILE *fd) {
43
44    if (fd == NULL) {
45        mr_log_exit(-1,"fd is NULL.\nShould NOT happen.\nExiting");
46    }
47    if (fclose(fd) < 0) {
48        mr_msg(0,"Unable to close fd");
49    }
50    fd = NULL;
51}
Note: See TracBrowser for help on using the repository browser.