Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

18. Directories and Links > Changing the Name of a File: rename()

Changing the Name of a File: rename()

The rename() system call can be used both to rename a file and to move it into another directory on the same file system.

#include <stdio.h>

int rename(const char *oldpath, const char *newpath);

Note

Returns 0 on success, or -1 on error

The oldpath argument is an existing pathname, which is renamed to the pathname given in newpath.

The rename() call just manipulates directory entries; it doesn’t move file data. Renaming a file doesn’t affect other hard links to the file, nor does it affect any processes that hold open descriptors for the file, since these descriptors refer to open file descriptions, which (after the open() call) have no connection with filenames.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint