3 * Written by Jan Roeloffzen
19 set_LogFile(FILE **plogFile
)
27 if (strcmp(opt_logFile
,"none") == 0)
28 return 0; //just close
30 *plogFile
= fopen(opt_logFile
, opt_mod
? opt_mod
: "a");
33 // disable buffering so fflush is not needed
36 l2l_dbg(1, "Disabling log buffering on %s\n", opt_logFile
);
37 setbuf(*plogFile
, NULL
);
40 l2l_dbg(1, "Enabling log buffering on %s\n", opt_logFile
);
44 l2l_dbg(0, "Could not open logfile %s (%s)\n", opt_logFile
, strerror(errno
));
52 file_exists(char *name
)
63 /* Do this in reverse (recursively)
64 This saves many system calls if the path is likely
65 to already exist (creating large trees).
68 mkPath(char *path
, int isDir
)
76 if (!res
|| (res
== -1 && errno
== EEXIST
))
80 if ((s
= strrchr(path
, PATH_CHAR
)))
83 res
= mkPath(path
, 1);
95 rfopen(char *path
, char *mode
)
98 char tmppath
[PATH_MAX
]; // Don't modify const strings
100 strcpy(tmppath
, path
);
101 f
= fopen(tmppath
, mode
);
102 if (!f
&& !mkPath(tmppath
, 0))
103 f
= fopen(tmppath
, mode
);
114 base
= strrchr(path
, PATH_CHAR
);
121 getFmt(const char *a
)
123 const char *fmt
= "%x";
146 my_atoi(const char *a
)
149 sscanf(a
, getFmt(a
), &i
);
154 isOffset(const char *a
)
159 return sscanf(a
, getFmt(a
), &i
);
163 copy_file(char *src
, char *dst
)
167 sprintf(Line
, CP_FMT
, src
, dst
);
168 l2l_dbg(2, "Executing: %s\n", Line
);
170 if (file_exists(dst
))
172 l2l_dbg(0, "Cannot remove dst %s before copy\n", dst
);
175 if (system(Line
) < 0)
177 l2l_dbg(0, "Cannot copy %s to %s\n", src
, dst
);
178 l2l_dbg(1, "Failed to execute: '%s'\n", Line
);
182 if (!file_exists(dst
))
184 l2l_dbg(0, "Dst %s does not exist after copy\n", dst
);