X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/64e74631e0bb81b5e781c619c4f91417096d4ee8..536492752b930d94f644daed3d1b0af7f21d24a1:/batch.c?ds=sidebyside diff --git a/batch.c b/batch.c index f27e6fc3..1364b562 100644 --- a/batch.c +++ b/batch.c @@ -60,6 +60,8 @@ void write_batch_flist_file(char *buff, int bytes_to_write) } } +/* TODO: Someone please rewrite this! Why in the world don't we use + * the send/receive code from flist.c for this? */ void write_batch_flist_info(int flist_count, struct file_struct **fptr) { int i; @@ -68,7 +70,6 @@ void write_batch_flist_info(int flist_count, struct file_struct **fptr) /* Write flist info to batch file */ bytes_to_write = - sizeof(unsigned) + sizeof(time_t) + sizeof(OFF_T) + sizeof(mode_t) + @@ -82,7 +83,8 @@ void write_batch_flist_info(int flist_count, struct file_struct **fptr) fdb_close = 0; for (i = 0; i < flist_count; i++) { - write_batch_flist_file((char *) fptr[i], bytes_to_write); + write_batch_flist_file((char*)&fptr[i]->flags, sizeof fptr[0]->flags); + write_batch_flist_file((char*)fptr[i], bytes_to_write); write_char_bufs(fptr[i]->basename); write_char_bufs(fptr[i]->dirname); write_char_bufs(fptr[i]->basedir); @@ -180,20 +182,19 @@ void write_batch_argvs_file(int argc, char *argv[]) struct file_list *create_flist_from_batch(void) { - unsigned char flags; + unsigned short flags; fdb_open = 1; fdb_close = 0; - batch_flist = (struct file_list *) malloc(sizeof(batch_flist[0])); + batch_flist = new(struct file_list); if (!batch_flist) { out_of_memory("create_flist_from_batch"); } batch_flist->count = 0; batch_flist->malloced = 1000; - batch_flist->files = - (struct file_struct **) malloc(sizeof(batch_flist->files[0]) * - batch_flist->malloced); + batch_flist->files = new_array(struct file_struct *, + batch_flist->malloced); if (!batch_flist->files) { out_of_memory("create_flist_from_batch"); } @@ -207,14 +208,10 @@ struct file_list *create_flist_from_batch(void) batch_flist->malloced += 1000; else batch_flist->malloced *= 2; - batch_flist->files = - (struct file_struct **) realloc(batch_flist-> - files, - sizeof - (batch_flist-> - files[0]) * - batch_flist-> - malloced); + batch_flist->files + = realloc_array(batch_flist->files, + struct file_struct *, + batch_flist->malloced); if (!batch_flist->files) out_of_memory("create_flist_from_batch"); } @@ -264,15 +261,13 @@ int read_batch_flist_file(char *buff, int len) return bytes_read; } -unsigned char read_batch_flags() +unsigned short read_batch_flags(void) { - int flags; + unsigned short flags; - if (read_batch_flist_file((char *) &flags, 4)) { + if (read_batch_flist_file((char*)&flags, sizeof flags)) return 1; - } else { - return 0; - } + return 0; } void read_batch_flist_info(struct file_struct **fptr) @@ -282,7 +277,7 @@ void read_batch_flist_info(struct file_struct **fptr) char buff[256]; struct file_struct *file; - file = (struct file_struct *) malloc(sizeof(*file)); + file = new(struct file_struct); if (!file) out_of_memory("read_batch_flist_info"); memset((char *) file, 0, sizeof(*file)); @@ -392,20 +387,27 @@ void close_batch_csums_file(void) close(fdb); } + +/** + * Write csum info to batch file + * + * @todo This will break if s->count is ever larger than maxint. The + * batch code should probably be changed to consistently use the + * variable-length integer routines, which is probably a compatible + * change. + **/ void write_batch_csum_info(int *flist_entry, int flist_count, struct sum_struct *s) { size_t i; - size_t int_zero = 0; + int int_count; extern int csum_length; fdb_open = 1; - /* Write csum info to batch file */ - - /* FIXME: This will break if s->count is ever not exactly an int. */ write_batch_csums_file(flist_entry, sizeof(int)); - write_batch_csums_file(s ? &s->count : &int_zero, sizeof(int)); + int_count = s ? (int) s->count : 0; + write_batch_csums_file(&int_count, sizeof int_count); if (s) { for (i = 0; i < s->count; i++) {