[parted-devel] Don't use deprecated mktemp, to avoid linker warning

David Cantrell dcantrell at redhat.com
Wed Mar 7 23:22:55 CET 2007


On Wed, 2007-03-07 at 22:22 +0100, Jim Meyering wrote:
> 	* libparted/tests/common.c (_create_disk): Rewrite to
> 	use mkstemp instead.
> 
> diff --git a/libparted/tests/common.c b/libparted/tests/common.c
> index af5b983..642da23 100644
> --- a/libparted/tests/common.c
> +++ b/libparted/tests/common.c
> @@ -8,20 +8,25 @@
> 
>  char *_create_disk (const off_t size)
>  {
> -		char filename[] = "parted-test-XXXXXX";
> -		mktemp (filename);
> +		char *filename = strdup ("parted-test-XXXXXX");
> +		if (filename == NULL)
> +		  return NULL;
> +		int fd = mkstemp (filename);
> +		if (fd < 0) {
> +	free_filename:;
> +			free (filename);
> +			return NULL;
> +		}
> 
> -		FILE *disk = fopen (filename, "w");
> +		FILE *disk = fdopen (fd, "w");
>  		if (disk == NULL)
> -			/* FIXME: give a diagnostic? */
> -			return NULL;
> +			goto free_filename;
>  		off_t total_size = size * 1024 * 1024;	/* Mb */
> 
> -		fseek (disk, total_size, SEEK_SET);
> -		fwrite ("", sizeof (char), 1, disk);
> -		if (fclose (disk) != 0)
> -		      /* FIXME: give a diagnostic? */
> -		      return NULL;
> +		int fail = (fseek (disk, total_size, SEEK_SET) != 0
> +		            || fwrite ("", sizeof (char), 1, disk) != 1);
> +		if (fclose (disk) != 0 || fail)
> +			goto free_filename;
> 
> -		return strdup (filename);
> +		return filename;
>  }

Nice patch, Jim.  It's often hard to allocate time to fix something that
still works, but that you shouldn't use.

-- 
David Cantrell <dcantrell at redhat.com>
Red Hat / Westford, MA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.alioth.debian.org/pipermail/parted-devel/attachments/20070307/251e689d/attachment.pgp


More information about the parted-devel mailing list