Command line args
- linux
argc argv env on stack.
- win32
LPTSTR WINAPI GetCommandLine(void);
Exit code
- linux
exit syscall or int 80.
- win32
ExitProcess or ret.
Library
dlopen : filename — handle
- linux
void *dlopen(const char *filename, int flag); Returns NULL on error.
- win32
HMODULE WINAPI LoadLibrary( _in_ LPCTSTR lpFileName); Returns NULL on error.
dlsym : symbol handle — addr
- linux
void *dlsym(void *handle, const char* symbol); NULL doesn't indicate error (clear dlerror before call and compare).
- win32
FARPROC WINAPI GetProcAddress( _in_ HMODULE hModule, _in_ LPCSTR lpProcName); Returns NULL on error (GetLastError).
dlclose : handle — flag
- linux
int dlclose(void *handle); Returns nonzero on error.
- win32
BOOL WINAPI CloseHandle( _in_ HANDLE hObject); Returns 0 on error (GetLastError).
dlerror : — n
- linux
char *dlerror(void); Returns message or NULL.
- win32
DWORD WINAPI GetLastError(void); Returns last error code.
Memory
malloc : size — handle
- linux
void *malloc(size_t size); Returns NULL on error.
- win32
LPVOID WINAPI VirtualAlloc( _in_opt_ LPVOID lpAddress, _in_ SIZE_T dwSize, _in_ DWORD flAllocationType, _in_ DWORD flProtect); Returns NULL on error (GetLastError).
mfree : handle — flag
- linux
void free(void *ptr); Returns nothing.
- win32
BOOL WINAPI VirtualFree( _in_ LPVOID lpAddress, _in_ SIZE_T dwSize, _in_ DWORD dwFreeType); Returns 0 on error (GetLastError).
mprot : prot count addr — flag
- linux
int mprotect(void *addr, size_t len, int prot); Returns -1 on error (errno).
- win32
BOOL WINAPI VirtualProtect( _in_ LPVOID lpAddress, _in_ SIZE_T dwSize, _in_ DWORD flNewProtect, _out_ DWORD lpflOldProtect); Returns 0 on error (GetLastError).
File
fopen : mode filename — handle | -1
- linux
int open(const char *pathname, int flags); Returns -1 on error (errno).
- win32
HANDLE WINAPI CreateFile( _in_ LPCTSTR lpFileName, _in_ DWORD dwDesiredAccess, _in_ DWORD dwShareMode, _in_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _in_ DWORD dwCreationDisposition, _in_ DWORD dwFlagsAndAttributes, _in_opt_ HANDLE hTemplateFile); Returns INVALID_HANDLE_VALUE on error (GetLastError).
fread : count buffer handle — n | -1
- linux
ssize_t read(int fd, void *buf, size_t count); Returns -1 on error (errno), n bytes read (0 on EOF).
- win32
BOOL WINAPI ReadFile( _in_ HANDLE hFile, _out_ LPVOID lpBuffer, _in_ DWORD nNumberOfBytesToRead, _out_opt_ LPDWORD lpNumberOfBytesRead, _inout_opt_ LPOVERLAPPED lpOverlapped); Returns 0 on error (GetLastError).
fwrite : count buffer handle — n | -1
- linux
ssize_t write(int fd, void *buf, size_t count); Returns -1 on error (errno), n bytes written.
- win32
BOOL WINAPI WriteFile( _in_ HANDLE hFile, _out_ LPVOID lpBuffer, _in_ DWORD nNumberOfBytesToWrite, _out_opt_ LPDWORD lpNumberOfBytesWritten, _inout_opt_ LPOVERLAPPED lpOverlapped); Returns 0 on error (GetLastError).
fclose : handle — flag
- linux
int close(int fd); Returns -1 on error (errno).
- win32
BOOL WINAPI CloseHandle( _in_ HANDLE hObject); Returns 0 on error (GetLastError).