]> code.delx.au - gnu-emacs/blobdiff - lib-src/update-game-score.c
Fix ChangeLog typos.
[gnu-emacs] / lib-src / update-game-score.c
index 76483c371ffbc573b1cb4c5c1e6222d469bd416a..e0c940510bed45a9a0a54c45f0126f450be3bb3b 100644 (file)
@@ -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 <walters@debian.org>
 
@@ -35,12 +35,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <unistd.h>
 #include <errno.h>
-#ifdef HAVE_STRING_H
+#include <limits.h>
 #include <string.h>
-#endif
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
 #include <stdio.h>
 #include <time.h>
 #include <pwd.h>
@@ -48,14 +45,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
-#ifdef STDC_HEADERS
-#include <stdarg.h>
-#endif
 #include <sys/stat.h>
-
-/* Needed for SunOS4, for instance.  */
-extern char *optarg;
-extern int optind, opterr;
+#include <getopt.h>
 
 static int usage (int err) NO_RETURN;
 
@@ -135,19 +126,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 +343,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++;