X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/ec3b5374a7e1581685becbe60b09a40f2bc446f6..63807d4757d1c2ab6e4e0c5ec537316fcb324436:/lib-src/update-game-score.c diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 76483c371f..94de662e58 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -1,6 +1,6 @@ /* update-game-score.c --- Update a score file -Copyright (C) 2002-2011 Free Software Foundation, Inc. +Copyright (C) 2002-2012 Free Software Foundation, Inc. Author: Colin Walters @@ -35,12 +35,9 @@ along with GNU Emacs. If not, see . */ #include #include -#ifdef HAVE_STRING_H +#include #include -#endif -#ifdef HAVE_STDLIB_H #include -#endif #include #include #include @@ -48,16 +45,8 @@ along with GNU Emacs. If not, see . */ #ifdef HAVE_FCNTL_H #include #endif -#ifdef STDC_HEADERS -#include -#endif #include - -/* Needed for SunOS4, for instance. */ -extern char *optarg; -extern int optind, opterr; - -static int usage (int err) NO_RETURN; +#include #define MAX_ATTEMPTS 5 #define MAX_SCORES 200 @@ -68,7 +57,7 @@ static int usage (int err) NO_RETURN; #define difftime(t1, t0) (double)((t1) - (t0)) #endif -static int +static _Noreturn void usage (int err) { fprintf (stdout, "Usage: update-game-score [-m MAX] [-r] [-d DIR] game/scorefile SCORE DATA\n"); @@ -98,17 +87,13 @@ static void sort_scores (struct score_entry *scores, int count, int reverse); static int write_scores (const char *filename, const struct score_entry *scores, int count); -static void lose (const char *msg) NO_RETURN; - -static void +static _Noreturn void lose (const char *msg) { fprintf (stderr, "%s\n", msg); exit (EXIT_FAILURE); } -static void lose_syserr (const char *msg) NO_RETURN; - /* Taken from sysdep.c. */ #ifndef HAVE_STRERROR #ifndef WINDOWSNT @@ -125,7 +110,7 @@ strerror (int errnum) #endif /* not WINDOWSNT */ #endif /* ! HAVE_STRERROR */ -static void +static _Noreturn void lose_syserr (const char *msg) { fprintf (stderr, "%s: %s\n", msg, strerror (errno)); @@ -135,19 +120,13 @@ lose_syserr (const char *msg) static char * get_user_id (void) { - char *name; struct passwd *buf = getpwuid (getuid ()); if (!buf) { - int count = 1; - int uid = (int) getuid (); - int tuid = uid; - while (tuid /= 10) - count++; - name = malloc (count+1); - if (!name) - return NULL; - sprintf (name, "%d", uid); + long uid = getuid (); + char *name = malloc (sizeof uid * CHAR_BIT / 3 + 1); + if (name) + sprintf (name, "%ld", uid); return name; } return buf->pw_name; @@ -358,7 +337,7 @@ read_scores (const char *filename, struct score_entry **scores, int *count) return -1; while ((readval = read_score (f, &ret[scorecount])) == 0) { - /* We encoutered an error */ + /* We encountered an error. */ if (readval < 0) return -1; scorecount++;