-#if (!defined(BT_LOG_WRITE_CUR_LVL) && !defined(BT_LOG_WRITE_ERRNO_CUR_LVL))
-#define BT_LOG_LEVEL_UNUSED_ATTR __attribute__((unused))
-#else
-#define BT_LOG_LEVEL_UNUSED_ATTR
-#endif
-
-/*
- * Wraps read() function to handle EINTR and partial reads.
- * On success, it returns `count` received as parameter. On error, it returns a
- * value smaller than the requested `count`.
- */
-static inline
-ssize_t bt_common_read(int fd, void *buf, size_t count,
- int log_level BT_LOG_LEVEL_UNUSED_ATTR)
-{
- size_t i = 0;
- ssize_t ret;
-
- BT_ASSERT_DBG(buf);
-
- /* Never return an overflow value. */
- BT_ASSERT_DBG(count <= SSIZE_MAX);
-
- do {
- ret = read(fd, ((char *) buf) + i, count - i);
- if (ret < 0) {
- if (errno == EINTR) {
-#ifdef BT_LOG_WRITE_CUR_LVL
- BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level,
- BT_LOG_TAG,
- "read() call interrupted; retrying...");
-#endif
- /* retry operation */
- continue;
- } else {
-#ifdef BT_LOG_WRITE_ERRNO_PRINTF_CUR_LVL
- BT_LOG_WRITE_ERRNO_PRINTF_CUR_LVL(BT_LOG_ERROR,
- log_level, BT_LOG_TAG,
- "Error while reading", ": fd=%d", fd);
-#endif
- goto end;
- }
- }
- i += ret;
- BT_ASSERT_DBG(i <= count);
- } while (count - i > 0 && ret > 0);
-
-end:
- if (ret >= 0) {
- if (i == 0) {
- ret = -1;
- } else {
- ret = i;
- }
- }
-
- return ret;
-}
-