This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Accepting IRIX 5.2's old-style getpwuid_r


On Aug 21, 1999, Alexandre Oliva <oliva@dcc.unicamp.br> wrote:

> function overloading to accomplish the same.  That's the only
> solution I could find to detect the type of ctime_r, anyway...

Function overloading worked beautifully.  We can even remove some
other similar tests from configure.in, since the
overload-resolution-based ones are much more reliable.

Here's the patch that fixes getpwduid_r and ctime_r on IRIX 5.2,
allowing it to build to completion.  The patch was also tested on
Solaris 2.5/sparc, 7/sparc/x86, DU4.0d and GNU/Linux
RedHat 6.0 /x86/alpha/sparc, and it certainly works any other platform
that worked before (famous last words, huh? :-), so I'm installing it
in mainline and branch.

Tell me what you think about this solution.  I myself found it quite
ugly, but it's probably worth the ugliness.

Index: libjava/ChangeLog
from  Alexandre Oliva  <oliva@dcc.unicamp.br>
	
	* java/lang/natSystem.cc (getpwuid_adaptor): New overloaded
	function that detects the signature of getpwuid_r.
	(init_properties): Use it.
	* java/util/natDate.cc (ctime_adaptor): Likewise for ctime_r.
	(toString): Use it.
	
Index: libjava/java/lang/natSystem.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natSystem.cc,v
retrieving revision 1.7.2.1
diff -u -r1.7.2.1 natSystem.cc
--- libjava/java/lang/natSystem.cc	1999/07/31 23:42:11	1.7.2.1
+++ libjava/java/lang/natSystem.cc	1999/08/21 11:50:27
@@ -231,6 +231,34 @@
 #endif
 static char *default_file_encoding = DEFAULT_FILE_ENCODING;
 
+#if HAVE_GETPWUID_R
+/* Use overload resolution to find out the signature of getpwuid_r.  */
+
+  /* This is Posix getpwuid_r.  */
+template <typename T_uid, typename T_passwd, typename T_buf, typename T_len>
+static inline int
+getpwuid_adaptor(int (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r,
+				   T_buf *buf_r, T_len len_r,
+				   T_passwd **pwd_entry_ptr),
+		 uid_t user_id, struct passwd *pwd_r,
+		 char *buf_r, size_t len_r, struct passwd **pwd_entry)
+{
+  return getpwuid_r(user_id, pwd_r, buf_r, len_r, pwd_entry);
+}
+
+/* This is used on IRIX 5.2.  */
+template <typename T_uid, typename T_passwd, typename T_buf, typename T_len>
+static inline int
+getpwuid_adaptor(T_passwd * (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r,
+					  T_buf *buf_r, T_len len_r),
+		 uid_t user_id, struct passwd *pwd_r,
+		 char *buf_r, size_t len_r, struct passwd **pwd_entry)
+{
+  *pwd_entry = getpwuid_r(user_id, pwd_r, buf_r, len_r);
+  return (*pwd_entry == NULL) ? errno : 0;
+}
+#endif
+
 void
 java::lang::System::init_properties (void)
 {
@@ -293,7 +321,8 @@
 
   while (buf_r != NULL)
     {
-      int r = getpwuid_r (user_id, &pwd_r, buf_r, len_r, &pwd_entry);
+      int r = getpwuid_adaptor
+	(getpwuid_r, user_id, &pwd_r, buf_r, len_r, &pwd_entry);
       if (r == 0)
 	break;
       else if (r != ERANGE)
Index: libjava/java/util/natDate.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/natDate.cc,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 natDate.cc
--- libjava/java/util/natDate.cc	1999/04/07 14:52:41	1.1.1.1
+++ libjava/java/util/natDate.cc	1999/08/21 11:50:27
@@ -28,13 +28,35 @@
 #include <sys/time.h>
 #endif
 
+#if HAVE_CTIME_R
+/* Use overload resolution to find out the signature of ctime_r.  */
+
+  /* This is Posix ctime_r().  */
+template <typename T_clock, typename T_buf, size_t buflen>
+static inline char *
+ctime_adaptor (char* (*ctime_r)(T_clock *clock, T_buf *buf),
+	       time_t *clock, char (&buf)[buflen])
+{
+  return ctime_r(clock, buf);
+}
+
+/* This is an old-style ctime_r, used on IRIX 5.2.  */
+template <typename T_clock, typename T_buf, typename T_buflen, size_t buflen>
+static inline char *
+ctime_adaptor (char* (*ctime_r)(T_clock *clock, T_buf *buf, T_buflen len),
+	       time_t *clock, char (&buf)[buflen])
+{
+  return ctime_r(clock, buf, buflen);
+}
+#endif
+
 jstring
 java::util::Date::toString()
 {
 #ifdef HAVE_CTIME_R
   time_t t = millis / 1000;
   char buf[30];
-  return JvNewStringLatin1 (ctime_r (&t, buf));
+  return JvNewStringLatin1 (ctime_adaptor (ctime_r, &t, buf));
 #elif defined (HAVE_CTIME)
   // FIXME: this isn't thread-safe.
   time_t t = millis / 1000;


-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]