Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#13012) move MAX_LEN_NAME into fc_types
Home

[Freeciv-Dev] (PR#13012) move MAX_LEN_NAME into fc_types

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13012) move MAX_LEN_NAME into fc_types
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 9 May 2005 11:16:22 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13012 >

This patch moves MAX_LEN_NAME out of utility/ and into fc_types.h.  The
one user of this value in utility/, user_username, is changed so it
doesn't need this value (making it more generally useful).

-jason

Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.223
diff -u -r1.223 civclient.c
--- client/civclient.c  5 May 2005 19:22:24 -0000       1.223
+++ client/civclient.c  9 May 2005 18:12:31 -0000
@@ -290,7 +290,7 @@
 
   /* after log_init: */
 
-  sz_strlcpy(default_user_name, user_username());
+  (void)user_username(default_user_name, MAX_LEN_NAME);
   if (!is_valid_username(default_user_name)) {
     char buf[sizeof(default_user_name)];
 
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.24
diff -u -r1.24 fc_types.h
--- common/fc_types.h   5 May 2005 18:32:49 -0000       1.24
+++ common/fc_types.h   9 May 2005 18:12:31 -0000
@@ -36,6 +36,7 @@
 #define MAX_VET_LEVELS 10
 
 /* Changing these will probably break network compatability. */
+#define MAX_LEN_NAME     32
 #define MAX_LEN_DEMOGRAPHY 16
 #define MAX_LEN_ALLOW_TAKE 16
 #define MAX_ID_LEN 33
Index: utility/shared.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/shared.c,v
retrieving revision 1.130
diff -u -r1.130 shared.c
--- utility/shared.c    13 Apr 2005 02:21:51 -0000      1.130
+++ utility/shared.c    9 May 2005 18:12:32 -0000
@@ -726,30 +726,23 @@
   Gets value once, and then caches result.
   Note the caller should not mess with returned string.
 ***************************************************************************/
-const char *user_username(void)
+char *user_username(char *buf, size_t bufsz)
 {
-  static char username[MAX_LEN_NAME];
-
   /* This function uses a number of different methods to try to find a
-   * username.  This username then has to be truncated to MAX_LEN_NAME
+   * username.  This username then has to be truncated to bufsz
    * characters (including terminator) and checked for sanity.  Note that
    * truncating a sane name can leave you with an insane name under some
    * charsets. */
 
-  if (username[0] != '\0') {
-    /* Username is already known; just return it. */
-    return username;
-  }
-
   /* If the environment variable $USER is present and sane, use it. */
   {
     char *env = getenv("USER");
 
     if (env) {
-      sz_strlcpy(username, env);
-      if (is_ascii_name(username)) {
-       freelog(LOG_VERBOSE, "USER username is %s", username);
-       return username;
+      mystrlcpy(buf, env, bufsz);
+      if (is_ascii_name(buf)) {
+       freelog(LOG_VERBOSE, "USER username is %s", buf);
+       return buf;
       }
     }
   }
@@ -761,10 +754,10 @@
     struct passwd *pwent = getpwuid(getuid());
 
     if (pwent) {
-      sz_strlcpy(username, pwent->pw_name);
-      if (is_ascii_name(username)) {
-       freelog(LOG_VERBOSE, "getpwuid username is %s", username);
-       return username;
+      mystrlcpy(buf, pwent->pw_name, bufsz);
+      if (is_ascii_name(buf)) {
+       freelog(LOG_VERBOSE, "getpwuid username is %s", buf);
+       return buf;
       }
     }
   }
@@ -777,23 +770,23 @@
     DWORD length = sizeof(name);
 
     if (GetUserName(name, &length)) {
-      sz_strlcpy(username, name);
-      if (is_ascii_name(username)) {
-       freelog(LOG_VERBOSE, "GetUserName username is %s", username);
-       return username;
+      mystrlcpy(buf, name, bufsz);
+      if (is_ascii_name(bufsz)) {
+       freelog(LOG_VERBOSE, "GetUserName username is %s", buf);
+       return buf;
       }
     }
   }
 #endif
 
 #ifdef ALWAYS_ROOT
-  sz_strlcpy(username, "name");
+  mystrlcpy(buf, "name", bufsz);
 #else
-  my_snprintf(username, MAX_LEN_NAME, "name%d", (int)getuid());
+  my_snprintf(buf, bufsz, "name%d", (int)getuid());
 #endif
-  freelog(LOG_VERBOSE, "fake username is %s", username);
-  assert(is_ascii_name(username));
-  return username;
+  freelog(LOG_VERBOSE, "fake username is %s", buf);
+  assert(is_ascii_name(buf));
+  return buf;
 }
 
 /***************************************************************************
Index: utility/shared.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/shared.h,v
retrieving revision 1.144
diff -u -r1.144 shared.h
--- utility/shared.h    30 Apr 2005 20:59:50 -0000      1.144
+++ utility/shared.h    9 May 2005 18:12:32 -0000
@@ -55,7 +55,6 @@
 #define fc__attribute(x)
 #endif
 
-#define MAX_LEN_NAME     32
 #define MAX_LEN_ADDR     256   /* see also MAXHOSTNAMELEN and RFC 1123 2.1 */
 #define MAX_LEN_PATH 4095
 
@@ -225,7 +224,7 @@
 #define datafile_list_iterate_end LIST_ITERATE_END
                                                                                
 char *user_home_dir(void);
-const char *user_username(void);
+char *user_username(char *buf, size_t bufsz);
 char **datafilelist(const char *suffix);
 struct datafile_list *datafilelist_infix(const char *subpath,
                                          const char *infix, bool nodups);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13012) move MAX_LEN_NAME into fc_types, Jason Short <=