#include <unistd.h> int QlgLchown(Qlg_Path_Name_T *path, uid_t owner,gid_t group);Service Program Name: QP0LLIB1
The QlgLchown() function, like the lchown() function, changes the owner and group of a file. The difference is that the QlgLchown() function takes a pointer to a Qlg_Path_Name_T structure, while lchown() takes a pointer to a character string.
Limited information on the path parameter is provided here. For more on the path parameter and for a discussion of other parameters, authorities required, return values, and related information, see lchown()--Change Owner and Group of Symbolic Link.
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 <Qp0lstdi.h> main() { #define mypath_link_name "temp.link" #define mypath_fn "temp.file" const char US_const]3[= "US"; const char Language_const]4[="ENU"; struct stat info; 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_link; struct pnstruct path_fn; /***************************************************************/ /* Initialize Qlg_Path_Name_T parameters */ /***************************************************************/ memset((void*)&path_link, 0x00, sizeof(struct pnstruct)); path_link.qlg_struct.CCSID = 37; memcpy(path_link.qlg_struct.Country_ID,US_const,2); memcpy(path_link.qlg_struct.Language_ID,Language_const,3); path_link.qlg_struct.Path_Type = QLG_CHAR_SINGLE; path_link.qlg_struct.Path_Length = sizeof(mypath_link_name)-1; path_link.qlg_struct.Path_Name_Delimiter]0[ = '/'; memcpy(path_link.pn,mypath_link_name,sizeof(mypath_link_name)-1); memset((void*)&path_fn, 0x00, sizeof(struct pnstruct)); path_fn.qlg_struct.CCSID = 37; memcpy(path_fn.qlg_struct.Country_ID,US_const,2); memcpy(path_fn.qlg_struct.Language_ID,Language_const,3); path_fn.qlg_struct.Path_Type = QLG_CHAR_SINGLE; path_fn.qlg_struct.Path_Length = sizeof(mypath_fn)-1; path_fn.qlg_struct.Path_Name_Delimiter]0[ = '/'; memcpy(path_fn.pn,mypath_fn,sizeof(mypath_fn)-1); if (QlgSymlink((Qlg_Path_Name_T *)&path_fn, (Qlg_Path_Name_T *)&path_link) == -1) perror("QlgSymlink() error"); else { QlgLstat((Qlg_Path_Name_T *)&path_link, &info); printf("original owner was %d and group was %d\n", info.st_uid, info.st_gid); if (QlgLchown((Qlg_Path_Name_T *)&path_link, 152, 0) != 0) perror("QlgLchown() error"); else { QlgLstat((Qlg_Path_Name_T *)&path_link, &info); printf("after QlgLchown(), owner is %d and group is %d\n", info.st_uid, info.st_gid); } QlgUnlink((Qlg_Path_Name_T *)&path_link); } }
Output:
original owner was 137 and group was 0 after QlgLchown(), owner is 152 and group is 0
Top | UNIX-Type APIs | APIs by category |