- Use glib wrappers for fopen/stat/chmod/unlink, fixes file operations for win32 where glib uses utf-8 for all file-handling

- win32: remove company name from exe headers as there's no company behind GKrellM
This commit is contained in:
Stefan Gehn 2008-10-28 19:02:04 +00:00
parent 5e176b0ed0
commit 3d405b9970
19 changed files with 82 additions and 122 deletions

View File

@ -24,6 +24,7 @@
#include "log.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -663,7 +663,7 @@ load_config(gchar *path)
//g_print("Trying to load config from file '%s'\n", path);
f = fopen(path, "r");
f = g_fopen(path, "r");
if (!f)
return;
while (fgets(buf, sizeof(buf), f))

View File

@ -1031,7 +1031,7 @@ update_net(GkrellmdMonitor *mon, gboolean first_update)
if (net_timer->up_event)
{
snprintf(buf, sizeof(buf), "/var/run/%s.pid", net_timer->name);
if (stat(buf, &st) == 0)
if (g_stat(buf, &st) == 0)
net_timer0 = st.st_mtime;
else
time(&net_timer0);

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="gkrellmd.exe" type="win32"/>
<description>GKrellM Daemon</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

View File

@ -20,7 +20,7 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "The GKrellM Developers"
VALUE "CompanyName", ""
VALUE "FileDescription", "GKrellM Daemon"
VALUE "FileVersion", "2.3.2"
VALUE "InternalName", "gkrellmd"
@ -35,10 +35,3 @@ BEGIN
VALUE "Translation", 1033, 1200
END
END
//
// Manifest resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1 RT_MANIFEST "win32-manifest.xml"

View File

@ -120,7 +120,7 @@ gkrellm_log_set_filename(const gchar* filename)
if (filename && filename[0] != '\0')
{
// Open the file to log into
s_gkrellm_logfile = fopen(filename, "at");
s_gkrellm_logfile = g_fopen(filename, "at");
// Add our callbacks to logging chain
if (s_gkrellm_logfile)
{

View File

@ -168,9 +168,9 @@ gkrellm_theme_file_exists(char *name, gchar *subdir)
path = g_strdup_printf("%s/%s_%d%s", _GK.theme_path,
name, _GK.theme_alternative, image_type[i]);
#ifdef WIN32
if (stat(path, &st) == 0 && S_ISREG(st.st_mode))
if (g_stat(path, &st) == 0 && S_ISREG(st.st_mode))
#else
if ( stat(path, &st) == 0
if ( g_stat(path, &st) == 0
&& (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
)
#endif
@ -188,9 +188,9 @@ gkrellm_theme_file_exists(char *name, gchar *subdir)
path = g_strdup_printf("%s/%s%s", _GK.theme_path, name,
image_type[i]);
#ifdef WIN32
if (stat(path, &st) == 0 && S_ISREG(st.st_mode))
if (g_stat(path, &st) == 0 && S_ISREG(st.st_mode))
#else
if ( stat(path, &st) == 0
if ( g_stat(path, &st) == 0
&& (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
)
#endif
@ -2202,7 +2202,7 @@ parse_gkrellmrc(gint alternative)
if (alternative > 0)
snprintf(lbuf, sizeof(lbuf), "_%d", alternative);
path = g_strdup_printf("%s/%s%s", _GK.theme_path, GKRELLMRC, lbuf);
if ((f = fopen(path, "r")) != NULL)
if ((f = g_fopen(path, "r")) != NULL)
{
while (fgets(buf, sizeof(buf), f))
{
@ -2311,7 +2311,7 @@ gkrellm_load_user_config(GkrellmMonitor *mon_only, gboolean monitor_values)
}
config = gkrellm_make_config_file_name(gkrellm_homedir(),
GKRELLM_USER_CONFIG);
f = fopen(config, "r");
f = g_fopen(config, "r");
g_free(config);
if (f)
@ -2432,7 +2432,7 @@ gkrellm_save_user_config(void)
GKRELLM_USER_CONFIG);
config_new = g_strconcat(config, ".new", NULL);
f = fopen(config_new, "w");
f = g_fopen(config_new, "w");
if (f == NULL)
{
g_warning(_("Cannot open config file %s for writing.\n"), config_new);
@ -2467,7 +2467,7 @@ gkrellm_save_user_config(void)
}
if ( !_GK.config_clean
&& (ff = fopen(config, "r")) != NULL
&& (ff = g_fopen(config, "r")) != NULL
)
{
gchar buf[CFG_BUFSIZE], *keyword, *ch, tmp;
@ -2516,9 +2516,9 @@ gkrellm_save_user_config(void)
fclose(f);
#if defined(WIN32)
/* windows rename() does not allow overwriting existing files! */
unlink(config);
g_unlink(config);
#endif
i = rename(config_new, config);
i = g_rename(config_new, config);
if (i != 0)
{
g_warning("Cannot rename new config file %s to %s.\n", config_new, config);
@ -2535,7 +2535,7 @@ gkrellm_save_user_config(void)
#else
mode = 0600;
#endif
chmod(config, mode);
g_chmod(config, mode);
g_free(config);
g_free(config_new);

View File

@ -1354,7 +1354,7 @@ fstab_user_permission(Mount *m)
{
struct stat my_stat;
stat(m->device, &my_stat);
g_stat(m->device, &my_stat);
if ( strstr(m->options, "user")
|| (strstr(m->options, "owner") && my_stat.st_uid == uid)
)

View File

@ -45,6 +45,7 @@
#endif
#include <gtk/gtk.h>
#include <glib/gstdio.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -1314,7 +1314,7 @@ get_theme_author(gchar *path)
if (!path || *path == '\0')
return buf;
rcfile = g_strdup_printf("%s/%s", path, GKRELLMRC);
f = fopen(rcfile, "r");
f = g_fopen(rcfile, "r");
g_free(rcfile);
if (!f)
return buf;
@ -1570,7 +1570,7 @@ gkrellm_save_theme_config(void)
path = gkrellm_make_config_file_name(gkrellm_homedir(),
GKRELLM_THEME_CONFIG);
if ((f = fopen(path, "w")) != NULL)
if ((f = g_fopen(path, "w")) != NULL)
{
fprintf(f, "%s\n", _GK.theme_path);
fprintf(f, "%d\n", _GK.theme_alternative);
@ -1602,7 +1602,7 @@ gkrellm_load_theme_config(void)
{
path = gkrellm_make_config_file_name(gkrellm_homedir(),
GKRELLM_THEME_CONFIG);
f = fopen(path, "r");
f = g_fopen(path, "r");
g_free(path);
if (f && fgets(buf, sizeof(buf), f))
{

View File

@ -1323,7 +1323,7 @@ gkrellm_inet_save_data(void)
{
in = (InetMon *) list->data;
fname = make_inet_data_fname(in);
if ((f = fopen(fname, "w")) == NULL)
if ((f = g_fopen(fname, "w")) == NULL)
continue;
fputs("minute hour yday width\n", f);
@ -1357,7 +1357,7 @@ gkrellm_inet_load_data(void)
{
in = (InetMon *) list->data;
fname = make_inet_data_fname(in);
if ((f = fopen(fname, "r")) == NULL)
if ((f = g_fopen(fname, "r")) == NULL)
{
gkrellm_reset_chart(in->chart);
draw_inet_chart(in);

View File

@ -1263,7 +1263,7 @@ mh_sequences_new_count(Mailbox *mbox)
path = g_strconcat(mbox->account->path, G_DIR_SEPARATOR_S,
".mh_sequences", NULL);
f = fopen(path, "r");
f = g_fopen(path, "r");
g_free(path);
if (!f)
return FALSE;
@ -1315,7 +1315,7 @@ sylpheed_mark_new_count(Mailbox *mbox)
for (fname = mark_file_names; *fname; fname++) {
path = g_strconcat(mbox->account->path, G_DIR_SEPARATOR_S,
*fname, NULL);
f = fopen(path, "rb");
f = g_fopen(path, "rb");
g_free(path);
if (f)
break;
@ -1551,7 +1551,7 @@ check_mbox(Mailbox *mbox)
gint is_multipart = FALSE;
gint content_len = 0;
if (stat(mbox->account->path, &s) != 0)
if (g_stat(mbox->account->path, &s) != 0)
{
mbox->mail_count = mbox->old_mail_count = mbox->new_mail_count = 0;
mbox->last_mtime = 0;
@ -1589,7 +1589,7 @@ check_mbox(Mailbox *mbox)
|| force_mail_check
)
{
if ((f = fopen(mbox->account->path, "r")) == NULL)
if ((f = g_fopen(mbox->account->path, "r")) == NULL)
{
if (_GK.debug_level & DEBUG_MAIL)
printf("check_mbox can't fopen(%s): %s\n", mbox->account->path,

View File

@ -279,7 +279,7 @@ set_or_save_position(gint save)
}
if ( !_GK.no_config
&& (_GK.x_position != x_last || _GK.y_position != y_last)
&& (f = fopen(path, "w")) != NULL
&& (f = g_fopen(path, "w")) != NULL
)
{
x_last = _GK.x_position;
@ -292,7 +292,7 @@ set_or_save_position(gint save)
}
else if (!_GK.withdrawn) /* In slit conflicts with setting position */
{
if ((f = fopen(path, "r")) != NULL)
if ((f = g_fopen(path, "r")) != NULL)
{
x = y = 0;
fscanf(f, "%d %d", &x, &y);

View File

@ -781,7 +781,7 @@ get_connect_state(void)
{
snprintf(buf, sizeof(buf),
"%s/%s", lock_directory, PPP_LOCK_FILE);
if (stat(buf, &st) == 0)
if (g_stat(buf, &st) == 0)
state = TB_STANDBY;
else
{
@ -790,7 +790,7 @@ get_connect_state(void)
*/
snprintf(buf, sizeof(buf), "%s/%s/%s",
gkrellm_homedir(), GKRELLM_DIR, PPP_LOCK_FILE);
if (stat(buf, &st) == 0)
if (g_stat(buf, &st) == 0)
state = TB_STANDBY;
}
}
@ -821,7 +821,7 @@ get_connect_time(void)
break;
case TIMER_TYPE_PPP:
snprintf(buf, sizeof(buf), "/var/run/%s.pid", timer_button_iface);
if (stat(buf, &st) == 0)
if (g_stat(buf, &st) == 0)
t = st.st_mtime;
break;
case TIMER_TYPE_IPPP:
@ -917,7 +917,7 @@ stale_pppd_files_debug(void)
gchar buf[256];
snprintf(buf, sizeof(buf), "/var/run/%s.pid", timer_button_iface);
if (stat(buf, &st) == 0 && !net_timed->up)
if (g_stat(buf, &st) == 0 && !net_timed->up)
g_print(_(" **** Stale pppd pppX.pid file detected!\n"));
}
@ -1672,7 +1672,7 @@ gkrellm_net_save_data(void)
continue;
snprintf(fname, sizeof(fname), "%s%c%s", net_data_dir,
G_DIR_SEPARATOR, net->name);
if ((f = fopen(fname, "w")) == NULL)
if ((f = g_fopen(fname, "w")) == NULL)
continue;
fprintf(f, "%d\n", NET_DATA_VERSION);
fputs("wday mday month yday year\n", f);
@ -1822,7 +1822,7 @@ load_net_data(void)
net = (NetMon *) list->data;
snprintf(fname, sizeof(fname), "%s%c%s", net_data_dir,
G_DIR_SEPARATOR, net->name);
if ((f = fopen(fname, "r")) == NULL)
if ((f = g_fopen(fname, "r")) == NULL)
continue;
fgets(buf, sizeof(buf), f);
if (sscanf(buf, "%d\n", &version) != 1)

View File

@ -1050,7 +1050,7 @@ load_plugins_placement_file(void)
gkrellm_free_glist_and_data(&plugins_place_list);
path = gkrellm_make_config_file_name(gkrellm_homedir(),
PLUGIN_PLACEMENT_FILE);
if ((f = fopen(path, "r")) != NULL)
if ((f = g_fopen(path, "r")) != NULL)
{
while ((fgets(buf, sizeof(buf), f)) != NULL)
{
@ -1077,7 +1077,7 @@ save_plugins_placement_file(void)
return;
path = gkrellm_make_config_file_name(gkrellm_homedir(),
PLUGIN_PLACEMENT_FILE);
if ((f = fopen(path, "w")) != NULL)
if ((f = g_fopen(path, "w")) != NULL)
{
for (list = plugins_list; list; list = list->next)
{
@ -1111,7 +1111,7 @@ load_plugins_enable_file(void)
gkrellm_free_glist_and_data(&plugins_enable_list);
path = gkrellm_make_config_file_name(gkrellm_homedir(),PLUGIN_ENABLE_FILE);
if ((f = fopen(path, "r")) != NULL)
if ((f = g_fopen(path, "r")) != NULL)
{
while ((fgets(buf, sizeof(buf), f)) != NULL)
{
@ -1139,7 +1139,7 @@ save_plugins_enable_file(void)
return;
path = gkrellm_make_config_file_name(gkrellm_homedir(),
PLUGIN_ENABLE_FILE);
if ((f = fopen(path, "w")) != NULL)
if ((f = g_fopen(path, "w")) != NULL)
{
for (list = plugins_list; list; list = list->next)
{

View File

@ -1724,7 +1724,7 @@ save_sensors_config(FILE *f_not_used)
return;
sprintf(buf, "%s/%s", GKRELLM_DIR, SENSOR_CONFIG_FILE);
config = gkrellm_make_config_file_name(gkrellm_homedir(), buf);
f = fopen(config, "w");
f = g_fopen(config, "w");
g_free(config);
if (!f)
return;
@ -1901,14 +1901,14 @@ read_sensors_config(void)
sprintf(buf, "%s/%s", GKRELLM_DIR, SENSOR_CONFIG_FILE);
config = gkrellm_make_config_file_name(gkrellm_homedir(), buf);
f = fopen(config, "r");
f = g_fopen(config, "r");
g_free(config);
if (!f)
{
sprintf(buf, "%s/%s", GKRELLM_DIR, SENSOR_2_1_14_CONFIG_FILE);
config = gkrellm_make_config_file_name(gkrellm_homedir(), buf);
f = fopen(config, "r");
f = g_fopen(config, "r");
g_free(config);
}
if (f)

View File

@ -216,7 +216,7 @@ gkrellm_homedir(void)
homedir = (gchar *) g_get_home_dir();
if (!homedir)
homedir = ".";
homedir = "."; // FIXME: This does not look right to me (stefan)
return homedir;
}
@ -229,11 +229,7 @@ gkrellm_make_home_subdir(gchar *subdir, gchar **path)
dir = g_build_path(G_DIR_SEPARATOR_S, gkrellm_homedir(), subdir, NULL);
if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
{
#ifdef WIN32
if (mkdir(dir) < 0)
#else
if (mkdir(dir, 0755) < 0)
#endif
if (g_mkdir(dir, 0755) < 0)
printf(_("Cannot create directory: %s\n"), dir);
else
result = TRUE;

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="gkrellm.exe" type="win32"/>
<description>GKrellM</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

View File

@ -27,7 +27,7 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "The GKrellM Developers"
VALUE "CompanyName", ""
VALUE "FileDescription", "GKrellM"
VALUE "FileVersion", "2.3.2"
VALUE "InternalName", "gkrellm"
@ -42,10 +42,3 @@ BEGIN
VALUE "Translation", 1033, 1200
END
END
//
// Manifest resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1 RT_MANIFEST "win32-manifest.xml"