putspent.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (C) 1991, 1992, 1996, 1997, 1998 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #include <stdio.h>
  16. #include "config.h"
  17. #define _S(x) x ? x : ""
  18. /* Write an entry to the given stream.
  19. This must know the format of the password file. */
  20. int putspent (const struct spwd *p, FILE *stream)
  21. {
  22. int errors = 0;
  23. if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
  24. ++errors;
  25. if ((p->sp_lstchg != (long int) -1
  26. && fprintf (stream, "%ld:", p->sp_lstchg) < 0)
  27. || (p->sp_lstchg == (long int) -1
  28. && putc (':', stream) == EOF))
  29. ++errors;
  30. if ((p->sp_min != (long int) -1
  31. && fprintf (stream, "%ld:", p->sp_min) < 0)
  32. || (p->sp_min == (long int) -1
  33. && putc (':', stream) == EOF))
  34. ++errors;
  35. if ((p->sp_max != (long int) -1
  36. && fprintf (stream, "%ld:", p->sp_max) < 0)
  37. || (p->sp_max == (long int) -1
  38. && putc (':', stream) == EOF))
  39. ++errors;
  40. if ((p->sp_warn != (long int) -1
  41. && fprintf (stream, "%ld:", p->sp_warn) < 0)
  42. || (p->sp_warn == (long int) -1
  43. && putc (':', stream) == EOF))
  44. ++errors;
  45. if ((p->sp_inact != (long int) -1
  46. && fprintf (stream, "%ld:", p->sp_inact) < 0)
  47. || (p->sp_inact == (long int) -1
  48. && putc (':', stream) == EOF))
  49. ++errors;
  50. if ((p->sp_expire != (long int) -1
  51. && fprintf (stream, "%ld:", p->sp_expire) < 0)
  52. || (p->sp_expire == (long int) -1
  53. && putc (':', stream) == EOF))
  54. ++errors;
  55. if (p->sp_flag != ~0ul
  56. && fprintf (stream, "%ld", p->sp_flag) < 0)
  57. ++errors;
  58. if (putc ('\n', stream) == EOF)
  59. ++errors;
  60. return errors ? -1 : 0;
  61. }