/* -*- Mode:C; Coding:us-ascii-unix; fill-column:132 -*- */
   @file      shmRemoveRT.c
   @author    Mitch Richling <https://www.mitchr.me/>
   @Copyright Copyright 1998,2000,2004 by Mitch Richling.  All rights reserved.
   @brief     How to delete a shared memory segment@EOL
   @Keywords  UNIX shared memory
   @Std       ISOC
              - MacOS X.2

   This C program is intended to illustrate how one can delete shared memory segments in UNIX using the POSIX real-time APIs.

#include <stdlib.h>             /* Standard Lib    C89   */
#include <stdio.h>              /* I/O lib         C89   */
#include <errno.h>              /* error stf       POSIX */
#include <sys/mman.h>           /* mmap()          POSIX */

int main(int argc, char *argv[]) {

  /* Getting rid of a shared memory segment via the POSIX RT APIs is simple: */
  if(shm_unlink("/tmp/foobar") < 0) {
    /* I have a case for all of the interesting cases, even the ones that can not happen in this situation... */
    switch(errno) {
     case EACCES:           printf("shm_unlink failed: Permission is denied to be remove the object.\n");
     case ENAMETOOLONG:     printf("shm_unlink failed: name exceeded SHM_NAME_MAX characters.\n");
     case ENOENT:           printf("shm_unlink failed: The named object does not exist.\n");
    default:                printf("shm_unlink failed: Duno why (%d)...\n", errno);
    } /* end switch */
  } /* end if */

  printf("The shared memory segment was removed.\n");

  return 0;
} /* end func main() */