closedir.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright (C) 1991, 1993, 1995, 1996, 1998 Free Software Foundation, Inc.
  4. * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  5. *
  6. * This file is part of GNU Mes.
  7. *
  8. * GNU Mes is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * GNU Mes is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. // Taken from GNU C Library 2.2.5
  22. #include <errno.h>
  23. #include <stddef.h>
  24. #include <stdlib.h>
  25. #include <dirent.h>
  26. #include <unistd.h>
  27. #include <errno.h>
  28. #include <stddef.h>
  29. #include <stdlib.h>
  30. #include <dirent.h>
  31. #include <unistd.h>
  32. #include <dirstream.h>
  33. /* Close the directory stream DIRP.
  34. Return 0 if successful, -1 if not. */
  35. int
  36. closedir (DIR * dirp)
  37. {
  38. int filedes;
  39. if (dirp == NULL)
  40. {
  41. errno = EINVAL;
  42. return -1;
  43. }
  44. filedes = dirp->fd;
  45. free (dirp);
  46. return close (filedes);
  47. }