Unify usage of iopl-like code by introducing get_io_perms()

Factor out portable iopl()-style code into a global function which all
programmers can use, add missing close() call.

Corresponding to flashrom svn r511.

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
diff --git a/flash.h b/flash.h
index f04e851..27b6328 100644
--- a/flash.h
+++ b/flash.h
@@ -593,6 +593,9 @@
 uint8_t internal_chip_readb(const volatile void *addr);
 uint16_t internal_chip_readw(const volatile void *addr);
 uint32_t internal_chip_readl(const volatile void *addr);
+#if defined(__FreeBSD__) || defined(__DragonFly__)
+extern int io_fd;
+#endif
 
 /* dummyflasher.c */
 int dummy_init(void);