- if (ar_files[0][0] == '-' && ar_files[0][1] == '\0')
- {
- if (ar_reading)
- archive = STDIN;
- else
- archive = STDOUT;
- }
- else /* This can't happen if (ar_reading==2)
- archive = rmtopen(ar_files[0], O_RDWR|O_CREAT|O_BINARY, 0666);
- else */ if (ar_reading)
- archive = rmtopen (ar_files[0], O_RDONLY | O_BINARY, 0666);
- else
- archive = rmtcreat (ar_files[0], 0666);
-
- if (archive < 0)
- {
- msg_perror ("can't open archive %s", ar_files[0]);
- exit (EX_BADARCH);
- }
-
- if (ar_reading)
- {
- for (;;)
- {
- char *ptr;
- int max, count;
-
- r_error_count = 0;
- error_loop:
- err = rmtread (archive, ar_block->charptr, (int) (blocksize));
- if (err < 0)
- {
- readerror ();
- goto error_loop;
- }
- if (err == 0)
- break;
- ptr = ar_block->charptr;
- max = err;
- while (max)
- {
- count = (max < RECORDSIZE) ? max : RECORDSIZE;
- err = write (STDOUT, ptr, count);
- if (err != count)
- {
- if (err < 0)
- {
- msg_perror ("can't write to compress");
- exit (EX_SYSTEM);
- }
- else
- msg ("write to compress short %d bytes", count - err);
- count = (err < 0) ? 0 : err;
- }
- ptr += count;
- max -= count;
- }
- }
- }
- else
- {
- for (;;)
- {
- int n;
- char *ptr;
-
- n = blocksize;
- ptr = ar_block->charptr;
- while (n)
- {
- err = read (STDIN, ptr, (n < RECORDSIZE) ? n : RECORDSIZE);
- if (err <= 0)
- break;
- n -= err;
- ptr += err;
- }
- /* EOF */
- if (err == 0)
- {
- if (f_compress < 2)
- blocksize -= n;
- else
- bzero (ar_block->charptr + blocksize - n, n);
- err = rmtwrite (archive, ar_block->charptr, blocksize);
- if (err != (blocksize))
- writeerror (err);
- if (f_compress < 2)
- blocksize += n;
- break;
- }
- if (n)
- {
- msg_perror ("can't read from compress");
- exit (EX_SYSTEM);
- }
- err = rmtwrite (archive, ar_block->charptr, (int) blocksize);
- if (err != blocksize)
- writeerror (err);
- }
- }
-
- /* close_archive(); */
- exit (0);
- }
- }
- /* So we should exec compress (-d) */
- if (ar_reading)
- execlp ("compress", "compress", "-d", (char *) 0);
- else
- execlp ("compress", "compress", (char *) 0);
- msg_perror ("can't exec compress");
- _exit (EX_SYSTEM);
-}