- 论坛徽章:
- 0
|
5可用积分
rename这个函数是在stdio.h里面的,照理说应该是一个c语言标准规定的函数,但是我man了一下,发现有如下的说明
- NAME
- rename - change the name or location of a file
- SYNOPSIS
- #include <stdio.h>
- int rename(const char *oldpath, const char *newpath);
- DESCRIPTION
- rename() renames a file, moving it between directories if required.
- Any other hard links to the file (as created using link(2)) are unaffected.
- If newpath already exists it will be atomically replaced (subject to a few conditions; see ERRORS below),
- so that there is no point at which another process attempting to access newpath will find it missing.
复制代码
上面说目标文件存在时是会被替换的,但是我查了一下msdn却又是另一个说法
- Rename a file or directory.
- int rename(
- const char *oldname,
- const char *newname
- );
- int _wrename(
- const wchar_t *oldname,
- const wchar_t *newname
- );
- Parameters
- oldname
- Pointer to old name.
- newname
- Pointer to new name.
- Return Value
- Each of these functions returns 0 if it is successful. On an error, the function returns a nonzero value and sets errno to one of the following values:
- EACCES
- File or directory specified by newname already exists or could not be created (invalid path); or oldname is a directory and newname specifies a different path.
- ENOENT
- File or path specified by oldname not found.
- EINVAL
- Name contains invalid characters.
- For other possible return values, see _doserrno, _errno, syserrlist, and _sys_nerr.
复制代码
从这个说明来看,如果目标文件是存在,rename函数会返回错误,两者的说明似乎有冲突,不知道是怎么回事呢 |
最佳答案
查看完整内容
The rename function causes the file whose name is the string pointed to by old to behenceforth known by the name given by the string pointed to by new. The file namedold is no longer accessible by that name. If a file named by the string pointed to by new exists prior to the call to the rename function, the behavior is implementation-defined.ISO C99 p267
|