Open file descriptors thread-safely on Unix and don't leak them

::open directly is not thread-safe. You need to pass O_CLOEXEC if the OS
supports it. That's the only thread-safe way to open files. qt_safe_open
does that for you.

This patch also implicitly makes all serial devices be opened with
CLOEXEC on all systems, which prevents the file descriptors from leaking
to child processes.

Change-Id: I83a2657fa8d9ccca1b42182bcd83416091066045
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Protect against EINTR in Unix non-atomic I/O calls

read(), write() and close() may return EINTR, indicating the system call
should be restarted. The qt_safe_xxx versions of those functions do it.

Change-Id: Ifef3b98131a7e24a5defea3e3af9345a505ad733
Reviewed-by: Laszlo Papp <lpapp@kde.org>