(__getmntent_r): Don't return with locked stream.
[kopensolaris-gnu/glibc.git] / misc / getttyent.c
index 6743ac5..e886e58 100644 (file)
@@ -71,12 +71,15 @@ getttyent()
 
        if (!tf && !setttyent())
                return (NULL);
+       flockfile (tf);
        for (;;) {
-               if (!fgets(p = line, sizeof(line), tf))
+               if (!fgets_unlocked(p = line, sizeof(line), tf)) {
+                       funlockfile (tf);
                        return (NULL);
+               }
                /* skip lines that are too big */
                if (!index(p, '\n')) {
-                       while ((c = getc(tf)) != '\n' && c != EOF)
+                       while ((c = getc_unlocked(tf)) != '\n' && c != EOF)
                                ;
                        continue;
                }
@@ -85,6 +88,7 @@ getttyent()
                if (*p && *p != '#')
                        break;
        }
+       funlockfile(tf);
 
        zapchar = 0;
        tty.ty_name = p;