putspent.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <shadow.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
  21. putspent (const struct spwd *p, FILE *stream)
  22. {
  23. int errors = 0;
  24. if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
  25. ++errors;
  26. if ((p->sp_lstchg != (long int) -1
  27. && fprintf (stream, "%ld:", p->sp_lstchg) < 0)
  28. || (p->sp_lstchg == (long int) -1
  29. && putc (':', stream) == EOF))
  30. ++errors;
  31. if ((p->sp_min != (long int) -1
  32. && fprintf (stream, "%ld:", p->sp_min) < 0)
  33. || (p->sp_min == (long int) -1
  34. && putc (':', stream) == EOF))
  35. ++errors;
  36. if ((p->sp_max != (long int) -1
  37. && fprintf (stream, "%ld:", p->sp_max) < 0)
  38. || (p->sp_max == (long int) -1
  39. && putc (':', stream) == EOF))
  40. ++errors;
  41. if ((p->sp_warn != (long int) -1
  42. && fprintf (stream, "%ld:", p->sp_warn) < 0)
  43. || (p->sp_warn == (long int) -1
  44. && putc (':', stream) == EOF))
  45. ++errors;
  46. if ((p->sp_inact != (long int) -1
  47. && fprintf (stream, "%ld:", p->sp_inact) < 0)
  48. || (p->sp_inact == (long int) -1
  49. && putc (':', stream) == EOF))
  50. ++errors;
  51. if ((p->sp_expire != (long int) -1
  52. && fprintf (stream, "%ld:", p->sp_expire) < 0)
  53. || (p->sp_expire == (long int) -1
  54. && putc (':', stream) == EOF))
  55. ++errors;
  56. if (p->sp_flag != ~0ul
  57. && fprintf (stream, "%ld", p->sp_flag) < 0)
  58. ++errors;
  59. if (putc ('\n', stream) == EOF)
  60. ++errors;
  61. return errors ? -1 : 0;
  62. }