#include <stdlib.h>
#include <pwd.h>
#include <string.h>
#include <sys/stat.h>
#include <gtk/gtk.h>
#include "gh-datastore.h"
#include "gh-main-window.h"

char *
data_dir_path ()
{
  uid_t uid = getuid ();
  struct passwd *pw = getpwuid (uid);

  char *home_dir = pw->pw_dir;
  char *data_dir = "/.ghighlighter-c";

  int length = strlen (home_dir);
  length = length + strlen (data_dir);

  char *result = malloc (length + sizeof (char));
  strcat (result, home_dir);
  strcat (result, data_dir);

  return result;
}

void
setup_environment (char *data_dir)
{
  mkdir (data_dir, 0755);
}

int
main (int argc, char *argv[])
{
  char *data_dir = data_dir_path ();
  setup_environment (data_dir);
  sqlite3 *db = gh_datastore_open_db (data_dir);
  free (data_dir);

  GtkWidget *window;

  gtk_init (&argc, &argv);

  window = gh_main_window_create ();
  gtk_widget_show_all (window);

  gtk_main ();

  sqlite3_close (db);

  return 0;
}

#include <stdlib.h>
#include <pwd.h>
#include <string.h>
#include <sys/stat.h>
#include <gtk/gtk.h>
#include "gh-datastore.h"
#include "gh-main-window.h"

char *
data_dir_path ()
{
  uid_t uid = getuid ();
  struct passwd *pw = getpwuid (uid);

  char *home_dir = pw->pw_dir;
  char *data_dir = "/.ghighlighter-c";

  int length = strlen (home_dir);
  length = length + strlen (data_dir);

  char *result = malloc (length + sizeof (char));
  result[0] = '\0';
  strcat (result, home_dir);
  strcat (result, data_dir);

  return result;
}

void
setup_environment (char *data_dir)
{
  mkdir (data_dir, 0755);
}

int
main (int argc, char *argv[])
{
  char *data_dir = data_dir_path ();
  setup_environment (data_dir);
  sqlite3 *db = gh_datastore_open_db (data_dir);
  free (data_dir);

  GtkWidget *window;

  gtk_init (&argc, &argv);

  window = gh_main_window_create ();
  gtk_widget_show_all (window);

  gtk_main ();

  sqlite3_close (db);

  return 0;
}

Set null byte in allocated data dir path
Set null byte in allocated data dir path
