Correctly handle missing initgroups database
[platform/upstream/glibc.git] / grp / putgrent.c
index cb9b6b1..6d7dce9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 96, 98, 99, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,96,98,99,2000,2005,2011 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
 #include <stdio.h>
 #include <grp.h>
 
-#ifdef USE_IN_LIBIO
-# define flockfile(s) _IO_flockfile (s)
-# define funlockfile(s) _IO_funlockfile (s)
-#endif
+#define flockfile(s) _IO_flockfile (s)
+#define funlockfile(s) _IO_funlockfile (s)
 
 #define _S(x)  x ? x : ""
 
@@ -44,8 +42,13 @@ putgrent (gr, stream)
 
   flockfile (stream);
 
-  retval = fprintf (stream, "%s:%s:%u:",
-                   gr->gr_name, _S (gr->gr_passwd), gr->gr_gid);
+  if (gr->gr_name[0] == '+' || gr->gr_name[0] == '-')
+    retval = fprintf (stream, "%s:%s::",
+                     gr->gr_name, _S (gr->gr_passwd));
+  else
+    retval = fprintf (stream, "%s:%s:%lu:",
+                     gr->gr_name, _S (gr->gr_passwd),
+                     (unsigned long int) gr->gr_gid);
   if (__builtin_expect (retval, 0) < 0)
     {
       funlockfile (stream);