summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorjuhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73>2011-09-21 11:47:35 +0000
committerjuhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73>2011-09-21 11:47:35 +0000
commit25ead84c946e2f3b87531bd6c099f45cdbed08e6 (patch)
treef282447d0279045c9e79a3932f8d31fc72b03f27 /package
parentde7614b2c5934965c8c8603588c7fc0d6e6d6ca6 (diff)
package/maccalc: don't expect to get all data in one read
Signed-off-by: Alexander Gordeev <lasaine@lvk.cs.msu.su> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@28266 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package')
-rw-r--r--package/maccalc/src/main.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/package/maccalc/src/main.c b/package/maccalc/src/main.c
index e1e12cd96f..dcb5f55c55 100644
--- a/package/maccalc/src/main.c
+++ b/package/maccalc/src/main.c
@@ -9,6 +9,7 @@
*
*/
+#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
@@ -124,6 +125,34 @@ static int maccalc_do_mac2bin(int argc, const char *argv[])
return 0;
}
+static ssize_t read_safe(int fd, void *buf, size_t count)
+{
+ ssize_t total = 0;
+ ssize_t r;
+
+ while(count > 0) {
+ r = read(fd, buf, count);
+ if (r == 0)
+ /* EOF */
+ break;
+ if (r < 0) {
+ if (errno == EINTR)
+ /* interrupted by a signal, restart */
+ continue;
+ /* error */
+ total = -1;
+ break;
+ }
+
+ /* ok */
+ total += r;
+ count -= r;
+ buf += r;
+ }
+
+ return total;
+}
+
static int maccalc_do_bin2mac(int argc, const char *argv[])
{
unsigned char mac[MAC_ADDRESS_LEN];
@@ -134,7 +163,7 @@ static int maccalc_do_bin2mac(int argc, const char *argv[])
return ERR_INVALID;
}
- c = read(STDIN_FILENO, mac, sizeof(mac));
+ c = read_safe(STDIN_FILENO, mac, sizeof(mac));
if (c != sizeof(mac)) {
fprintf(stderr, "failed to read from stdin\n");
return ERR_IO;