File: vmcp_example.c

package info (click to toggle)
s390-tools 2.35.0-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 12,248 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 (65 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (4)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 * vmcp_example - Example program for vmcp.c
 *
 * Copyright 2018 IBM Corp.
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

//! [code]
#include <stdio.h>
#include <stdlib.h>
#include <err.h>

#include "lib/vmcp.h"

/*
 * Demonstrate vmcp() function usage
 */
int main(void)
{
	struct vmcp_parm cp;
	int rc;

	cp.cpcmd = "q osa";
	cp.buffer_size = VMCP_DEFAULT_BUFSZ;
	cp.do_upper = true;

	rc = vmcp(&cp);

	switch (rc) {
	case VMCP_SUCCESS:
		printf("%s\n", cp.response);
		free(cp.response);
		break;
	case VMCP_ERR_OPEN:
		errx(EXIT_FAILURE, "Could not open device %s", VMCP_DEVICE_NODE);
		break;
	case VMCP_ERR_SETBUF:
		errx(EXIT_FAILURE, "Could not set buffer size");
		break;
	case VMCP_ERR_GETCODE:
		errx(EXIT_FAILURE, "Could not query return code");
		break;
	case VMCP_ERR_GETSIZE:
		errx(EXIT_FAILURE, "Could not query response size");
		break;
	case VMCP_ERR_WRITE:
		errx(EXIT_FAILURE, "Could not issue CP command");
		break;
	case VMCP_ERR_READ:
		errx(EXIT_FAILURE, "Could not read CP response");
		break;
	case VMCP_ERR_TOOSMALL:
		free(cp.response);
		printf("Response truncated (requires %u bytes)\n",
		       cp.response_size);
		errx(EXIT_FAILURE, "Response buffer (%u bytes) too small",
		     cp.buffer_size);
		break;
	}
	return EXIT_SUCCESS;
}

//! [code]