QlgSem_open()--Open Named Semaphore (using NLS-enabled path name)


  Syntax
 #include <semaphore.h>
 #include <qlg.h>

 sem_t * QlgSem_open(const Qlg_Path_Name_T *name,  
                    int oflag, ...);

  Service Program Name: QP0ZPSEM

  Default Public Authority: *USE

  Threadsafe: Yes

The QlgSem_open() function, like the sem_open() function, opens a named semaphore and returns a semaphore pointer that may be used on subsequent calls to sem_post(), sem_post_np(), sem_wait(), sem_wait_np(), sem_trywait(), sem_getvalue(), and sem_close(). The QlgSem_open() function takes a pointer to a Qlg_Path_Name_T structure, while the sem_open() function takes a pointer to a character string that is in the CCSID of the job.

Limited information about the name parameter is provided in this API. For additional information about the name parameter and a discussion of other parameters, authorities required, return values, and related information, see sem_open()--Open Named Semaphore.


Parameters

name
(Input) A pointer to a Qlg_Path_Name_T structure that contains a path name or a pointer to a path name of the semaphore to be opened. For more information on the Qlg_Path_Name_T structure, see Path name format.

Error Conditions

If QlgSem_open() is not successful, errno usually indicates the following error or one of the errors identified in sem_open()--Open Named Semaphore.

[ECONVERT]
A conversion error for the parameter name.

Related Information

Note: All of the related information for sem_open() applies to QlgSem_open(). See Related Information in sem_open().


Example

The following example opens the named semaphore "/mysemaphore" and creates the semaphore with an initial value of 10 if it does not already exist. If the semaphore is created, the permissions are set such that only the current user has access to the semaphore.

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

#include <semaphore.h>
#include <qlg.h>
main() {

  sem_t * my_semaphore;
  int rc;

  #define mypath "/mysemaphore"
  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));

  my_semaphore = QlgSem_open((Qlg_Path_Name_T *)path name,
                          O_CREAT, S_IRUSR | S_IWUSR, 10);

}


API introduced: V5R1

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