求getcwd函数源码解决办法
求getcwd函数源码
不需要全路径,只需要获得当前运行程序的目录名就行,
想看一下源码怎么实现的,system调用?
------解决方案--------------------
引用赵老师的话“单步调试和设断点调试是程序员必须掌握的技能之一。”
打断点,跟进去。windows下就是,主要就是调用GetFullPathName这个api
------解决方案--------------------
先
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\getcwd.c
不需要全路径,只需要获得当前运行程序的目录名就行,
想看一下源码怎么实现的,system调用?
------解决方案--------------------
引用赵老师的话“单步调试和设断点调试是程序员必须掌握的技能之一。”
打断点,跟进去。windows下就是,主要就是调用GetFullPathName这个api
------解决方案--------------------
先
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\getcwd.c
...
/***
*_TSCHAR *_getdcwd(drive, pnbuf, maxlen) - get c.w.d. for given drive
*
*Purpose:
* _getdcwd gets the current working directory for the user,
* placing it in the buffer pointed to by pnbuf. It returns
* the length of the string put in the buffer. If the length
* of the string exceeds the length of the buffer, maxlen,
* then NULL is returned. If pnbuf = NULL, maxlen is ignored,
* and a buffer is automatically allocated using malloc() --
* a pointer to which is returned by _getdcwd().
*
* side effects: no global data is used or affected
*
*Entry:
* int drive - number of the drive being inquired about
* 0 = default, 1 = 'a:', 2 = 'b:', etc.
* _TSCHAR *pnbuf - pointer to a buffer maintained by the user;
* int maxlen - length of the buffer pointed to by pnbuf;
*
*Exit:
* Returns pointer to the buffer containing the c.w.d. name
* (same as pnbuf if non-NULL; otherwise, malloc is
* used to allocate a buffer)
*
*Exceptions:
*
*******************************************************************************/
_TSCHAR * __cdecl _tgetdcwd (
int drive,
_TSCHAR *pnbuf,
int maxlen
)
{
_TSCHAR *retval;
_mlock( _ENV_LOCK );
__try {
retval = _tgetdcwd_nolock(drive, pnbuf, maxlen);
}
_finally {
_munlock( _ENV_LOCK );
}