open_standard_streams.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @file open_standard_streams.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but 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 along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef BADVPN_OPEN_STANDARD_STREAMS_H
  23. #define BADVPN_OPEN_STANDARD_STREAMS_H
  24. #ifndef BADVPN_USE_WINAPI
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <fcntl.h>
  28. #include <unistd.h>
  29. #endif
  30. static void open_standard_streams (void)
  31. {
  32. #ifndef BADVPN_USE_WINAPI
  33. int fd;
  34. do {
  35. fd = open("/dev/null", O_RDWR);
  36. if (fd > 2) {
  37. close(fd);
  38. }
  39. } while (fd >= 0 && fd <= 2);
  40. #endif
  41. }
  42. #endif