From c9b8f7fd3f088a2a71c9e09169bfe490d933b657 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Thu, 23 Apr 2009 18:20:28 +0000 Subject: [PATCH] putsgent implementation. --- gshadow/putsgent.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 gshadow/putsgent.c diff --git a/gshadow/putsgent.c b/gshadow/putsgent.c new file mode 100644 index 0000000000..938a71334c --- /dev/null +++ b/gshadow/putsgent.c @@ -0,0 +1,71 @@ +/* Copyright (C) 2009 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + 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. */ + +#include +#include +#include + +#define _S(x) x ? x : "" + + +/* Write an entry to the given stream. + This must know the format of the group file. */ +int +putsgent (const struct sgrp *g, FILE *stream) +{ + int errors = 0; + + _IO_flockfile (stream); + + if (fprintf (stream, "%s:%s:", g->sg_namp, _S (g->sg_passwd)) < 0) + ++errors; + + bool first = true; + char **sp = g->sg_adm; + if (sp != NULL) + while (*sp != NULL) + { + if (fprintf (stream, "%s%s", first ? "" : ",", *sp++) < 0) + { + ++errors; + break; + } + first = false; + } + if (putc_unlocked (':', stream) == EOF) + ++errors; + + first = true; + sp = g->sg_mem; + if (sp != NULL) + while (*sp != NULL) + { + if (fprintf (stream, "%s%s", first ? "" : ",", *sp++) < 0) + { + ++errors; + break; + } + first = false; + } + if (putc_unlocked ('\n', stream) == EOF) + ++errors; + + _IO_funlockfile (stream); + + return errors ? -1 : 0; +} -- 2.11.4.GIT