免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7589 | 回复: 9

[C] 关于rename函数的问题 [复制链接]

论坛徽章:
0
发表于 2009-05-18 17:06 |显示全部楼层
5可用积分
rename这个函数是在stdio.h里面的,照理说应该是一个c语言标准规定的函数,但是我man了一下,发现有如下的说明

  1. NAME
  2.        rename - change the name or location of a file

  3. SYNOPSIS
  4.        #include <stdio.h>

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

  6. DESCRIPTION
  7.        rename() renames a file, moving it between directories if required.

  8.        Any other hard links to the file (as created using link(2)) are unaffected.

  9.        If newpath already exists it will be atomically replaced (subject to a few conditions; see ERRORS below),
  10.        so that there is no point at which another process attempting to access newpath will find it missing.
复制代码


上面说目标文件存在时是会被替换的,但是我查了一下msdn却又是另一个说法

  1. Rename a file or directory.

  2. int rename(
  3.    const char *oldname,
  4.    const char *newname
  5. );
  6. int _wrename(
  7.    const wchar_t *oldname,
  8.    const wchar_t *newname
  9. );
  10. Parameters
  11. oldname
  12. Pointer to old name.
  13. newname
  14. Pointer to new name.
  15. Return Value
  16. 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:

  17. EACCES
  18. 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.
  19. ENOENT
  20. File or path specified by oldname not found.
  21. EINVAL
  22. Name contains invalid characters.
  23. 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

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
发表于 2009-05-18 17:06 |显示全部楼层
The rename function causes the file whose name is the string pointed to by old to be
henceforth known by the name given by the string pointed to by new. The file named
old 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

论坛徽章:
0
发表于 2009-05-18 17:19 |显示全部楼层

回复 #1 皇家救星 的帖子

自己试验一下,不就OK了?

论坛徽章:
0
发表于 2009-05-18 17:32 |显示全部楼层
谢谢LS

不知你这段话是在哪搞到的呢?

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
发表于 2009-05-18 17:34 |显示全部楼层
原帖由 OwnWaterloo 于 2009-5-18 17:06 发表
……
ISO C99 p267


这里 ……

论坛徽章:
0
发表于 2009-05-18 17:36 |显示全部楼层
我是想问在哪个网址上找到的

我想去搞全一点的说明

论坛徽章:
0
发表于 2009-05-18 17:38 |显示全部楼层
哦,,也是,,具体情况具体分析
就好像linux区分大小写而windows不区分一样。。

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
发表于 2009-05-18 17:39 |显示全部楼层

论坛徽章:
0
发表于 2009-05-18 17:41 |显示全部楼层
因为csdn人气比较旺 

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
发表于 2009-05-18 17:46 |显示全部楼层

回复 #9 皇家救星 的帖子

而且都是要分的 …… (第3个只要1分)
要分的资源我一般不下的 ……………………

莫非那时候对C99标准非常饥渴 ……
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP