regex: avoid glibc deadlock during configure
[gnulib.git] / lib / ttyname_r.c
index 5b59547..2689b26 100644 (file)
@@ -1,6 +1,6 @@
 /* Determine name of a terminal.
 
-   Copyright (C) 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010-2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -32,8 +32,9 @@ ttyname_r (int fd, char *buf, size_t buflen)
   /* When ttyname_r exists, use it.  */
 #if HAVE_TTYNAME_R
   /* This code is multithread-safe.  */
-  /* On Solaris, ttyname_r always fails if buflen < 128.  So provide a buffer
-     that is large enough.  */
+  /* On Solaris, ttyname_r always fails if buflen < 128.  On OSF/1 5.1,
+     ttyname_r ignores the buffer size and assumes the buffer is large enough.
+     So provide a buffer that is large enough.  */
   char largerbuf[512];
 # if HAVE_POSIXDECL_TTYNAME_R
   int err =
@@ -44,7 +45,7 @@ ttyname_r (int fd, char *buf, size_t buflen)
     return err;
   if (buflen < sizeof (largerbuf))
     {
-      size_t namelen = strlen (largerbuf);
+      size_t namelen = strlen (largerbuf) + 1;
       if (namelen > buflen)
         return ERANGE;
       memcpy (buf, largerbuf, namelen);