public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
Cc: vasily.isaenko@oracle.com, ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH V4 1/2] Implemented tst_fill_file function
Date: Tue, 13 Aug 2013 16:59:02 +0200	[thread overview]
Message-ID: <20130813145902.GC29233@rei> (raw)
In-Reply-To: <1376311771-30968-2-git-send-email-stanislav.kholmanskikh@oracle.com>

Hi!
> +int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount)
> +{
> +	int fd, counter;
> +	char *buf;
> +
> +	fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
> +	if (fd < 0)
> +		return -1;
> +
> +	/* Filling a memory buffer with provided pattern */
> +	buf = malloc(bs);
> +	if (buf == NULL) {
> +		close(fd);
> +
> +		return -1;
> +	}
> +
> +	for (counter = 0; counter < bs; counter++)
> +		buf[counter] = pattern;
> +
> +	/* Filling the file */
> +	for (counter = 0; counter < bcount; counter++)
> +		if (write(fd, buf, bs) != bs) {
> +			free(buf);
> +			close(fd);
> +			unlink(path);
> +
> +			return -1;
> +		}

This is minor but I've told you allready that it's preffered to add the
curly brackets ({}) around large blocks. Such as:

	for (counter = 0; counter < bcount; counter++) {
		if (...) {
			...
			...
		}
	}

> +	free(buf);
> +	if (close(fd) < 0)

Add unlink here too, just to be consistent.

> +		return -1;
> +
> +	return 0;
> +}

Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2013-08-13 14:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-24  9:29 [LTP] [PATCH] syscalls/swapon: fix for variable page size Stanislav Kholmanskikh
2013-06-24 16:23 ` chrubis
     [not found]   ` <51C932ED.6060309@oracle.com>
2013-06-25 12:48     ` chrubis
2013-07-16 14:06       ` [LTP] [PATCH V2] " Stanislav Kholmanskikh
2013-07-17 13:05         ` chrubis
2013-07-25 11:43           ` [LTP] [PATCH V3 1/2] lib/tst_fill_file.c: added tst_fill_file function Stanislav Kholmanskikh
2013-07-25 11:43           ` [LTP] [PATCH V3 2/2] syscalls/swapon: fix for variable page size Stanislav Kholmanskikh
2013-08-12 12:49           ` [LTP] [PATCH V4] " Stanislav Kholmanskikh
2013-08-12 12:49           ` [LTP] [PATCH V4 1/2] Implemented tst_fill_file function Stanislav Kholmanskikh
2013-08-13 14:59             ` chrubis [this message]
2013-08-12 12:49           ` [LTP] [PATCH V4 2/2] syscalls/swapon: fix for variable page size Stanislav Kholmanskikh
2013-08-13 15:01             ` chrubis
2013-08-14  6:01           ` [LTP] [PATCH V5 1/2] Implemented tst_fill_file function Stanislav Kholmanskikh
2013-08-14  6:01           ` [LTP] [PATCH V5 2/2] syscalls/swapon: fix for variable page size Stanislav Kholmanskikh
2013-08-14  9:57             ` chrubis

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=20130813145902.GC29233@rei \
    --to=chrubis@suse.cz \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=stanislav.kholmanskikh@oracle.com \
    --cc=vasily.isaenko@oracle.com \
    /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