#include "prefs.h"
#include "utils.h"
+/*!
+ *\brief Open preferences file for reading
+ *
+ *\param path Filename with path of preferences file to read
+ *
+ *\return PrefFile * preferences file struct
+ */
PrefFile *prefs_read_open(const gchar *path)
{
PrefFile *pfile;
return pfile;
}
+/*!
+ *\brief Open preferences file for writing
+ * Prefs are written to a temp file: Call prefs_write_close()
+ * to rename this to the final filename
+ *
+ *\param path Filename with path of preferences file to write
+ *
+ *\return PrefFile * preferences file struct
+ */
PrefFile *prefs_write_open(const gchar *path)
{
PrefFile *pfile;
return pfile;
}
+/*!
+ *\brief Close and free preferences file
+ * Creates final file from temp, creates backup
+ *
+ *\param pfile Preferences file struct
+ *
+ *\return 0 on success, -1 on failure
+ */
+#define PREFS_FILE_FREE() \
+{ \
+ if (path) g_free(path); \
+ if (tmppath) g_free(tmppath); \
+ if (bakpath) g_free(bakpath); \
+ if (pfile) g_free(pfile); \
+}
gint prefs_file_close(PrefFile *pfile)
{
FILE *fp, *orig_fp;
fp = pfile->fp;
orig_fp = pfile->orig_fp;
path = pfile->path;
- g_free(pfile);
if (!pfile->writing) {
fclose(fp);
+ g_free(pfile);
+ g_free(path);
return 0;
}
return -1;
}
+ g_free(pfile);
g_free(path);
g_free(tmppath);
g_free(bakpath);
return 0;
}
+#undef PREFS_FILE_FREE
+/*!
+ *\brief Close and free preferences file, delete temp file
+ *
+ *\param pfile Preferences file struct
+ */
gint prefs_file_close_revert(PrefFile *pfile)
{
gchar *tmppath;
return 0;
}
+/*!
+ *\brief Check if "path" is a file and readonly
+ */
gboolean prefs_is_readonly(const gchar * path)
{
if (path == NULL)
return (access(path, W_OK) != 0 && access(path, F_OK) == 0);
}
+/*!
+ *\brief Check if "rcfile" is in rcdir, a file and readonly
+ */
gboolean prefs_rc_is_readonly(const gchar * rcfile)
{
gboolean result;
return result;
}
+/*!
+ *\brief Selects current section in preferences file
+ * Creates section if file is written
+ *
+ *\param pfile Preferences file struct
+ *
+ *\return 0 on success, -1 on failure
+ */
gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
{
gchar *block_label;