Name

wrename - wrename files

Library

libc.lib

Synopsis

  #include <wchar.h>
  int wrename (const wchar_t *from, const wchar_t *to);

Return values

The wrename() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

Detailed description

The wrename system call causes the link with the wide character name from to be renamed with the wide character name to. If to exists, it is first removed. Both from and to must be of the same type (that is, both directories or both non-directories), and must reside on the same file system.

If the final component of from is a symbolic link, the symbolic link is renamed, not the file or directory to which it points.

If a file with a symbolic link pointing to it is renamed, then a subsequent open call on the symbolic link file would automatically remove the link file, i.e consider a symbolic file link.x pointing to a file abc.x. If the file abc.x is renamed to abcd.x then, a subsequent open call on link.x file would automatically remove link.x file.

Limitation: wrename call fails if from and to are files, and are in use(i.e., if any one of these files is kept open by a process). Parent directory time stamps remain uneffected if wrename creates a new entry in the directory, this new entry has only two time stamps, modification and access time stamps, here access time stamp is equal to modification time stamp.


Examples

/****************************************************************************************
* Detailed description  : This sample code demonstrates usage of wrename system call.
*
* Preconditions : Example.cfg file should be present in the current working directory.
****************************************************************************************/
#include <wchar.h>
#include <stdio.h>
int main()
{
  if(wrename(L"Example.txt" , L"Example2.txt") < 0 )  {
     printf("Failed to wrename Example.txt\n");
     return -1;
  }
  printf("wrename successful \n");
  return 0;
}

         

Output:

wrename successful

         


Errors

The wrename system call will fail and neither of the argument files will be affected if:
[EINVAL]
  Invalid argument.
[ENAMETOOLONG]
  A component of a pathname exceeded 255 characters.
[ENOENT]
  The named file does not exist.
[EACCES]
  Search permission is denied for a component of the path prefix.
[EACCES]
  The from argument is a parent directory of to, or an attempt is made to wrename .’ or ..’.

See also

open, symlink, rename

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top