scroll_tok = g_idle_add((GSourceFunc)activity_scroll_to_bottom,
ud);
}
+ if (ud->activity_log != NULL)
+ {
#if defined(_WIN32)
- gsize one = 1;
- utf8_text[length-1] = '\r';
+ gsize one = 1;
+ utf8_text[length-1] = '\r';
#endif
- g_io_channel_write_chars (ud->activity_log, utf8_text,
- length, &outlength, NULL);
+ g_io_channel_write_chars (ud->activity_log, utf8_text,
+ length, &outlength, NULL);
#if defined(_WIN32)
- g_io_channel_write_chars (ud->activity_log, "\n",
- one, &one, NULL);
+ g_io_channel_write_chars (ud->activity_log, "\n",
+ one, &one, NULL);
#endif
- g_io_channel_flush(ud->activity_log, NULL);
+ g_io_channel_flush(ud->activity_log, NULL);
+ }
if (ud->job_activity_log)
{
g_io_channel_write_chars (ud->job_activity_log, utf8_text,
g_free(str);
g_free(path);
g_free(config);
- // Set encoding to raw.
- g_io_channel_set_encoding(ud->activity_log, NULL, NULL);
+ if (ud->activity_log != NULL)
+ {
+ // Set encoding to raw.
+ g_io_channel_set_encoding(ud->activity_log, NULL, NULL);
+ }
// redirect stderr to the writer end of the pipe
#if defined(_WIN32)
}
}
-gchar*
+gchar *
ghb_get_user_config_dir(gchar *subdir)
{
- const gchar *dir;
- gchar *config;
+ const gchar * dir, * ghb = "ghb";
+ gchar * config;
if (override_user_config_dir != NULL)
{
{
dir = g_get_user_config_dir();
}
- if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
+ if (dir == NULL || !g_file_test(dir, G_FILE_TEST_IS_DIR))
{
- dir = g_get_home_dir();
- config = g_strdup_printf ("%s/.ghb", dir);
- if (!g_file_test(config, G_FILE_TEST_IS_DIR))
- g_mkdir (config, 0755);
+ dir = g_get_home_dir();
+ ghb = ".ghb";
}
- else
+ if (dir == NULL || !g_file_test(dir, G_FILE_TEST_IS_DIR))
{
- config = g_strdup_printf ("%s/ghb", dir);
- if (!g_file_test(config, G_FILE_TEST_IS_DIR))
- g_mkdir (config, 0755);
+ // Last ditch, use CWD
+ dir = "./";
+ ghb = ".ghb";
}
+ config = g_strdup_printf("%s/%s", dir, ghb);
+ if (!g_file_test(config, G_FILE_TEST_IS_DIR))
+ g_mkdir (config, 0755);
if (subdir)
{
gchar **split;
path = g_strdup_printf ("%s/ghb.pid.%d", config, pid);
fp = g_fopen(path, "w");
- fprintf(fp, "%d\n", pid);
- fclose(fp);
+ if (fp != NULL)
+ {
+ fprintf(fp, "%d\n", pid);
+ fclose(fp);
+ }
fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
- lockf(fd, F_TLOCK, 0);
+ if (fd >= 0)
+ {
+ lockf(fd, F_TLOCK, 0);
+ }
g_free(config);
g_free(path);