/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : shmtest_baseline.cc                                           */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>

char memfile[] = "hello, world";
const char msg[] = "hello, world\n";

main()
{
  int   fd;
  char  *p;

  if ((fd=shm_open(memfile,O_RDWR|O_CREAT,0)) == -1) {
    perror("hello:shm_open(create) failed");
    return EXIT_FAILURE;
  }
  if (ltrunc(fd, strlen(msg)+1, SEEK_SET) == -1) {
    perror("hello:ltrunc failed");
    return EXIT_FAILURE;
  }
  if ((p=(char *)mmap(0,strlen(msg)+1,PROT_READ|PROT_WRITE,
	      MAP_SHARED, fd, 0)) == (char *)-1) {
    perror("hello: cannot map region");
    return EXIT_FAILURE;
  }
  strcpy(p, msg);
  fputs(p, stdout);
  munmap(p, strlen(msg)+1);
  close(fd);
  if (shm_unlink(memfile) == -1) {
    perror("hello: cannot unlink region");
    return EXIT_FAILURE;
  }
  return 0;
}



