diff options
Diffstat (limited to 'lib-src/update-game-score.c')
| -rw-r--r-- | lib-src/update-game-score.c | 31 |
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 | ||
| 3 | Copyright (C) 2002-2011 Free Software Foundation, Inc. | 3 | Copyright (C) 2002-2012 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | Author: Colin Walters <walters@debian.org> | 5 | Author: 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; | |||
| 71 | static int | 65 | static int |
| 72 | usage (int err) | 66 | usage (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 |
| 115 | char * | 109 | char * |
| 116 | strerror (errnum) | 110 | strerror (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) | |||
| 136 | static char * | 129 | static char * |
| 137 | get_user_id (void) | 130 | get_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++; |