QlgFtok()--Generate IPC Key from File Name (using NLS-enabled path name)


  Syntax
 #include <sys/ipc.h>
 #include <qlg.h>

 key_t QlgFtok(const Qlg_Path_Name_T *path, int id);  


  Service Program Name: QP0ZCPA

  Default Public Authority: *USE

  Threadsafe: Conditional. See Usage Notes for ftok()--Generate IPC Key from File Name.

The QlgFtok() function, like the ftok() function, generates an IPC key based on the combination of path and id. The difference is that the QlgFtok() function takes a pointer to a Qlg_Path_Name_T structure, while the ftok() function takes a pointer to a character string.

Limited information on the path parameter is provided here. For more information on the path parameter and for a discussion of other parameters, authorities required, returnvalues, and related information, see ftok()--Generate IPC Key from File Name.


Parameters

path
(Input) The path name of the file used in combination with id to generate the key. For more information on the Qlg_Path_Name_T structure, see Path name format.

Related Information

ftok()--Generate IPC Key from File Name


Example

The following example uses the QlgFtok() and semget() functions.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <sys/ipc.h>
#include <sys/sem.h>
#include <errno.h>
#include <stdio.h>
#include <qlg.h>

int main(int argc, char *argv[])
{
    key_t myKey;
    int   semid;

    #define mypath "/myApplication/myFile"
    const char US_const[3]= "US";
    const char Language_const[4]="ENU";
    const char Path_Name_Del_const[2]= "/";
    typedef struct pnstruct
     {
      Qlg_Path_Name_T qlg_struct;
      char[100] pn;  /* This size must be >= the path */
                               /* name length or be a pointer   */
                               /* to the path name.             */

     };
    struct pnstruct path;


   /***************************************************************/
   /*   Initialize Qlg_Path_Name_T parameters                     */
   /***************************************************************/
  memset((void*)path name, 0x00, sizeof(struct pnstruct));
  path.qlg_struct.CCSID = 37;
  memcpy(path.qlg_struct.Country_ID,US_const,2);
  memcpy(path.qlg_struct.Language_ID,Language_const,3);
  path.qlg_struct.Path_Type = QLG_CHAR_SINGLE;
  path.qlg_struct.Path_Length = sizeof(mypath)-1;
  memcpy(path.qlg_struct.Path_Name_Delimiter,Path_Name_Del_const,1);
  memcpy(path.pn,mypath,sizeof(mypath));


    /* Use QlgFtok to generate a key associated with a file.  */
    /* Every process will get the same key back if the caller */
    /* calls with the same parameters.                        */
    myKey = QlgFtok((Qlg_Path_Name_T *)path name, 42);
    if(myKey == -1) {
      printf("QlgFtok failed with errno = %d\n", errno);
      return -1;
    }

    /* Call an xxxget() API, where xxx is sem, shm, or msg.  */
    /* This will create or reference an existing IPC object  */
    /* with the 'well known' key associated with the file    */
    /* name used above.                                      */
    semid = semget(myKey, 1, 0666 | IPC_CREAT);
    if(semid == -1) {
      printf("semget failed with errno = %d\n", errno);
      return -1;
    }

    /* ... Use the semaphore as required ... */
    return 0;
}


API introduced: V5R1

[ Back to top | UNIX-Type APIs | APIs by category ]