razor.c
changeset 91 6884cefd1b8c
parent 83 43ef0eb1b603
child 92 74f19848a71b
     1.1 --- a/razor.c	Fri Nov 16 17:14:51 2007 -0500
     1.2 +++ b/razor.c	Thu Jan 03 09:32:31 2008 -0500
     1.3 @@ -14,6 +14,7 @@
     1.4  #include <fnmatch.h>
     1.5  
     1.6  #include "razor.h"
     1.7 +#include "razor-internal.h"
     1.8  
     1.9  struct array {
    1.10  	void *data;
    1.11 @@ -142,22 +143,6 @@
    1.12  	return p;
    1.13  }
    1.14  
    1.15 -static int
    1.16 -write_to_fd(int fd, void *p, size_t size)
    1.17 -{
    1.18 -	int rest, len;
    1.19 -
    1.20 -	rest = size;
    1.21 -	while (rest > 0) {
    1.22 -		len = write(fd, p, rest);
    1.23 -		if (len < 0)
    1.24 -			return -1;
    1.25 -		rest -= len;
    1.26 -	}
    1.27 -
    1.28 -	return 0;
    1.29 -}
    1.30 -
    1.31  static void *
    1.32  zalloc(size_t size)
    1.33  {
    1.34 @@ -262,7 +247,7 @@
    1.35  		header->sections[i].type = i;
    1.36  		header->sections[i].offset = offset;
    1.37  		header->sections[i].size = a->size;
    1.38 -		offset += (a->size + 4095) & ~4095;
    1.39 +		offset += ALIGN(a->size, 4096);
    1.40  	}
    1.41  
    1.42  	header->sections[i].type = ~0;
    1.43 @@ -273,12 +258,12 @@
    1.44  	if (fd < 0)
    1.45  		return -1;
    1.46  
    1.47 -	write_to_fd(fd, data, sizeof data);
    1.48 +	razor_write(fd, data, sizeof data);
    1.49  	for (i = 0; i < ARRAY_SIZE(razor_sections); i++) {
    1.50  		if (razor_sections[i].type != i)
    1.51  			continue;
    1.52  		a = (void *) set + razor_sections[i].offset;
    1.53 -		write_to_fd(fd, a->data, (a->size + 4095) & ~4095);
    1.54 +		razor_write(fd, a->data, ALIGN(a->size, 4096));
    1.55  	}
    1.56  
    1.57  	close(fd);