rename

Renames the specified file.

Library:LibC
Classification:ANSI
Service:File and Directory I/O

Syntax

  #include <stdio.h> 
   
  int rename (
     const char  *old,   
     const char  *new);
  

Parameters

old

(IN) Points to a string containing the pathname of the file to be renamed.

new

(IN) Points to a string containing the new pathname of the file.

Return Values

If successful, returns 0; otherwise returns -1 and sets errno to one of the following:

Decimal

Constant

Description

1

ENOENT

Either old or new points to an empty string.

6

EACCES

A component of either path prefix denies search permission; or one of the directories containing old or new denies write permissions; or, write permission is required and is denied for a directory pointed to by the old or new arguments.

7

EEXIST

The link named by new is a directory that is not an empty directory.

8

EXDEV

The links named by new and old are on different file systems, and the implementation does not support links between file systems.

9

EINVAL

The new directory pathname contains a path prefix that names the old directory.

12

ENOSPC

The directory that would contain new cannot be extended.

62

EBUSY

The directory named by old or new is currently in use by the system or another process.

64

EISDIR

The new argument points to a directory and the old argument points to a file that is not a directory.

65

ENAMETOOLONG

The length of the old or new argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.

68

ENOTEMPTY

The link named by new is a directory that is not an empty directory.

69

EPERM

The operation is not permitted.

72

EMLINK

Too many links.

76

EROFS

The requested operation requires writing in a directory on a read-only file system.

Remarks

The rename function takes on either NetWare/DOS semantics or POSIX semantics.

POSIX: If an NLM is compiled with POSIX prelude file (posixpre) or the POSIX semantics flag, the rename function allows you to rename FileA to FileB even if FileB already exists. FileB is deleted, and then the rename occurs. The rename function cannot be used to rename a directory to an existing filename or rename a file to an existing directory name.

NetWare: If the NLM is not compiled to use POSIX prelude file, the rename function uses NetWare semantics. The function fails when you try to rename a file to the name of an existing file. If you rename FileA to DirectoryB, FileA moves under DirectoryB. Renaming DirectoryA to FileB fails.

With NetWare semantics, wildcard specifiers are allowed for the old and new parameters. However, if a wildcard is specified, only matching files (not directories) are renamed.

See Also

rmdir