real names in score files
- From: "Andrey V. Panov" <panov canopus iacp dvo ru>
- To: gnome-libs-devel gnome org
- Subject: real names in score files
- Date: Mon, 11 Mar 2002 11:50:38 +1000
The patch against libgnome-2.0 is created making available to save real users
names in gnome-score files. Analogous patch was included in the latest gnome
1.4 libraries.
--
Andrey V. Panov
panov /AT/ iacp.dvo.ru
http://canopus.iacp.dvo.ru/~panov/
--- gnome-score.c Sun Jan 27 01:43:22 2002
+++ gnome-score.c.new Mon Mar 11 11:40:18 2002
@@ -35,7 +35,6 @@
#include <stdlib.h>
#include <string.h>
#include <glib.h>
-#include <pwd.h>
#include <locale.h>
#ifdef HAVE_SYS_FSUID_H
#ifdef HAVE_SETFSGID
@@ -119,7 +118,7 @@
{
FILE *infile;
FILE *outfile;
- gchar buf[512], name[512];
+ gchar buf[512], *buf2;
GList *scores = NULL, *anode;
gchar *game_score_file;
gfloat ascore;
@@ -142,12 +141,22 @@
while (g_ascii_isspace (buf[i]))
buf[i--] = '\0';
- if(sscanf(buf, "%f %ld %s", &ascore, <ime, name) != 3)
- break;
+ {
+ char *tokp;
+
+ if((buf2 = strtok_r (buf, " ", &tokp)) == NULL)
+ break;
+ ascore = atof (buf2);
+ if((buf2 = strtok_r (NULL, " ", &tokp)) == NULL)
+ break;
+ ltime = atoi (buf2);
+ if((buf2 = strtok_r (NULL, "\n", &tokp)) == NULL)
+ break;
+ }
anitem = g_new(struct ascore_t, 1);
anitem->score = ascore;
- anitem->username = g_strdup (name);
+ anitem->username = g_strdup (buf2);
anitem->scoretime = (time_t)ltime;
scores = g_list_append (scores, (gpointer) anitem);
}
@@ -219,7 +228,7 @@
{
struct command cmd;
gchar *level;
- struct passwd *pwd;
+ gchar *realname;
gint retval;
#ifdef HAVE_SETFSGID
gid_t gid;
@@ -228,7 +237,9 @@
setgid (getgid ());
setfsgid (gid);
#endif
- pwd = getpwuid (getuid ());
+ realname = g_strdup (g_get_real_name ());
+ if (strlen (realname) == 0)
+ realname = g_strdup (g_get_user_name ());
while (read (STDIN_FILENO, &cmd, sizeof cmd) == sizeof(cmd))
{
@@ -239,13 +250,15 @@
g_free(level);
level = NULL;
}
- retval = log_score (defgamename, level, pwd->pw_name, cmd.score,
+ retval = log_score (defgamename, level, realname, cmd.score,
cmd.ordering);
if (write(STDOUT_FILENO, &retval, sizeof retval) != sizeof retval)
return EXIT_FAILURE;
if (level)
g_free(level);
}
+ if (realname)
+ g_free (realname);
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]