[PATCH 09/19] include/all-io: replace usleep with nanosleep

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



POSIX.1-2001 declares usleep is obsolete.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html
Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 include/all-io.h | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/include/all-io.h b/include/all-io.h
index 38a760f..ed4f879 100644
--- a/include/all-io.h
+++ b/include/all-io.h
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
+#include <time.h>
 
 static inline int write_all(int fd, const void *buf, size_t count)
 {
@@ -18,8 +19,12 @@ static inline int write_all(int fd, const void *buf, size_t count)
 				buf = (void *) ((char *) buf + tmp);
 		} else if (errno != EINTR && errno != EAGAIN)
 			return -1;
-		if (errno == EAGAIN)	/* Try later, *sigh* */
-			usleep(10000);
+		if (errno == EAGAIN) {	/* Try later, *sigh* */
+			struct timespec waittime;
+			waittime.tv_sec = 0;
+			waittime.tv_nsec = 10000000;
+			nanosleep(&waittime, NULL);
+		}
 	}
 	return 0;
 }
@@ -38,8 +43,12 @@ static inline int fwrite_all(const void *ptr, size_t size,
 				ptr = (void *) ((char *) ptr + (tmp * size));
 		} else if (errno != EINTR && errno != EAGAIN)
 			return -1;
-		if (errno == EAGAIN)	/* Try later, *sigh* */
-			usleep(10000);
+		if (errno == EAGAIN) {	/* Try later, *sigh* */
+			struct timespec waittime;
+			waittime.tv_sec = 0;
+			waittime.tv_nsec = 10000000;
+			nanosleep(&waittime, NULL);
+		}
 	}
 	return 0;
 }
-- 
1.7.12.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux