#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <fcntl.h>
#include <sys/openprom.h>
#include <sys/openpromio.h>
#include <sys/stat.h>
#include <sys/types.h>

int main(int argc, char *argv[]) {
  int openprom;
  struct openpromio *property;

/* Ought to check args here */

  if ((property=(struct openpromio*)malloc(
				      sizeof(struct openpromio*) +
				      OPROMMAXPARAM))
      ==NULL) {
    fprintf(stderr, "%s cannot allocate mem.\n", argv[0]);
    exit(1);
  }
  strcpy(&property->oprom_array[0], argv[1]);
  strcpy(&property->oprom_array[strlen(&property->oprom_array[0])+1], argv[2]);
  property->oprom_size=OPROMMAXPARAM; 

  fprintf(stderr,"%s: setting OpenPROM property [%s] to [%s].\n",
	  argv[0], argv[1], argv[2]);

  if ((openprom=open("/dev/openprom", O_RDWR)) == -1) {
    fprintf(stderr, "%s open: %s\n", argv[0], strerror(errno));
    exit(1);
  }

  if (ioctl(openprom, OPROMSETOPT2, property)==-1) {
    fprintf(stderr, "%s ioctl(OPROMSETOPT2): %s\n", argv[0], strerror(errno));
      exit(1);
    }

  close(openprom);

  fprintf(stderr, "%s: done.\n", argv[0]);

  return 0;
}
