getpw.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * getpw.c - This file is part of the libc-8086/pwd package for ELKS,
  4. * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
  5. * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the Free
  19. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. */
  22. #include <sys/types.h>
  23. #include <errno.h>
  24. #include <stdio.h>
  25. #include "config.h"
  26. int getpw(uid_t uid, char *buf)
  27. {
  28. struct passwd *passwd;
  29. if (buf == NULL) {
  30. __set_errno(EINVAL);
  31. return -1;
  32. }
  33. if ((passwd = getpwuid(uid)) == NULL)
  34. return -1;
  35. if (sprintf
  36. (buf, "%s:%s:%u:%u:%s:%s:%s", passwd->pw_name, passwd->pw_passwd,
  37. passwd->pw_gid, passwd->pw_uid, passwd->pw_gecos, passwd->pw_dir,
  38. passwd->pw_shell) < 0) {
  39. __set_errno(ENOBUFS);
  40. return -1;
  41. }
  42. return 0;
  43. }