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

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

mr_msg used low level with a debug value of 1 (0 doesn't print enough info)
mr_file reviewed to also have low level debug functions

  • Property svn:eol-style set to native
File size: 1.5 KB
RevLine 
[1088]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>
[1100]13#include <sys/types.h>
14#include <sys/stat.h>
15
[1088]16#include "mr_err.h"
17#include "mr_msg.h"
18
19/*open and read file: each call must be coupled with mr_conf_close
20 function: return 0 if success*/
[1133]21FILE *mr_fopen_int(const char *path, const char *mode,int line, char *file) {
[1088]22 FILE *fd = NULL;
23
24 if ((fd = fopen(path, mode)) == NULL) {
[1133]25 mr_msg(1,line,file,"Unable to open %s",path);
[1088]26 mr_exit(-1,"Exiting");
27 }
28 return(fd);
29}
30
[1133]31void mr_fprintf_int(FILE *fd, int line, char *file, const char *fmt, ...) {
[1088]32
33 va_list args;
34
35 if (fd == NULL) {
[1133]36 mr_msg(1,line,file,"fd is NULL.\nShould NOT happen.");
37 mr_exit(-1,"Exiting");
[1088]38 }
39 va_start(args,fmt);
40 if (vfprintf(fd, fmt, args) < 0) {
[1133]41 mr_msg(1,line,file,"Unable to print to fd");
42 mr_exit(-1,"Exiting");
[1088]43 }
44 va_end(args);
45}
46
[1133]47void mr_fclose_int(FILE **fd, int line, char *file) {
[1088]48
[1133]49 if (**fd == NULL) {
50 mr_msg(1,line,file,"fd is NULL.\nShould NOT happen.");
51 mr_exit(-1,"Exiting");
[1088]52 }
[1133]53 if (*fd == NULL) {
54 mr_msg(1,line,file,"File descriptor is NULL.\nShould NOT happen.");
55 mr_exit(-1,"Exiting");
[1091]56 }
[1133]57 if (fclose(*fd) < 0) {
58 mr_msg(1,line,file,"Unable to close File Descriptor");
59 }
60 *fd = NULL;
[1088]61}
[1100]62
[1133]63void mr_mkdir_int(const char *pathname, mode_t mode, int line, char *file) {
[1100]64
65 if (mkdir(pathname,mode) != 0) {
[1133]66 mr_msg(1,line,file,"Unable to create directory %s",pathname);
[1100]67 mr_exit(-1,"Exiting");
68 }
69}
Note: See TracBrowser for help on using the repository browser.