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]
|