linux如何查看库函数源代码

周靖峰 2013-06-17 06:28:22
例如我想在Ubuntu下面查看fopen这个函数的源代码,我应该怎么做呢?
...全文
898 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kileny 2015-07-13
  • 打赏
  • 举报
回复
同求解,你现在解决吗,如果有的话给我连接,谢谢!
周靖峰 2013-06-21
  • 打赏
  • 举报
回复
源代码包去哪个网站下载呢?求指教啊
sevk 2013-06-18
  • 打赏
  • 举报
回复
输入 man fopen 就有. 因为应系统默认安装了这个包: apt-get install manpages-posix-dev ~$ locate fopen /usr/lib/perl/5.14.2/auto/POSIX/fopen.al /usr/share/man/man3/fopen.3.gz /usr/share/man/man3/fopen.3posix.gz /usr/share/man/man3/fopencookie.3.gz ~$ dpkg -S /usr/share/man/man3/fopen.3posix.gz manpages-posix-dev: /usr/share/man/man3/fopen.3posix.gz
赵4老师 2013-06-18
  • 打赏
  • 举报
回复
建议换windows更容易看fopen的源码: 先 http://www.microsoft.com/visualstudio/chs/downloads#d-2010-express 点开Visual C++ 2010 Express下面的语言选‘简体中文’,再点立即安装 再参考C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\fopen.c
/***
*fopen.c - open a file
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       defines fopen() and _fsopen() - open a file as a stream and open a file
*       with a specified sharing mode as a stream
*
*******************************************************************************/

#include <cruntime.h>
#include <stdio.h>
#include <share.h>
#include <dbgint.h>
#include <internal.h>
#include <mtdll.h>
#include <file2.h>
#include <tchar.h>
#include <errno.h>

/***
*FILE *_fsopen(file, mode, shflag) - open a file
*
*Purpose:
*       Opens the file specified as a stream.  mode determines file mode:
*       "r": read       "w": write      "a": append
*       "r+": read/write                "w+": open empty for read/write
*       "a+": read/append
*       Append "t" or "b" for text and binary mode. shflag determines the
*       sharing mode. Values are the same as for sopen().
*
*Entry:
*       char *file - file name to open
*       char *mode - mode of file access
*
*Exit:
*       returns pointer to stream
*       returns NULL if fails
*
*Exceptions:
*
*******************************************************************************/

FILE * __cdecl _tfsopen (
        const _TSCHAR *file,
        const _TSCHAR *mode
        ,int shflag
        )
{
    REG1 FILE *stream=NULL;
    REG2 FILE *retval=NULL;

    _VALIDATE_RETURN((file != NULL), EINVAL, NULL);
    _VALIDATE_RETURN((mode != NULL), EINVAL, NULL);
    _VALIDATE_RETURN((*mode != _T('\0')), EINVAL, NULL);

    /* Get a free stream */
    /* [NOTE: _getstream() returns a locked stream.] */

	if ((stream	= _getstream())	== NULL)
	{
		errno =	EMFILE;
		return(NULL);
	}

	__try {
		/* We deliberately don't hard-validate for emptry strings here. All other invalid
		path strings are treated as	runtime	errors by the inner	code in	_open and openfile.
		This is	also the appropriate treatment here. Since fopen is	the	primary	access point
		for	file strings it	might be subjected to direct user input	and	thus must be robust	to
		that rather	than aborting. The CRT and OS do not provide any other path	validator (because
		WIN32 doesn't allow such things to exist in full generality).
		*/

		if(*file==_T('\0'))
		{
			errno=EINVAL;
			return NULL;
		}

		/* open	the	stream */
#ifdef _UNICODE
		retval = _wopenfile(file,mode,shflag,stream);
#else  /* _UNICODE */
		retval = _openfile(file,mode,shflag,stream);
#endif	/* _UNICODE	*/

	}
	__finally {
		_unlock_str(stream);
	}

	return(retval);
}


/***
*FILE *fopen(file, mode) - open	a file
*
*Purpose:
*		Opens the file specified as	a stream.  mode	determines file	mode:
*		"r": read       "w": write      "a": append
*		"r+": read/write                "w+": open empty for read/write
*		"a+": read/append
*		Append "t" or "b" for text and binary mode
*
*Entry:
*		char *file - file name to open
*		char *mode - mode of file access
*
*Exit:
*		returns	pointer	to stream
*		returns	NULL if	fails
*
*Exceptions:
*
*******************************************************************************/

FILE * __cdecl _tfopen (
		const _TSCHAR *file,
		const _TSCHAR *mode
		)
{
		return(	_tfsopen(file, mode, _SH_DENYNO) );
}

/***
*errno_t _tfopen_s(pfile, file,	mode) -	open a file
*
*Purpose:
*		Opens the file specified as	a stream.  mode	determines file	mode:
*		"r": read       "w": write      "a": append
*		"r+": read/write                "w+": open empty for read/write
*		"a+": read/append
*		Append "t" or "b" for text and binary mode
*		This is	the	secure version fopen - it opens	the	file in	_SH_DENYRW
*		share mode.
*
*Entry:
*		FILE **pfile - Pointer to return the FILE handle into.
*		char *file - file name to open
*		char *mode - mode of file access
*
*Exit:
*		returns	0 on success & sets	pfile
*		returns	errno_t	on failure.
*
*Exceptions:
*
*******************************************************************************/

errno_t	__cdecl	_tfopen_s (
		FILE **	pfile,
		const _TSCHAR *file,
		const _TSCHAR *mode
		)
{
		_VALIDATE_RETURN_ERRCODE((pfile	!= NULL), EINVAL);
		*pfile = _tfsopen(file,	mode, _SH_SECURE);

		if(*pfile != NULL)
			return 0;

		return errno;
}
周靖峰 2013-06-18
  • 打赏
  • 举报
回复
求教各位大神,源码包的网址能不能提供一下,小弟百度出来的gnu libc没有源代码
自信男孩 2013-06-18
  • 打赏
  • 举报
回复
这个需要下载源码包,在镜像系统里你是找不到源码的,找到的是源码生成的库。
Dobzhansky 2013-06-17
  • 打赏
  • 举报
回复
http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=io/open.c;hb=HEAD
whizer 2013-06-17
  • 打赏
  • 举报
回复
下载一个gnu libc源代码库。然后在里面查。
Carl_CCC 2013-06-17
  • 打赏
  • 举报
回复
查看fopen不用内核,在gun libc里面实现,把这个源代码包下下来就可以了。
LouisScola 2013-06-17
  • 打赏
  • 举报
回复
下载Linux内核,然后搞个ctags

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧