[go: up one dir, main page]

File: output.c

package info (click to toggle)
s390-tools 2.35.0-1
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 12,220 kB
  • sloc: ansic: 184,236; sh: 12,152; cpp: 4,954; makefile: 2,763; perl: 2,519; asm: 1,085; python: 697; xml: 29
file content (47 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * zgetdump - Tool for copying and converting System z dumps
 *
 * Write dump to the file descriptor (fd)
 *
 * Copyright IBM Corp. 2001, 2017
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#include "zg.h"
#include "dfi.h"
#include "dfo.h"
#include "output.h"

#define BUFFER_SIZE	(1 * MIB)

int write_dump(FILE *stream)
{
	const u64 output_size = dfo_size();
	char *buf = zg_alloc(BUFFER_SIZE);
	u64 written = 0;

	if (!dfi_feat_copy())
		ERR_EXIT("Copying not possible for %s dumps", dfi_name());
	STDERR("Format Info:\n");
	STDERR("  Source: %s\n", dfi_name());
	STDERR("  Target: %s\n", dfo_name());
	STDERR("\n");
	zg_progress_init("Copying dump", output_size);
	while (written != output_size) {
		size_t rc;
		u64 cnt;

		cnt = dfo_read(buf, BUFFER_SIZE);
		rc = fwrite(buf, cnt, 1, stream);
		if (rc != 1 && ferror(stream))
			ERR_EXIT("Error: Write failed");
		written += cnt;
		zg_progress(written);
	};
	STDERR("\n");
	STDERR("Success: Dump has been copied\n");
	zg_free(buf);
	return 0;
}