diff mbox series

[5/6] util: global function to set non blocking mode

Message ID 20191208122844.11642-5-sbabic@denx.de
State Accepted
Headers show
Series [1/6] Updated mongoose to 6.16 | expand

Commit Message

Stefano Babic Dec. 8, 2019, 12:28 p.m. UTC
Add swupdate_file_setnonblocking()

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/util.c    | 17 +++++++++++++++++
 include/util.h |  1 +
 2 files changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index dc4f4af..f4aee4f 100644
--- a/core/util.c
+++ b/core/util.c
@@ -733,3 +733,20 @@  char *swupdate_time_iso8601(void)
 
 	return buf;
 }
+
+int swupdate_file_setnonblock(int fd, bool block)
+{
+	int flags;
+
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags == -1)
+		return -EFAULT;
+
+	if (block)
+		flags |= O_NONBLOCK;
+	else
+		flags &= ~O_NONBLOCK;
+
+	return !(fcntl(fd, F_SETFL, flags) == -1);
+}
+
diff --git a/include/util.h b/include/util.h
index 9f658ab..52928b8 100644
--- a/include/util.h
+++ b/include/util.h
@@ -177,6 +177,7 @@  off_t extract_next_file(int fd, int fdout, off_t start, int compressed,
 			int encrypted, unsigned char *hash);
 int openfileoutput(const char *filename);
 int mkpath(char *dir, mode_t mode);
+int swupdate_file_setnonblock(int fd, bool block);
 
 int register_notifier(notifier client);
 void notify(RECOVERY_STATUS status, int error, int level, const char *msg);