return str;
}
-void file_strip_crs(const gchar *file)
+gint file_strip_crs(const gchar *file)
{
FILE *fp = NULL, *outfp = NULL;
gchar buf[4096];
while (fgets(buf, sizeof (buf), fp) != NULL) {
strcrchomp(buf);
- fputs(buf, outfp);
+ if (fputs(buf, outfp) == EOF) {
+ fclose(fp);
+ fclose(outfp);
+ goto unlinkout;
+ }
}
fclose(fp);
- fclose(outfp);
- rename_force(out, file);
+ if (fclose(outfp) == EOF) {
+ goto unlinkout;
+ }
+
+ if (rename_force(out, file) < 0)
+ goto unlinkout;
+
+ return 0;
+unlinkout:
+ g_unlink(out);
freeout:
g_free(out);
+ return -1;
}
/* Similar to `strstr' but this function ignores the case of both strings. */
#endif
}
+static gchar *claws_rc_dir = NULL;
+static gboolean rc_dir_alt = FALSE;
const gchar *get_rc_dir(void)
{
- static gchar *rc_dir = NULL;
- if (!rc_dir)
- rc_dir = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
+ if (!claws_rc_dir)
+ claws_rc_dir = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
RC_DIR, NULL);
- return rc_dir;
+ return claws_rc_dir;
+}
+
+void set_rc_dir(const gchar *dir)
+{
+ if (claws_rc_dir != NULL) {
+ g_print("Error: rc_dir already set\n");
+ } else {
+ rc_dir_alt = TRUE;
+ if (g_path_is_absolute(dir))
+ claws_rc_dir = g_strdup(dir);
+ else {
+ claws_rc_dir = g_strconcat(g_get_current_dir(),
+ G_DIR_SEPARATOR_S, dir, NULL);
+ }
+ debug_print("set rc_dir to %s\n", claws_rc_dir);
+ if (!is_dir_exist(claws_rc_dir)) {
+ if (make_dir_hier(claws_rc_dir) != 0) {
+ g_print("Error: can't create %s\n",
+ claws_rc_dir);
+ }
+ }
+ }
+}
+
+gboolean rc_dir_is_alt(void) {
+ return rc_dir_alt;
}
const gchar *get_mail_base_dir(void)
t = time(NULL);
lt = localtime_r(&t, &buf1);
-#ifdef SOLARIS
- sscanf(asctime_r(lt, buf2, sizeof(buf2)), "%3s %3s %d %d:%d:%d %d\n",
- day, mon, &dd, &hh, &mm, &ss, &yyyy);
-#else
sscanf(asctime_r(lt, buf2), "%3s %3s %d %d:%d:%d %d\n",
day, mon, &dd, &hh, &mm, &ss, &yyyy);
-#endif
+
g_snprintf(buf, len, "%s, %d %s %d %02d:%02d:%02d %s",
day, dd, mon, yyyy, hh, mm, ss, tzoffset(&t));
}
FILE *fp = fopen(path, "rb");
FILE *outfp = fopen(outpath, "wb");
gchar buf[BUFFSIZE];
+ gboolean err = FALSE;
if (!outfp) {
g_free(path);
continue;
}
else {
- fputs(buf, outfp);
+ if(fputs(buf, outfp) == EOF) {
+ err = TRUE;
+ break;
+ }
}
g_strfreev(parts);
}
- fprintf(outfp, "%s; %s\n", type, command);
+ if (fprintf(outfp, "%s; %s\n", type, command) < 0)
+ err = TRUE;
if (fp)
fclose(fp);
- fclose(outfp);
- g_rename(outpath, path);
+ if (fclose(outfp) == EOF)
+ err = TRUE;
+
+ if (!err)
+ g_rename(outpath, path);
+
+ g_free(path);
+ g_free(outpath);
}
gint copy_dir(const gchar *src, const gchar *dst)