LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 583|回复: 2

关于文件/usr/include/string.h

[复制链接]
发表于 2004-5-14 22:22:53 | 显示全部楼层 |阅读模式
我的系统是RH8.0,内核为2.4.18-14。

在文件/usr/include/string.h中有这么一段:


  1. __BEGIN_NAMESPACE_STD
  2. /* Return a string describing the meaning of the `errno' code in ERRNUM.          */
  3. extern char *strerror (int __errnum) __THROW;
  4. __END_NAMESPACE_STD
  5. #if defined __USE_XOPEN2K || defined __USE_MISC
  6. /* Reentrant version of `strerror'.  If a temporary buffer is required,
  7. * at most BUFLEN bytes of BUF will be used.  */
  8. extern char *strerror_r (int __errnum, char *__buf, size_t __buflen) __T        HROW;
  9. #endif
复制代码


我不知函数strerror这个函数具体在哪、怎么实现的?

请指教,谢谢!!
发表于 2004-5-15 01:52:45 | 显示全部楼层
这是库函数,
  1. /* strerror()
  2. Convert an error number to an error message
  3. #include <string.h>
  4. char* strerror( int errnum );
  5. The strerror() function maps the error number contained in errnum to an
  6. error message. This function works for any valid errno value.
  7. Returns:
  8. A pointer to the error message. Don't modify the string it points to.
  9. */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <errno.h>
  13. #include <stdlib.h>
  14. int main( void )
  15. {
  16.     FILE *fp;
  17.     fp = fopen( "file.name", "r" );
  18.     if( fp == NULL ) {
  19.         printf( "Unable to open file: %s\n",
  20.             strerror( errno ) );
  21.     }
  22.     return (0);
  23. }
复制代码
 楼主| 发表于 2004-5-15 07:36:22 | 显示全部楼层
哦,是这样!谢谢啊!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表