QlgSem_open_np()--Open Named Semaphore with Maximum Value (using NLS-enabled path name)


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

 sem_t * QlgSem_open_np(const Qlg_Path_Name_T *name, int oflag  
                     mode_t mode, unsigned int value,
                     sem_attr_np_t * attr);

  Service Program Name: QP0ZPSEM

  Default Public Authority: *USE

  Threadsafe: Yes

The QlgSem_open_np() function, like the sem_open_np() 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_np() function takes a pointer to a Qlg_Path_Name_T structure, while the sem_open_np() function takes a pointer to a character string.

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_np()--Open Named Semaphore with Maximum Value.


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_np() is not successful, errno usually indicates the following error or one of the errors identified in sem_open_np()--Open Named Semaphore with Maximum Value.

[ECONVERT]
A conversion error for the parameter name.

Related Information

Note: All of the related information for sem_open_np() applies to QlgSem_open_np(). 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 and a maxiumum value of 11. 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;
  sem_attr_np_t attr;

  #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));


  memset(&attr, 0, sizeof(attr));
  attr.maxvalue=11;
  my_semaphore = QlgSem_open_np((Qlg_Path_Name_T *)path name,
                              O_CREAT|O_EXCL,
                              S_IRUSR | S_IWUSR,
                              10,
                              &attr);
}


API introduced: V5R1

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