mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Holger Schurig <holgerschurig@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH] commands: fix memset command
Date: Tue, 22 Jul 2014 11:58:42 +0200	[thread overview]
Message-ID: <1406023122-498-1-git-send-email-holgerschurig@gmail.com> (raw)

Before:

  barebox:/ memset -d /dev/fb0 -l 0 10 0xdeadbeef
  write: No space left on device
  barebox:/ md -s /dev/fb0
  00000000: 0a0a0a0a 0a0a0a0a 0a0a0a0a 0a0a0a0a                ................
  ...

After:

  barebox:/ memset -d /dev/fb0 -l 0 10 0xdeadbeef
  barebox:/ md -s /dev/fb0
  00000000: deadbeef deadbeef deadbeef deadbeef                ................
  00000010: deadbeef deadbeef deadbeef deadbeef                ................
  00000020: deadbeef deadbeef 00ffffff 00ffffff                ................
  00000030: 00ffffff 00ffffff 00ffffff 00ffffff                ...............

Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
---
 commands/memset.c |   14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/commands/memset.c b/commands/memset.c
index f869306..4afe404 100644
--- a/commands/memset.c
+++ b/commands/memset.c
@@ -39,7 +39,6 @@ static int do_memset(int argc, char *argv[])
 {
 	loff_t	s, c, n;
 	int     fd;
-	char   *buf;
 	int	mode  = O_RWSIZE_1;
 	int     ret = 1;
 	char	*file = "/dev/mem";
@@ -59,28 +58,19 @@ static int do_memset(int argc, char *argv[])
 	if (fd < 0)
 		return 1;
 
-	buf = xmalloc(RW_BUF_SIZE);
-	memset(buf, c, RW_BUF_SIZE);
 
-	while (n > 0) {
-		int now;
-
-		now = min((loff_t)RW_BUF_SIZE, n);
-
-		ret = write(fd, buf, now);
+	while (c--) {
+		ret = write(fd, &n, mode >> O_RWSIZE_SHIFT);
 		if (ret < 0) {
 			perror("write");
 			ret = 1;
 			goto out;
 		}
-
-		n -= now;
 	}
 
 	ret = 0;
 out:
 	close(fd);
-	free(buf);
 
 	return ret;
 }
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2014-07-22  9:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-22  9:58 Holger Schurig [this message]
2014-07-22 20:16 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406023122-498-1-git-send-email-holgerschurig@gmail.com \
    --to=holgerschurig@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox