-/* Read the utmp file FILENAME into UTMP_CONTENTS and return the
- number of entries it contains. */
+/* Read the utmp entries corresponding to file FILENAME into freshly-
+ malloc'd storage, set *UTMP_BUF to that pointer, set *N_ENTRIES to
+ the number of entries, and return zero. If there is any error,
+ return non-zero and don't modify the parameters. */
+
+#ifdef UTMP_NAME_FUNCTION
+
+int
+read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf)
+{
+ int n_read;
+ STRUCT_UTMP *u;
+ STRUCT_UTMP *utmp = NULL;
+
+ /* Ignore the return value for now.
+ Solaris' utmpname returns 1 upon success -- which is contrary
+ to what the GNU libc version does. In addition, older GNU libc
+ versions are actually void. */
+ UTMP_NAME_FUNCTION (filename);
+
+ SET_UTMP_ENT ();
+
+ n_read = 0;
+ while ((u = GET_UTMP_ENT ()) != NULL)
+ {
+ ++n_read;
+ utmp = (STRUCT_UTMP *) realloc (utmp, n_read * sizeof (STRUCT_UTMP));
+ if (utmp == NULL)
+ return 1;
+ utmp[n_read - 1] = *u;
+ }
+
+ END_UTMP_ENT ();
+
+ *n_entries = n_read;
+ *utmp_buf = utmp;
+
+ return 0;
+}
+
+#else