aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/update-game-score.c
diff options
context:
space:
mode:
authorStefan Monnier2012-03-25 16:37:21 -0400
committerStefan Monnier2012-03-25 16:37:21 -0400
commit699c782b7668c44d0fa4446331b0590a6d5dac82 (patch)
tree5dcce364741d0761920a3d274b0fc8aba4103d45 /lib-src/update-game-score.c
parent98fb480ee31bf74cf554044f60f21df16566dd7f (diff)
parente99a9b8bdccadded1f6fae88ee7a2a93dfd4eacf (diff)
downloademacs-pending.tar.gz
emacs-pending.zip
Merge from trunkpending
Diffstat (limited to 'lib-src/update-game-score.c')
-rw-r--r--lib-src/update-game-score.c31
1 files changed, 9 insertions, 22 deletions
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c
index e95e2ce259d..a32bd6d8d78 100644
--- a/lib-src/update-game-score.c
+++ b/lib-src/update-game-score.c
@@ -1,6 +1,6 @@
1/* update-game-score.c --- Update a score file 1/* update-game-score.c --- Update a score file
2 2
3Copyright (C) 2002-2011 Free Software Foundation, Inc. 3Copyright (C) 2002-2012 Free Software Foundation, Inc.
4 4
5Author: Colin Walters <walters@debian.org> 5Author: Colin Walters <walters@debian.org>
6 6
@@ -35,12 +35,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
35 35
36#include <unistd.h> 36#include <unistd.h>
37#include <errno.h> 37#include <errno.h>
38#ifdef HAVE_STRING_H 38#include <limits.h>
39#include <string.h> 39#include <string.h>
40#endif
41#ifdef HAVE_STDLIB_H
42#include <stdlib.h> 40#include <stdlib.h>
43#endif
44#include <stdio.h> 41#include <stdio.h>
45#include <time.h> 42#include <time.h>
46#include <pwd.h> 43#include <pwd.h>
@@ -48,9 +45,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
48#ifdef HAVE_FCNTL_H 45#ifdef HAVE_FCNTL_H
49#include <fcntl.h> 46#include <fcntl.h>
50#endif 47#endif
51#ifdef STDC_HEADERS
52#include <stdarg.h>
53#endif
54#include <sys/stat.h> 48#include <sys/stat.h>
55 49
56/* Needed for SunOS4, for instance. */ 50/* Needed for SunOS4, for instance. */
@@ -71,7 +65,7 @@ static int usage (int err) NO_RETURN;
71static int 65static int
72usage (int err) 66usage (int err)
73{ 67{
74 fprintf (stdout, "Usage: update-game-score [-m MAX ] [ -r ] game/scorefile SCORE DATA\n"); 68 fprintf (stdout, "Usage: update-game-score [-m MAX] [-r] [-d DIR] game/scorefile SCORE DATA\n");
75 fprintf (stdout, " update-game-score -h\n"); 69 fprintf (stdout, " update-game-score -h\n");
76 fprintf (stdout, " -h\t\tDisplay this help.\n"); 70 fprintf (stdout, " -h\t\tDisplay this help.\n");
77 fprintf (stdout, " -m MAX\t\tLimit the maximum number of scores to MAX.\n"); 71 fprintf (stdout, " -m MAX\t\tLimit the maximum number of scores to MAX.\n");
@@ -113,8 +107,7 @@ static void lose_syserr (const char *msg) NO_RETURN;
113#ifndef HAVE_STRERROR 107#ifndef HAVE_STRERROR
114#ifndef WINDOWSNT 108#ifndef WINDOWSNT
115char * 109char *
116strerror (errnum) 110strerror (int errnum)
117 int errnum;
118{ 111{
119 extern char *sys_errlist[]; 112 extern char *sys_errlist[];
120 extern int sys_nerr; 113 extern int sys_nerr;
@@ -136,19 +129,13 @@ lose_syserr (const char *msg)
136static char * 129static char *
137get_user_id (void) 130get_user_id (void)
138{ 131{
139 char *name;
140 struct passwd *buf = getpwuid (getuid ()); 132 struct passwd *buf = getpwuid (getuid ());
141 if (!buf) 133 if (!buf)
142 { 134 {
143 int count = 1; 135 long uid = getuid ();
144 int uid = (int) getuid (); 136 char *name = malloc (sizeof uid * CHAR_BIT / 3 + 1);
145 int tuid = uid; 137 if (name)
146 while (tuid /= 10) 138 sprintf (name, "%ld", uid);
147 count++;
148 name = malloc (count+1);
149 if (!name)
150 return NULL;
151 sprintf (name, "%d", uid);
152 return name; 139 return name;
153 } 140 }
154 return buf->pw_name; 141 return buf->pw_name;
@@ -359,7 +346,7 @@ read_scores (const char *filename, struct score_entry **scores, int *count)
359 return -1; 346 return -1;
360 while ((readval = read_score (f, &ret[scorecount])) == 0) 347 while ((readval = read_score (f, &ret[scorecount])) == 0)
361 { 348 {
362 /* We encoutered an error */ 349 /* We encountered an error. */
363 if (readval < 0) 350 if (readval < 0)
364 return -1; 351 return -1;
365 scorecount++; 352 scorecount++;