NetBSD-Bugs archive

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

Re: bin/51867: [PATCH] tests/lib/libc/sys/t_msync: various fixes in msync_sync(..)



The following reply was made to PR bin/51867; it has been noted by GNATS.

From: "Ngie Cooper (yaneurabeya)" <yaneurabeya%gmail.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: bin/51867: [PATCH] tests/lib/libc/sys/t_msync: various fixes in
 msync_sync(..)
Date: Fri, 13 Jan 2017 17:56:10 -0800

 --Apple-Mail=_00CC6283-06D7-4A47-98C6-3EAAA3A56E28
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain;
 	charset=us-ascii
 
 Patch attached.
 -Ngie
 
 --Apple-Mail=_00CC6283-06D7-4A47-98C6-3EAAA3A56E28
 Content-Disposition: attachment;
 	filename=t_msync-simplify-msync_sync-through-write-and-memset.patch
 Content-Type: application/octet-stream;
 	x-unix-mode=0644;
 	name="t_msync-simplify-msync_sync-through-write-and-memset.patch"
 Content-Transfer-Encoding: 7bit
 
 Index: lib/libc/sys/t_msync.c
 ===================================================================
 RCS file: /cvsroot/src/tests/lib/libc/sys/t_msync.c,v
 retrieving revision 1.2
 diff -u -r1.2 t_msync.c
 --- lib/libc/sys/t_msync.c	16 Mar 2012 06:15:17 -0000	1.2
 +++ lib/libc/sys/t_msync.c	13 Jan 2017 06:34:07 -0000
 @@ -52,8 +52,7 @@
  {
  	char *buf, *map = MAP_FAILED;
  	const char *str = NULL;
 -	size_t i, len;
 -	ssize_t tot;
 +	size_t len;
  	int fd, rv;
  
  	/*
 @@ -65,29 +64,17 @@
  	if (buf == NULL)
  		return NULL;
  
 -	for (i = 0; i < (size_t)page; i++)
 -		buf[i] = 'x';
 +	memset(buf, 'x', page);
  
  	fd = open(path, O_RDWR | O_CREAT, 0700);
  
  	if (fd < 0) {
 -		str = "failed to open";
 -		goto out;
 +		free(buf);
 +		return "failed to open";
  	}
  
 -	tot = 0;
 -
 -	while (tot < page) {
 -
 -		rv = write(fd, buf, sizeof(buf));
 -
 -		if (rv < 0) {
 -			str = "failed to write";
 -			goto out;
 -		}
 -
 -		tot += rv;
 -	}
 +	ATF_REQUIRE_MSG(write(fd, buf, page) != -1, "write(2) failed: %s",
 +	    strerror(errno));
  
  	map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_FILE|MAP_PRIVATE,
  	     fd, 0);
 
 --Apple-Mail=_00CC6283-06D7-4A47-98C6-3EAAA3A56E28--
 


Home | Main Index | Thread Index | Old Index