QlgReadlink()--Read Value of Symbolic Link (using NLS-enabled path name)


  Syntax
 #include <unistd.h>

 int QlgReadlink(Qlg_Path_Name_T *path,
                 Qlg_Path_Name_T *buf,  
                 size_t bufsiz);  
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

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

The QlgReadlink() function, like the readlink() function, places the contents of the symbolic link path in the buffer buf. The difference is that the QlgReadlink() function uses pointers to Qlg_Path_Name_T structures, while readlink() uses pointers to character strings.

Names returned on calls to QlgReadlink() are returned in the coded character set identifier (CCSID) specified in the symbolic link's path input path structure.

Limited information about the path parameter, the buf parameter, and the size parameter is provided here. For more information about these parameters and for a discussion on authorities required, return values, and related information, see readlink()--Read Value of Symbolic Link.


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 symbolic link. For more information about the Qlg_Path_Name_T structure, see Path name format.

The CCSID that is specified in this input path name structure is the CCSID that will be used for the returned symbolic link contents in the buf output buffer.

buf
(Output) A pointer to the area in which the contents of the link should be stored. For more information about the Qlg_Path_Name_T structure, see Path name format.

bufsiz
(Input) The size of buf in bytes.

Related Information


Example

The following example uses QlgReadlink().

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

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

int main()
{
  int fileDescriptor;

  char * pathToFile = "/readlink.file";
  char * pathToSymlnk = "/readlink.symlink";

  typedef struct pathStruct
  {
    Qlg_Path_Name_T pathHeader;
    char pathChars[100]; 
  } pathStruct_T;

  pathStruct_T filePath;
  pathStruct_T symlnkPath;
  pathStruct_T retrievedContents;

  /***************************************************************/
  /*   Initialize Qlg_Path_Name_T parameters                     */
  /***************************************************************/
  memset(&filePath, 0, sizeof(filePath));
  filePath.pathHeader.CCSID = 37;
  memcpy(filePath.pathHeader.Country_ID, "US", 2);
  memcpy(filePath.pathHeader.Language_ID, "ENU",3);
  filePath.pathHeader.Path_Type = QLG_CHAR_SINGLE;
  filePath.pathHeader.Path_Length = strlen(pathToFile);
  filePath.pathHeader.Path_Name_Delimiter[0] = '/';
  memcpy(filePath.pathChars,
         pathToFile,
         filePath.pathHeader.Path_Length);

  memset(&symlnkPath, 0, sizeof(symlnkPath));
  symlnkPath.pathHeader.CCSID = 37;
  memcpy(symlnkPath.pathHeader.Country_ID,"US",2);
  memcpy(symlnkPath.pathHeader.Language_ID,"ENU",3);
  symlnkPath.pathHeader.Path_Type = QLG_CHAR_SINGLE;
  symlnkPath.pathHeader.Path_Length = strlen(pathToSymlnk);
  symlnkPath.pathHeader.Path_Name_Delimiter[0] = '/';
  memcpy(symlnkPath.pathChars,
         pathToSymlnk,
         symlnkPath.pathHeader.Path_Length);

  /* Clear receiver to 0s so that the returned path will appear
     NULL terminated for printing later in this test program. */
  memset(&retrievedContents, 0, sizeof(retrievedContents));

  /* Create a symlnk */
  if (QlgSymlink((Qlg_Path_Name_T *)&filePath,
                 (Qlg_Path_Name_T *)&symlnkPath) != 0)
  {
    perror("QlgSymlink() error");
  }
  else
  {
    if (QlgReadlink((Qlg_Path_Name_T *)&symlnkPath,
                    (Qlg_Path_Name_T *)&retrievedContents,
                    sizeof(retrievedContents)) < 0)
    {
      perror("QlgReadlink() error");
    }
    else
    {

      printf("QlgReadlink() returned '%s' for '%s'\n",
             retrievedContents.pathChars,
             symlnkPath.pathChars);
    }

    /* Remove the symlnk */
    QlgUnlink((Qlg_Path_Name_T *)&symlnkPath);
  }

  /* Remove the stream file */
  QlgUnlink((Qlg_Path_Name_T *)&filePath);

  return 0;
}

Output:

QlgReadlink() returned '/readlink.file' for '/readlink.symlink'

API introduced: V5R1

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