Back to index

glibc  2.9
Defines | Functions
putgrent.c File Reference
#include <errno.h>
#include <stdio.h>
#include <grp.h>

Go to the source code of this file.

Defines

#define _S(x)   x ? x : ""

Functions

int putgrent (struct group *gr, FILE *stream) const

Define Documentation

#define _S (   x)    x ? x : ""

Definition at line 28 of file putgrent.c.


Function Documentation

int putgrent ( struct group gr,
FILE stream 
) const

Definition at line 33 of file putgrent.c.

{
  int retval;

  if (__builtin_expect (gr == NULL, 0) || __builtin_expect (stream == NULL, 0))
    {
      __set_errno (EINVAL);
      return -1;
    }

  flockfile (stream);

  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);
      return -1;
    }

  if (gr->gr_mem != NULL)
    {
      int i;

      for (i = 0 ; gr->gr_mem[i] != NULL; i++)
       if (fprintf (stream, i == 0 ? "%s" : ",%s", gr->gr_mem[i]) < 0)
         {
           /* What else can we do?  */
           funlockfile (stream);
           return -1;
         }
    }

  retval = fputc_unlocked ('\n', stream);

  funlockfile (stream);

  return retval < 0 ? -1 : 0;
}

Here is the call graph for this function: