Win32 Equivalents for C Run-Time FunctionsThe information in this article applies to:
SUMMARYMany of the C Run-time functions have direct equivalents in the Win32 application programming interface (API). This article lists the C Run-time functions by category with their Win32 equivalents or the word "none" if no equivalent exists. MORE INFORMATIONNOTE: the functions that are followed by an asterisk (*) are part of the 16-bit C Run-time only. Functions that are unique to the 32-bit C Run-time are listed separately in the last section. All other functions are common to both C Run-times. |
C Run time |
Win32 Equivalent |
_memccpy |
none |
memchr |
none |
memcmp |
none |
memcpy |
CopyMemory (SeeNote 6) |
_memicmp |
none |
memmove |
MoveMemory (SeeNote 6) |
memset |
FillMemory, ZeroMemory (SeeNote 6) |
_swab |
None |
C Run time |
Win32 Equivalent |
Isalnum |
IsCharAlphaNumeric |
Isalpha |
IsCharAlpha, GetStringTypeW (Unicode) |
__isascii |
None |
iscntrl |
None, GetStringTypeW (Unicode) |
__iscsym |
None |
__iscsymf |
None |
isdigit |
None, GetStringTypeW (Unicode) |
isgraph |
None |
islower |
IsCharLower, GetStringTypeW (Unicode) |
isprint |
None |
ispunct |
None, GetStringTypeW (Unicode) |
isspace |
None, GetStringTypeW (Unicode) |
isupper |
IsCharUpper, GetStringTypeW (Unicode) |
isxdigit |
None, GetStringTypeW (Unicode) |
__toascii |
None |
tolower |
CharLower |
_tolower |
None |
toupper |
CharUpper |
_toupper |
None |
C Run time |
Win32 Equivalent |
_chdir |
SetCurrentDirectory |
_chdrive |
SetCurrentDirectory |
_getcwd |
GetCurrentDirectory |
_getdrive |
GetCurrentDirectory |
_mkdir |
CreateDirectory |
_rmdir |
RemoveDirectory |
_searchenv |
SearchPath |
C Run time |
Win32 Equivalent |
_access |
none |
_chmod |
SetFileAttributes |
_chsize |
SetEndOfFile |
_filelength |
GetFileSize |
_fstat |
SeeNote 5 |
_fullpath |
GetFullPathName |
_get_osfhandle |
none |
_isatty |
GetFileType |
_locking |
LockFileEx |
_makepath |
none |
_mktemp |
GetTempFileName |
_open_osfhandle |
None |
remove |
DeleteFile |
rename |
MoveFile |
_setmode |
None |
_splitpath |
None |
_stat |
None |
_umask |
None |
_unlink |
DeleteFile |
C Run time |
Win32 Equivalent |
_displaycursor* |
SetConsoleCursorInfo |
_gettextcolor* |
GetConsoleScreenBufferInfo |
_gettextcursor* |
GetConsoleCursorInfo |
_gettextposition* |
GetConsoleScreenBufferInfo |
_gettextwindow* |
GetConsoleWindowInfo |
_outtext* |
WriteConsole |
_scrolltextwindow* |
ScrollConsoleScreenBuffer |
_settextcolor* |
SetConsoleTextAttribute |
_settextcursor* |
SetConsoleCursorInfo |
_settextposition* |
SetConsoleCursorPosition |
_settextwindow* |
SetConsoleWindowInfo |
_wrapon* |
SetConsoleMode |
C Run time |
Win32 Equivalent |
clearerr |
none |
fclose |
CloseHandle |
_fcloseall |
none |
_fdopen |
none |
feof |
none |
ferror |
none |
fflush |
FlushFileBuffers |
fgetc |
none |
_fgetchar |
none |
fgetpos |
none |
fgets |
none |
_fileno |
none |
_flushall |
none |
fopen |
CreateFile |
fprintf |
none |
fputc |
none |
_fputchar |
none |
fputs |
none |
fread |
ReadFile |
freopen (std handles) |
SetStdHandle |
fscanf |
None |
fseek |
SetFilePointer |
fsetpos |
SetFilePointer |
_fsopen |
CreateFile |
ftell |
SetFilePointer (check return value) |
fwrite |
WriteFile |
getc |
None |
getchar |
None |
gets |
None |
_getw |
None |
printf |
None |
putc |
None |
putchar |
None |
puts |
None |
_putw |
None |
rewind |
SetFilePointer |
_rmtmp |
None |
scanf |
None |
setbuf |
None |
setvbuf |
None |
_snprintf |
None |
sprintf |
Wsprintf |
sscanf |
None |
_tempnam |
GetTempFileName |
tmpfile |
None |
tmpnam |
GetTempFileName |
ungetc |
None |
vfprintf |
None |
vprintf |
None |
_vsnprintf |
None |
vsprintf |
Wvsprintf |
C Run time |
Win32 Equivalent |
_close |
_lclose, CloseHandle |
_commit |
FlushFileBuffers |
_creat |
_lcreat, CreateFile |
_dup |
DuplicateHandle |
_dup2 |
none |
_eof |
none |
_lseek |
_llseek, SetFilePointer |
_open |
_lopen, CreateFile |
_read |
_lread, ReadFile |
_sopen |
CreateFile |
_tell |
SetFilePointer (check return value) |
_write |
_lread |
C Run time |
Win32 Equivalent |
_cgets |
none |
_cprintf |
none |
_cputs |
none |
_cscanf |
none |
_getch |
ReadConsoleInput |
_getche |
ReadConsoleInput |
_inp |
none |
_inpw |
none |
_kbhit |
PeekConsoleInput |
_outp |
none |
_outpw |
none |
_putch |
WriteConsoleInput |
_ungetch |
none |
C Run time |
Win32 Equivalent |
_alloca |
none |
_bfreeseg* |
none |
_bheapseg* |
none |
calloc |
GlobalAlloc |
_expand |
none |
free |
GlobalFree |
_freect* |
GlobalMemoryStatus |
_halloc* |
GlobalAlloc |
_heapadd |
none |
_heapchk |
none |
_heapmin |
none |
_heapset |
none |
_heapwalk |
none |
_hfree* |
GlobalFree |
malloc |
GlobalAlloc |
_memavl |
GlobalMemoryStatus |
_memmax |
GlobalMemoryStatus |
_msize* |
GlobalSize |
realloc |
GlobalReAlloc |
_set_new_handler |
none |
_set_hnew_handler* |
None |
_stackavail* |
None |
C Run time |
Win32 Equivalent |
abort |
none |
assert |
none |
atexit |
none |
_cexit |
none |
_c_exit |
none |
_exec functions |
none |
exit |
ExitProcess |
_exit |
ExitProcess |
getenv |
GetEnvironmentVariable |
_getpid |
GetCurrentProcessId |
Longjmp |
none |
_onexit |
none |
Perror |
FormatMessage |
_putenv |
SetEnvironmentVariable |
Raise |
RaiseException |
Setjmp |
none |
signal (ctrl-c only) |
SetConsoleCtrlHandler |
_spawn functions |
CreateProcess |
system |
CreateProcess |
C Run time |
Win32 Equivalent |
strcat, wcscat |
lstrcat |
strchr, wcschr |
none |
strcmp, wcscmp |
lstrcmp |
strcpy, wcscpy |
lstrcpy |
strcspn, wcscspn |
none |
_strdup, _wcsdup |
none |
Strerror |
FormatMessage |
_strerror |
FormatMessage |
_stricmp, _wcsicmp |
lstrcmpi |
Strlen, wcslen |
lstrlen |
_strlwr, _wcslwr |
CharLower, CharLowerBuffer |
Strncat, wcsncat |
none |
Strncmp, wcsncmp |
none |
Strncpy, wcsncpy |
none |
_strnicmp, _wcsnicmp |
none |
_strnset, _wcsnset |
FillMemory, ZeroMemory |
strpbrk, wcspbrk |
none |
strrchr, wcsrchr |
none |
_strrev, _wcsrev |
none |
_strset, _wcsset |
FillMemory, ZeroMemory |
strspn, wcsspn |
none |
strstr, wcsstr |
none |
strtok, wcstok |
none |
_strupr, _wcsupr |
CharUpper, CharUpperBuffer |
C Run time |
Win32 Equivalent |
_bdos* |
none |
_chain_intr* |
none |
_disable* |
none |
_dos_allocmem* |
GlobalAlloc |
_dos_close* |
CloseHandle |
_dos_commit* |
FlushFileBuffers |
_dos_creat* |
CreateFile |
_dos_creatnew* |
CreateFile |
_dos_findfirst* |
FindFirstFile |
_dos_findnext* |
FindNextFile |
_dos_freemem* |
GlobalFree |
_dos_getdate* |
GetSystemTime |
_dos_getdiskfree* |
GetDiskFreeSpace |
_dos_getdrive* |
GetCurrentDirectory |
_dos_getfileattr* |
GetFileAttributes |
_dos_getftime* |
GetFileTime |
_dos_gettime* |
GetSystemTime |
_dos_getvect* |
none |
_dos_keep* |
none |
_dos_open* |
OpenFile |
_dos_read* |
ReadFile |
_dos_setblock* |
GlobalReAlloc |
_dos_setdate* |
SetSystemTime |
_dos_setdrive* |
SetCurrentDirectory |
_dos_setfileattr* |
SetFileAttributes |
_dos_setftime* |
SetFileTime |
_dos_settime* |
SetSystemTime |
_dos_setvect* |
none |
_dos_write* |
WriteFile |
_dosexterr* |
GetLastError |
_enable* |
none |
_FP_OFF* |
none |
_FP_SEG* |
none |
_harderr* |
SeeNote 1 |
_hardresume* |
SeeNote 1 |
_hardretn* |
SeeNote 1 |
_int86* |
none |
_int86x* |
none |
_intdos* |
none |
_intdosx* |
none |
_segread* |
none |
C Run time |
Win32 Equivalent |
asctime |
SeeNote 2 |
clock |
SeeNote 2 |
ctime |
SeeNote 2 |
difftime |
SeeNote 2 |
_ftime |
SeeNote 2 |
_getsystime |
GetLocalTime |
gmtime |
SeeNote 2 |
localtime |
SeeNote 2 |
mktime |
SeeNote 2 |
_strdate |
SeeNote 2 |
_strtime |
SeeNote 2 |
time |
SeeNote 2 |
_tzset |
SeeNote 2 |
_utime |
SetFileTime |
C Run time |
Win32 Equivalent |
_vfree* |
SeeNote 3 |
_vheapinit* |
SeeNote 3 |
_vheapterm* |
SeeNote 3 |
_vload* |
SeeNote 3 |
_vlock* |
SeeNote 3 |
_vlockcnt* |
SeeNote 3 |
_vmalloc* |
SeeNote 3 |
_vmsize* |
SeeNote 3 |
_vrealloc* |
SeeNote 3 |
_vunlock* |
SeeNote 3 |
C Run time |
Win32 Equivalent |
_beginthread |
CreateThread |
_cwait |
WaitForSingleObject w/ GetExitCodeProcess |
_endthread |
ExitThread |
_findclose |
FindClose |
_findfirst |
FindFirstFile |
_findnext |
FindNextFile |
_futime |
SetFileTime |
_get_osfhandle |
none |
_open_osfhandle |
none |
_pclose |
SeeNote 4 |
_pipe |
CreatePipe |
_popen |
SeeNote 4 |
_popen CreatePipe CreateProcess _pclose WaitForSingleObject CloseHandleGetFileInformationByHandle() is the Win32 equivalent for the _fstat() C Run-time function. However, GetFileInformationByHandle() is not supported by Win32s version 1.1. It is supported in Win32s 1.2. GetFileSize(), GetFileAttributes(), GetFileTime(), and GetFileTitle() are supported by Win32s 1.1 and 1.2. There are Win32 Buffer-Manipulation Routines that are actually not document but exist in kernel32.dll. Win32 functions such as FillMemory, CopyMemory, MoveMemory, and ZeroMemory are all actually macros that use the CLIB equivalents. After removing all default libraries we no longer have the CLIB, therefore we must use an alternative. RtlFillMemory, RtlMoveMemory, and RtlZeroMemory are also macros that use CLIB, although these functions actually do exist in kernel32.dll as Win32 API calls. Even though they exist they are not document and chances are that there may indeed be a reason behind that. These functions may be missing in some versions of Windows and are not support by Microsoft. A solution to this is to write your own Buffer-Manipulation Routines.
The following example is a header file that contains the source code to FillMemory, MoveMemory, CopyMemory, and ZeroMemory.
//********************************************************************** // File: buffer.h Last Modified: 03/02/01 // Modified by: PM // // Purpose: Custom Buffer-Manipulation Routines // // Developed By: Piotr Mintus 2001 //**********************************************************************#ifndef _BUFFER_H_ #define _BUFFER_H_ #ifdef FillMemory #undef FillMemory #endif #ifdef ZeroMemory #undef ZeroMemory #endif #ifdef CopyMemory #undef CopyMemory #endif #ifdef MoveMemory #undef MoveMemory #endif __forceinline void FillMemory(void *dest,unsigned __int8 c,unsigned __int32 count) { unsigned __int32 size32=count>>2; unsigned __int32 fill=(c<<24|c<<16|c<<8|c); unsigned __int32 *dest32=(unsigned __int32*)dest; switch( (count-(size32<<2)) ) { case 3: ((unsigned __int8*)dest)[count - 3] = c; case 2: ((unsigned __int8*)dest)[count - 2] = c; case 1: ((unsigned __int8*)dest)[count - 1] = c; } while( size32-- > 0 ) *(dest32++) = fill; } /* FillMemory */ #define ZeroMemory(dest,count) FillMemory(dest,0,count) __forceinline void CopyMemory(void *dest,const void *src,unsigned __int32 count) { unsigned __int32 size32=count>>2; unsigned __int32 *dest32=(unsigned __int32*)dest; unsigned __int32 *src32=(unsigned __int32*)src; switch( (count-(size32<<2)) ) { case 3: ((unsigned __int8*)dest)[count-1] = ((unsigned __int8*)src)[count-1]; case 2: ((unsigned __int8*)dest)[count-2] = ((unsigned __int8*)src)[count-2]; case 1: ((unsigned __int8*)dest)[count-3] = ((unsigned __int8*)src)[count-3]; } while( size32-- > 0 ) dest32[size32] = src32[size32]; } /* CopyMemory */ __forceinline void MoveMemory(void *dest,const void *src,unsigned __int32 count) { unsigned __int32 size32=count>>2,i; unsigned __int32 *dest32=(unsigned __int32*)dest; unsigned __int32 *src32=(unsigned __int32*)src; if( dest > src ) { switch( (count-(size32<<2)) ) { case 3: ((unsigned __int8*)dest)[count-1] = ((unsigned __int8*)src)[count-1]; case 2: ((unsigned __int8*)dest)[count-2] = ((unsigned __int8*)src)[count-2]; case 1: ((unsigned __int8*)dest)[count-3] = ((unsigned __int8*)src)[count-3]; } while( size32-- > 0 ) dest32[size32] = src32[size32]; } else { for(i=0;i<size32;i++) *(dest32++) = *(src32++); switch( (count-(size32<<2)) ) { case 3: ((unsigned __int8*)dest)[count-3] = ((unsigned __int8*)src)[count-3]; case 2: ((unsigned __int8*)dest)[count-2] = ((unsigned __int8*)src)[count-2]; case 1: ((unsigned __int8*)dest)[count-1] = ((unsigned __int8*)src)[count-1]; } } } /* MoveMemory */ #endif // _BUFFER_H_ |
Now you can freely use FillMemory, MoveMemory, CopyMemory, and ZeroMemory within your application.
Observation: The preceding source code uses the __forceinline keyword. This will achieve greater speed. If small size is desired over speed, please remove the keyword and use the preceding source as normal functions.
Bibliography:
http://www.hailstorm.net/papers/smallwin32.htm
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q99456
Download Files
The original files were compressed and can be downloaded
here (You will need Winzip to open these files - www.winzip.com)
Win32 Equivalents for C Run-Time FunctionsEdited by: Beyond2000! March, 17, 2.002 |