QlgChown()--Change Owner and Group of File (using NLS-enabled path name)


  Syntax
 #include <unistd.h>

 int QlgChown(Qlg_Path_Name_T *path, uid_t owner,gid_t  
 group);
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes for chown().

The QlgChown() function, like the chown() function, changes the owner and group of a file. The difference is that the QlgChown() function takes a pointer to a Qlg_Path_Name_T structure, while chown() 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, return values, and related information, see chown()--Change Owner and Group of File.


Parameters

path
(Input) A pointer to a Qlg_Path_Name_T structure that contains a path name or a pointer to a path name of the file whose owner and group are being changed. For more information on the Qlg_Path_Name_T structure, see Path name format.

Related Information


Example

See Code disclaimer information for information pertaining to code examples.

The following example changes the owner and group of a file:

#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <Qp0lstdi.h>

main() {
  int file_descriptor;
  struct stat info;

 #define mypath "temp.file"
 const char US_const[3]= "US";
 const char Language_const[4] ="ENU";
 typedef struct pnstruct
 {
   Qlg_Path_Name_T qlg_struct;
   char pn[100]; /* This array size must be >= the  */
                   /* length of the path name or this must */
                   /* be a pointer to the path name.  */
 };
 struct pnstruct path;
   /***************************************************************/
   /*   Initialize Qlg_Path_Name_T parameters                     */
   /***************************************************************/
  memset((void*)&path, 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;
  path.qlg_struct.Path_Name_Delimiter[0] = '/';
  memcpy(path.pn,mypath,sizeof(mypath)-1);


  if ((file_descriptor = QlgCreat((Qlg_Path_Name_T *)&path, S_IRWXU)) == -1)
    perror("creat() error");
  else {
    close(file_descriptor);
    QlgStat((Qlg_Path_Name_T *)&path, &info);
    printf("original owner was %d and group was %d\n", info.st_uid,
           info.st_gid);
    if (QlgChown((Qlg_Path_Name_T *)&path, 152, 0) != 0)
      perror("QlgChown() error");
    else {
      QlgStat((Qlg_Path_Name_T *)&path, &info);
      printf("after QlgChown(), owner is %d and group is %d\n",
             info.st_uid, info.st_gid);
    }
    QlgUnlink((Qlg_Path_Name_T *)&path);
  }
}

Output:

original owner was 137 and group was 0
after QlgChown(), owner is 152 and group is 0

API introduced: V5R1
Top | UNIX-Type APIs | APIs by category