Get the equivalent of GetModuleFileName on Linux
来源:互联网 发布:努比亚z9miniroot软件 编辑:程序博客网 时间:2024/05/22 11:37
GetModuleFileName is a windows API,
which is used to retrieves the fully qualified path for the file that contains the specified module.
The module must have been loaded by the current process.
On Linux SUSE, you can choose to use the following code block:
TCHAR tUserProfile[_MAX_PATH] = {0};char cUserProfile[_MAX_PATH] = {0};readlink("/proc/self/exe", cUserProfile,_MAX_PATH);long nBytesConverted = mbstowcs (tUserProfile, cUserProfile, _MAX_PATH);tUserProfile [nBytesConverted] = _T('\0');
If your Module is a DLL, you can use the code below. It can also be applied to exe.
long_GetModuleFileName (TCHAR *exeName,long maxLen){char sLine[1024*2] = { 0 };void* pSymbol = (void*)"";long nBytesConverted = 0;FILE *fp = fopen ("/proc/self/maps", "r");if ( fp != NULL ){while( !feof (fp) ){if ( !fgets (sLine, sizeof (sLine), fp))continue;if ( !strstr (sLine, " r-xp ") || !strchr (sLine, '/'))continue;unsigned long start = 0, end = 0;sscanf (sLine, "%lx-%lx ", &start, &end);if (pSymbol >= (void *) start && pSymbol < (void *) end){char* pPath = strchr (sLine, '/');char* tmp = strrchr (pPath, '\n');if (tmp) *tmp = 0;nBytesConverted = mbstowcs (exeName, pPath, maxLen); exeName [nBytesConverted] = _T('\0'); break;}}fclose (fp);} return nBytesConverted;}
- Get the equivalent of GetModuleFileName on Linux
- the equivalent of _vscprintf && _vscwprintf under Linux
- The Clojure (or Lisp) Equivalent of a Compound Boolean Test
- Linux:Failed to get exclusive lock on the configuration file
- To get the tree list of the objects on which an object depends
- Get on the D-BUS
- The pre-installation of RAC 11g on linux
- enlarge the space of linux based on vmware
- Trick on the Version Magic Number of Linux Kernel
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- get the position of mouse base on IE and Fire fox
- Get the 48×48 or 256×256 icon of a file on Windows
- Get to the Top on Google: Tips and Techniques to Get Your Site to the Top of the Search Engine Ranki
- Linux Equivalent Project
- get the offset of field
- Get the frame of app
- Get the center of contour
- 10位以内二进制数字转十进制计算器(Printing the Decimal Equivalent of a Binary Number)
- 【算法练习】数组排序
- Android控件复习
- Get UUID on SUSE OS
- BIOS与CMOS
- 注意,tcpcopy 0.5版本和tcpcopy 0.4版本用法有很大的差别,而tcpcopy 1.0和tcpcopy 0.9差别也非常大
- Get the equivalent of GetModuleFileName on Linux
- 有了vb.net,C#就是个鸡肋
- VC 中使用内存映射文件处理大文件
- Linux内核中kzalloc函数详解
- 学期小结5:大三上学期
- .net多项目开发
- Get Linux Version
- 《5S活动推广与实施》读书笔记
- JS学习 面向对象