razor.c
changeset 197 d29026900856
parent 196 b38fc517ea04
child 208 7b460017c221
     1.1 --- a/razor.c	Mon Apr 07 00:06:22 2008 -0400
     1.2 +++ b/razor.c	Mon Apr 07 00:35:27 2008 -0400
     1.3 @@ -198,13 +198,13 @@
     1.4  }
     1.5  
     1.6  int
     1.7 -razor_set_write(struct razor_set *set, const char *filename)
     1.8 +razor_set_write_to_fd(struct razor_set *set, int fd)
     1.9  {
    1.10  	char data[4096];
    1.11  	struct razor_set_header *header = (struct razor_set_header *) data;
    1.12  	struct array *a;
    1.13  	uint32_t offset;
    1.14 -	int i, fd;
    1.15 +	int i;
    1.16  
    1.17  	memset(data, 0, sizeof data);
    1.18  	header->magic = RAZOR_MAGIC;
    1.19 @@ -225,10 +225,6 @@
    1.20  	header->sections[i].offset = 0;
    1.21  	header->sections[i].size = 0;
    1.22  
    1.23 -	fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
    1.24 -	if (fd < 0)
    1.25 -		return -1;
    1.26 -
    1.27  	razor_write(fd, data, sizeof data);
    1.28  	memset(data, 0, sizeof data);
    1.29  	for (i = 0; i < ARRAY_SIZE(razor_sections); i++) {
    1.30 @@ -239,11 +235,27 @@
    1.31  		razor_write(fd, data, ALIGN(a->size, 4096) - a->size);
    1.32  	}
    1.33  
    1.34 -	close(fd);
    1.35 -
    1.36  	return 0;
    1.37  }
    1.38  
    1.39 +int
    1.40 +razor_set_write(struct razor_set *set, const char *filename)
    1.41 +{
    1.42 +	int fd, status;
    1.43 +
    1.44 +	fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
    1.45 +	if (fd < 0)
    1.46 +		return -1;
    1.47 +
    1.48 +	status = razor_set_write_to_fd(set, fd);
    1.49 +	if (status) {
    1.50 +	    close(fd);
    1.51 +	    return status;
    1.52 +	}
    1.53 +
    1.54 +	return close(fd);
    1.55 +}
    1.56 +
    1.57  void
    1.58  razor_build_evr(char *evr_buf, int size, const char *epoch,
    1.59  		const char *version, const char *release)