]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - login/getutline.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / login / getutline.c
index d1704ec31c854e4763e212a2a2ed912b980f7047..cc1a8615e722dbe6f5c50d3dc4eac5d99eba7124 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
-#include <stddef.h>            /* For NULL.  */
+#include <stdlib.h>
 #include <utmp.h>
 
 
 /* Local buffer to store the result.  */
-static struct utmp buffer;
+libc_freeres_ptr (static struct utmp *buffer);
 
 
 struct utmp *
@@ -30,9 +29,16 @@ __getutline (const struct utmp *line)
 {
   struct utmp *result;
 
-  if (__getutline_r (line, &buffer, &result) < 0)
+  if (buffer == NULL)
+    {
+      buffer = (struct utmp *) malloc (sizeof (struct utmp));
+      if (buffer == NULL)
+        return NULL;
+    }
+  if (__getutline_r (line, buffer, &result) < 0)
     return NULL;
 
   return result;
 }
+libc_hidden_def (__getutline)
 weak_alias (__getutline, getutline)