mntent.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Utilities for reading/writing fstab, mtab, etc.
  2. Copyright (C) 1995-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <mntent.h>
  16. #include <stdlib.h>
  17. #include <libc-lock.h>
  18. /* We don't want to allocate the static buffer all the time since it
  19. is not always used (in fact, rather infrequently). Accept the
  20. extra cost of a `malloc'. */
  21. libc_freeres_ptr (static char *getmntent_buffer);
  22. /* This is the size of the buffer. This is really big. */
  23. #define BUFFER_SIZE 4096
  24. static void
  25. allocate (void)
  26. {
  27. getmntent_buffer = (char *) malloc (BUFFER_SIZE);
  28. }
  29. struct mntent *
  30. getmntent (FILE *stream)
  31. {
  32. static struct mntent m;
  33. __libc_once_define (static, once);
  34. __libc_once (once, allocate);
  35. if (getmntent_buffer == NULL)
  36. /* If no core is available we don't have a chance to run the
  37. program successfully and so returning NULL is an acceptable
  38. result. */
  39. return NULL;
  40. return __getmntent_r (stream, &m, getmntent_buffer, BUFFER_SIZE);
  41. }