Beispiel #1
0
extern ssize_t io_write(IO_HANDLE f, const void *d, size_t l)
{
	io_private_t *io_ptr = f;
	if (!io_ptr || io_ptr->fd < 0)
		return errno = EBADF , -1;

	if (io_ptr->hash_init)
		gcry_md_write(io_ptr->hash_handle, d, l);

	switch (io_ptr->operation)
	{
		case IO_LZMA:
			if (!io_ptr->lzma_init)
				io_do_compress(io_ptr);
			return lzma_write(io_ptr, d, l);
		case IO_ENCRYPT:
			return enc_write(io_ptr, d, l);
		case IO_DEFAULT:
			return ecc_write(io_ptr, d, l);
	}
	errno = EINVAL;
	return -1;
}
Beispiel #2
0
/* lzma_printf writes the output to the given lzmafile file pointer.
   Upon success, it returns the number of characters printed (not
   including the trailing '\0'). If an output error is encountered,
   a negative value is returned. */
int lzma_printf (struct lzmafile* file, const char *format, ...)
{
  size_t size = 32768;
  int len;
  unsigned char in[32768];
  va_list va;
  va_start(va, format);
  
  in[size-1] = 0;
  (void)vsnprintf((char *)in, size, format, va);
  va_end(va);
  len = strlen((char *)in);
  
  /* check that printf() results fit in buffer */
  if (len <= 0 || len >= (int)size || in[size - 1] != 0) {
    fprintf(stderr,"lzma_printf error: the printf results do not fit in the buffer\n");
    return -1;
  }
  in[len] = '\0';
  len = lzma_write(file, in, len);

  return len;
}
Beispiel #3
0
static int lzma_sync(io_private_t *c)
{
	lzma_write(c, NULL, 0);
	return enc_sync(c);
}