-read_utmp (filename, n_entries, utmp_buf)
- const char *filename;
- int *n_entries;
- STRUCT_UTMP **utmp_buf;
+read_utmp (const char *filename, size_t *n_entries, STRUCT_UTMP **utmp_buf)
+{
+ size_t n_read;
+ size_t n_alloc = 4;
+ STRUCT_UTMP *utmp = xmalloc (n_alloc * sizeof *utmp);
+ STRUCT_UTMP *u;
+
+ /* 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)
+ {
+ if (n_read == n_alloc)
+ {
+ utmp = xnrealloc (utmp, n_alloc, 2 * sizeof *utmp);
+ n_alloc *= 2;
+ }
+ ++n_read;
+ utmp[n_read - 1] = *u;
+ }
+
+ END_UTMP_ENT ();
+
+ *n_entries = n_read;
+ *utmp_buf = utmp;
+
+ return 0;
+}
+
+#else
+
+int
+read_utmp (const char *filename, size_t *n_entries, STRUCT_UTMP **utmp_buf)