$OpenBSD: patch-hotspot_src_os_bsd_vm_perfMemory_bsd_cpp,v 1.1 2008/06/28 12:34:57 kurt Exp $
--- hotspot/src/os/bsd/vm/perfMemory_bsd.cpp.orig	Thu Jun 26 14:46:58 2008
+++ hotspot/src/os/bsd/vm/perfMemory_bsd.cpp	Thu Jun 26 15:15:28 2008
@@ -223,8 +223,6 @@ static bool is_directory_secure(const char* path) {
 //
 static char* get_user_name(uid_t uid) {
 
-#if bsd_not_yet
-
   struct passwd pwent;
 
   // determine the max pwbuf size from sysconf, and hardcode
@@ -236,9 +234,16 @@ static char* get_user_name(uid_t uid) {
 
   char* pwbuf = NEW_C_HEAP_ARRAY(char, bufsize);
 
+#ifdef _ALLBSD_SOURCE
+  struct passwd* p = NULL;
+  int ret = getpwuid_r(uid, &pwent, pwbuf, (size_t)bufsize, &p);
+
+  if (ret != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
+#else
   struct passwd* p = getpwuid_r(uid, &pwent, pwbuf, (int)bufsize);
 
   if (p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
+#endif
     if (PrintMiscellaneous && Verbose) {
       if (p == NULL) {
         warning("Could not retrieve passwd entry: %s\n",
@@ -260,26 +265,6 @@ static char* get_user_name(uid_t uid) {
   FREE_C_HEAP_ARRAY(char, pwbuf);
   return user_name;
 
-#else
-
-  struct passwd* p = getpwuid(uid);
-    if (PrintMiscellaneous && Verbose) {
-      if (p == NULL) {
-        jio_fprintf(stderr, "Could not retrieve passwd entry: %s\n",
-                            strerror(errno));
-      }
-      else {
-        jio_fprintf(stderr, "Could not determine user name: %s\n",
-                             p->pw_name == NULL ? "pw_name = NULL" :
-                                                  "pw_name zero length");
-      }
-    }
-
-   char* user_name = NEW_C_HEAP_ARRAY(char, strlen(p->pw_name) + 1);
-   strcpy(user_name, p->pw_name);
-   return user_name;
-
-#endif
 }
 
 // return the name of the user that owns the process identified by vmid.
