sgetspent.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * sgetspent.c
  4. * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the Free
  18. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. */
  21. #include <features.h>
  22. #include <errno.h>
  23. #include <stdio.h>
  24. #include "config.h"
  25. #ifdef __UCLIBC_HAS_THREADS__
  26. #include <pthread.h>
  27. static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
  28. # define LOCK pthread_mutex_lock(&mylock)
  29. # define UNLOCK pthread_mutex_unlock(&mylock);
  30. #else
  31. # define LOCK
  32. # define UNLOCK
  33. #endif
  34. int sgetspent_r (const char *string, struct spwd *spwd,
  35. char *buff, size_t buflen, struct spwd **result)
  36. {
  37. int ret;
  38. *result = NULL;
  39. ret = __sgetspent_r(string, spwd, buff, buflen);
  40. *result = spwd;
  41. return ret;
  42. }
  43. struct spwd *sgetspent(const char *string)
  44. {
  45. int ret;
  46. static char line_buff[PWD_BUFFER_SIZE];
  47. static struct spwd spwd;
  48. struct spwd *result;
  49. LOCK;
  50. if ((ret = sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result)) == 0) {
  51. UNLOCK;
  52. return &spwd;
  53. }
  54. __set_errno(ret);
  55. UNLOCK;
  56. return NULL;
  57. }