QlgRenameKeep()--Rename File or Directory, Keep "new" If It Exists (using NLS-enabled path name)


  Syntax
 #include <Qp0lstdi.h>

 int QlgRenameKeep(Qlg_Path_Name_T *old, Qlg_Path_Name_T *new);  
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

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

The QlgRenameKeep() function, like the Qp0lRenameKeep() function, renames a file or a directory specified by old to the name given by new. The difference is that the QlgRenameKeep() function takes pointers to Qlg_Path_Name_T structures, while Qp0lRenameKeep() takes pointers to character strings.

Limited information about the old and new parameters is provided here. For more information about these parameters and for a discussion of the authorities required, return values, and related information, see Qp0lRenameKeep()--Rename File or Directory, Keep "new" If It Exists.


Parameters

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

new
(Input) A pointer to a Qlg_Path_Name_T structure that contains a path name or a pointer to the path name of the new name for the file. For more information about the Qlg_Path_Name_T structure, see Path name format.

Related Information


Example

When you pass two file names to this example, it changes the first file name to the second file name using QlgRenameKeep().

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

#include <Qp0lstdi.h>
#include <stdio.h>

int main(int argc, char **argv)
{

  if ( argc != 3 )
  {
    printf( "Usage: %s old_fn new_fn\n", argv[0]);
    perror ( "Could not rename file" );
  }

  else
  {
    const char US_const[3]= "US";
    const char Language_const[4]="ENU";
    typedef struct pnstruct
    {
      Qlg_Path_Name_T qlg_struct;
                                /*** EXTRA STORAGE MAY BE NEEDED ***/
      char pn[1025];  /* This size must be >= the path */
                                /* name length or a pointer to   */
                                /* the path name.                */
    };
    struct pnstruct path_old;
    struct pnstruct path_new;

    struct pnstruct *path_old_ptr;
    struct pnstruct *path_new_ptr;


    memset((void*)&path_old, 0x00, sizeof(struct pnstruct));
    path_old_ptr = &path_old;

    path_old.qlg_struct.CCSID = 37;
    memcpy(path_old.qlg_struct.Country_ID,US_const,2);
    memcpy(path_old.qlg_struct.Language_ID,Language_const,3);;
    path_old.qlg_struct.Path_Type = 0;
    path_old.qlg_struct.Path_Length = strlen(argv[1]);
    path_old.qlg_struct.Path_Name_Delimiter[0] = '/';
    memcpy(path_old.pn,argv[1],sizeof(argv[1])-1);


    memset((void*)&path_new, 0x00, sizeof(struct pnstruct));
    path_new_ptr = &path_new;

    path_new.qlg_struct.CCSID = 37;
    memcpy(path_new.qlg_struct.Country_ID,US_const,2);
    memcpy(path_new.qlg_struct.Language_ID,Language_const,3);;
    path_new.qlg_struct.Path_Type = 0;
    path_new.qlg_struct.Path_Length = strlen(argv[2]);
    path_new.qlg_struct.Path_Name_Delimiter[0] = '/';
    memcpy(path_new.pn,argv[2],sizeof(argv[2])-1);


    if (QlgRenameKeep((Qlg_Path_Name_T *)path_old_ptr,
                      (Qlg_Path_Name_T *)path_new_ptr ) != 0)
    {perror ( "Could not rename file." ); }
    else {perror ( "File renamed." ); }
  }

}

API introduced: V5R1

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