-void write_char_bufs(char *buf)
-{
- /* Write the size of the string which will follow */
-
- char b[4];
- if (buf != NULL)
- SIVAL(b, 0, strlen(buf));
- else {
- SIVAL(b, 0, 0);
- }
-
- write_batch_flist_file(b, sizeof(int));
-
- /* Write the string if there is one */
-
- if (buf != NULL) {
- write_batch_flist_file(buf, strlen(buf));
- }
-}
-
-void write_batch_argvs_file(int argc, char *argv[])
-{
- int fdb;
- int i;
- char buff[256];
-
- strcat(rsync_argvs_file, batch_file_ext);
-
-
- /* Open batch argvs file for writing; create it if it doesn't exist */
- fdb = do_open(rsync_argvs_file, O_WRONLY | O_CREAT | O_TRUNC,
- S_IREAD | S_IWRITE | S_IEXEC);
- if (fdb == -1) {
- rprintf(FERROR, "Batch file %s open error: %s\n",
- rsync_argvs_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- buff[0] = '\0';
- /* Write argvs info to batch file */
-
- for (i = 0; i < argc; ++i) {
- if (i == argc - 2)
- continue;
- /*
- * FIXME:
- * I think directly manipulating argv[] is probably bogus
- */
- if (!strcmp(argv[i], "--write-batch")) {
- /* Safer to change it here than script */
- /* Change to --read-batch + ext * to get ready for remote */
- strlcat(buff, "--read-batch ", sizeof(buff));
- strlcat(buff, batch_file_ext, sizeof(buff));
- } else {
- strlcat(buff, argv[i], sizeof(buff));
- }
-
- if (i < (argc - 1)) {
- strlcat(buff, " ", sizeof(buff));
- }
- }
- strlcat(buff, "\n", sizeof(buff));
- if (!write(fdb, buff, strlen(buff))) {
- rprintf(FERROR, "Batch file %s write error: %s\n",
- rsync_argvs_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- close(fdb);
-}
-
-struct file_list *create_flist_from_batch()
-{
- unsigned char flags;
-
- fdb_open = 1;
- fdb_close = 0;
-
- batch_flist = (struct file_list *) malloc(sizeof(batch_flist[0]));
- 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);
- if (!batch_flist->files) {
- out_of_memory("create_flist_from_batch"); /* dw -- will exit */
- }
-
- for (flags = read_batch_flags(); flags; flags = read_batch_flags()) {
-
- int i = batch_flist->count;
-
- if (i >= batch_flist->malloced) {
- if (batch_flist->malloced < 1000)
- 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);
- if (!batch_flist->files)
- out_of_memory("create_flist_from_batch");
- }
- read_batch_flist_info(&batch_flist->files[i]);
- batch_flist->files[i]->flags = flags;
-
- batch_flist->count++;
- }
-
- return batch_flist;
-
-}
-
-int read_batch_flist_file(char *buff, int len)
-{
- int bytes_read;
-
- if (fdb_open) {
-
- /* Set up file extension */
- strcat(rsync_flist_file, batch_file_ext);
-
- /* Open batch flist file for reading */
- fdb = do_open(rsync_flist_file, O_RDONLY, 0);
- if (fdb == -1) {
- rprintf(FERROR, "Batch file %s open error: %s\n",
- rsync_flist_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- fdb_open = 0;
- }
-
- /* Read flist batch file */
-
- bytes_read = read(fdb, buff, len);
-
- if (bytes_read == -1) {
- rprintf(FERROR, "Batch file %s read error: %s\n",
- rsync_flist_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- if (bytes_read == 0) { /* EOF */
- close(fdb);
- }
- return bytes_read;
-}
-
-unsigned char read_batch_flags()
-{
- int flags;
-
- if (read_batch_flist_file((char *) &flags, 4)) {
- return 1;
- } else {
- return 0;
- }
-}
-
-void read_batch_flist_info(struct file_struct **fptr)