]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
natSystem.cc (getpwuid_adaptor): New overloaded function that detects the signature...
authorAlexandre Oliva <oliva@gcc.gnu.org>
Sat, 21 Aug 1999 11:56:21 +0000 (11:56 +0000)
committerAlexandre Oliva <oliva@gcc.gnu.org>
Sat, 21 Aug 1999 11:56:21 +0000 (11:56 +0000)
* 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.

From-SVN: r28789

libjava/ChangeLog
libjava/java/lang/natSystem.cc
libjava/java/util/natDate.cc

index 6e768341a029bba58f82f0aaa23b26919f10c9c8..c2af3ddd559177553159e7ca4ed8302fe023173c 100644 (file)
@@ -1,3 +1,16 @@
+1999-08-21  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.
+
+Mon Aug  9 18:33:38 1999  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>
+
+       * configure.in (sched_yield): Try librt first, then libposix4.
+       Add -lrt, -lposix4 to THREADSPEC.
+
 1999-08-06  Tom Tromey  <tromey@cygnus.com>
 
        * configure: Rebuilt.
index b1effafd5bfa2da221a3377a54e0f2d57806e46a..71c8579f8e0740c8446ba2f5b4b84f320fec36c5 100644 (file)
@@ -231,6 +231,34 @@ java::lang::System::identityHashCode (jobject obj)
 #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 @@ java::lang::System::init_properties (void)
 
   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 27f91f6fa190f72c88629c12bc64c37547d402a7..799e6e05a32c9760f0d77ad1c532390054da39c9 100644 (file)
@@ -1,45 +1,23 @@
-/* Copyright (C) 1998, 1999  Cygnus Solutions
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-
-// We want to make sure to pick up the POSIX ctime_r.  Some systems,
-// such as Solaris 2.6, have their own version as well.
-#ifdef HAVE_CTIME_R
-#define _POSIX_PTHREAD_SEMANTICS
-#endif
-
-#include <cni.h>
-#include <java/util/Date.h>
-#include <java/lang/String.h>
-
-#include <time.h>
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-#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);
+}
 
-jstring
-java::util::Date::toString()
+/* 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])
 {
-#ifdef HAVE_CTIME_R
-  time_t t = millis / 1000;
-  char buf[30];
-  return JvNewStringLatin1 (ctime_r (&t, buf));
-#elif defined (HAVE_CTIME)
-  // FIXME: this isn't thread-safe.
-  time_t t = millis / 1000;
-  return JvNewStringLatin1 (ctime (&t));
-#else
-  return NULL;
-#endif
+  return ctime_r(clock, buf, buflen);
 }
+#endif
+
+  return JvNewStringLatin1 (ctime_adaptor (ctime_r, &t, buf));