Windows, Unix and ANSI C API Comparison


1. I/O

1. 1 File & Directory


SubjectWindowsUNIXC LibraryComments
Console I/OAllocConsoleterminal I/ON/A 
Console I/OFreeConsoleterminal I/ON/A 
Console I/OReadConsolereadgetc, scanf, gets 
Console I/OSetConsoleModeioctlN/A 
Console I/OWriteConsolewriteputc, printf, puts 
Directory MgtCreateDirectorymkdir*N/AMake a new directory
Directory MgtFindCloseclosedir*N/AClose a directory search handle
Directory MgtFindFirstFileopendir*, readdir*N/AFind first file matching a pattern
Directory MgtFindNextFilereaddir*N/AFind subsequent files
Directory MgtGetCurrentDirectorygetcwd*N/A 
Directory MgtGetFullPathNameN/AN/A 
Directory MgtGetSystemDirectoryWell-known pathnamesN/A 
Directory MgtRemoveDirectoryrmdir, unlink*remove 
Directory MgtSearchPathUse opendir, readdirN/ASearch for a file on a specified path
Directory MgtSetCurrentDirectorychdir*, fchdirN/AChange the working directory
Error HandlingFormatMessagestrerrorperror 
Error HandlingGetLastErrorerrnoerrnoGlobal variable
Error HandlingSetLastErrorerrnoerrnoGlobal variable
File LockingLockFilefcntl (cmd=F_GETLK, ..)N/A 
File LockingLockFileExfcntl (cmd=F_GETLK, ..)N/A 
File LockingUnlockFilefcntl (cmd=F_GETLK, ..)N/A 
File LockingUnlockFileExfcntl (cmd=F_GETLK, ..)N/A 
File SystemCloseHandle (file handle)close*fcloseCloseHandle is not limited to files
File SystemCopyFileopen; read; write; closefopen; fread; fwrite; fcloseDuplicate a file
File SystemCreateFileopen*, creat*fopenOpen/create a file
File SystemDeleteFileunlink*removeDelete a file
File SystemFlushFileBuffersfsynchfflushWrite file buffers
File SystemGetFileAttributesstat*, fstat*, lstatN/A 
File SystemGetFileInformationByHandlestat*, fstat*, lstatN/AFill structure with file info
File SystemGetFileSizestat*, fstat*, lstatftell, fseekGet length of file in bytes
File SystemGetFileTimestat*, fstat*, lstatN/A 
File SystemGetFileTypestat*, fstat*, lstatN/ACheck for character stream device or file
File SystemGetStdHandleUse file desc 0, 1, or 2Use stdinstdout,stderr 
File SystemGetTempFileNameUse C librarytmpnamCreate a unique file name
File SystemGetTempFileName, CreateFileUse C librarytmpfileCreate a temporary file
File SystemGetTempPath/temp pathN/ADirectory for temp files
File SystemMoveFile, MoveFileExUse C libraryrenameRename a file or directory
File SystemCreateHardLinklink, unlink*N/AWindows does not support links
File SystemN/AsymlinkN/ACreate a symbolic link
File SystemN/AreadlinkN/ARead name in a symbolic link
File SystemN/A, ReadFile returns 0 bytesN/A, read returns 0 bytesfeofRest for end of file
File SystemN/A, use multiple ReadFilesreadvN/A, use multiplefreadsScatter read
File SystemN/A, use multiple WriteFileswritevN/A, use multiplefwritesGather write
File SystemReadFilereadfreadRead data from a file
File SystemSetEndOfFilechsize*N/A 
File SystemSetFileAttributesfcntlN/A 
File SystemSetFilePointerlseekfseekSet file pointer
FileSystemSetFilePointer (to 0)lseek (0)rewind 
File SystemSetFileTimeutime*N/A 
File SystemSetStdHandleclose, dup*,dup2*, or fcntlfreopendup2 or fcntl
File SystemWriteFilewritefwriteWrite data to a file

1.2 Async I/O

SubjectWindowsUNIXC LibraryComments
Asynch I/OGetOverlappedResultN/AN/A 
Asynch I/OReadFileExN/AN/AExtended I/O with completion routine
Asynch I/OSleepExN/AN/AAlertable wait
Asynch I/OWaitForMultipleObjects (file handles)poll, selectN/A 
Asynch I/OWaitForMultipleObjectsExN/AN/AAlertable wait
Asynch I/OWriteFileExN/AN/AExtended I/O with completion routine
Asynch I/OWaitForSingleObjectExwaitpidN/AAlertable wait

2. Memory & DLL

SubjectWindowsUNIXC Library
Mapped FilesCreateFileMappingshmgetN/A
Mapped FilesMapViewOfFilemmap, shmatN/A
Mapped FilesMapViewOfFileExmmap, shmatN/A
Mapped FilesOpenFileMappingshmgetN/A
Mapped FilesUnmapViewOfFilemunmap, shmdt, shmctlN/A
Memory MgtGetProcessHeapN/AN/A
Memory MgtGetSystemInfoN/AN/A
Memory MgtHeapAllocsbrkbrk, or C librarymalloc, calloc
Memory MgtHeapCreateN/AN/A
Memory MgtHeapDestroyN/AN/A
Memory MgtHeapFreeUse C libraryfree
Memory MgtHeapReAllocUse C libraryrealloc
Memory MgtHeapSizeN/AN/A
Shared MemoryCloseHandle (map handle)shmctlN/A
Shared MemoryCreateFileMapping, OpenFileMappingshmgetN/A
Shared MemoryMapViewOfFileshmatN/A
Shared MemoryUnmapViewOfFileshmdtN/A
DLLsLoadLibrarydlopenN/A
DLLsFreeLibrarydlcloseN/A
DLLsGetProcAddressdlsynN/A
DLLsDllMainpthread_onceN/A

3. Process & Thread

3.1 Process


SubjectWindowsUNIXC LibraryComments
Process MgtCreateProcessfork (); execl ()*, system()N/AThere are 6 execxxfunctions
Process MgtExitProcess_exitexit 
Process MgtGetCommandLineargv []argv [] 
Process MgtGetCurrentProcessgetpid*N/A 
Process MgtGetCurrentProcessIdgetpid*N/A 
Process MgtGetEnvironmentStringsN/Agetenv 
Process MgtGetEnvironmentVariableN/Agetenv 
Process MgtGetExitCodeProcesswait, waitpidN/A 
Process MgtGetProcessTimestimes, wait3, wait4N/A 
Process MgtGetProcessWorkingSetSizewait3, wait4N/A 
Process MgtN/Aexecl*, execv*, execle*, execve*, execlp*, execvp*N/AWindows does not have a direct equivalent
Process MgtN/Afork, vforkN/AWindows does not have a direct equivalent
Process MgtN/AgetppidN/ANo parent/child relationships in Windows
Process MgtN/Agetgid, getegidN/ANo process groups in Windows
Process MgtN/AgetpgrpN/A 
Process MgtN/AsetpgidN/A 
Process MgtN/AsetsidN/A 
Process MgtN/AtcgetpgrpN/A 
Process MgtN/AtcsetpgrpN/A 
Process MgtOpenProcessN/AN/A 
Process MgtSetEnvironmentVariableputenvN/Aputenv is not part of the Standard C library
Process MgtTerminateProcesskillN/A 
Synch: ProcessWaitForMultipleObjects(process handles)waitpidN/A 
Synch: ProcessWaitForSingleObject(process handle)wait, waitpidN/A 
TimersKillTimeralarm (0)N/A 
TimersSetTimeralarmN/A 
TimersSleepsleepN/A 
TimersSleeppoll or select, no file descriptorN/A 

3.2 Thread

SubjectWindowsUNIX/PthreadsComments
Thread MgtCreateRemoteThreadN/A 
TLSTlsAllocpthread_key_alloc 
TLSTlsFreepthread_key_delete 
TLSTlsGetValuepthread_getspecific 
TLSTlsSetValuepthread_setspecific 
Thread MgtCreateThread, _beginthreadexpthread_create 
Thread MgtExitThread, _endthreadexpthread_exit 
Thread MgtGetCurrentThreadpthread_self 
Thread MgtGetCurrentThreadIdN/A 
Thread MgtGetExitCodeThreadpthread_yield 
Thread MgtResumeThreadN/A 
Thread MgtSuspendThreadN/A 
Thread MgtTerminateThreadpthread_cancelpthread_cancel is safer
Thread MgtWaitForSingleObject(thread handle)pthread_join 
Thread PriorityGetPriorityClasspthread_attr_getschedpolicy, getpriority 
Thread PriorityGetThreadPrioritypthread_attr_getschedparam 
Thread PrioritySetPriorityClasspthread_attr_setschedpolicy, setpriority, nice 
Thread PrioritySetThreadPrioritypthread_attr_setschedparam 
Note: Pthreads, while a part of all modern UNIX offerings, are available on non-UNIX systems as well.

3.3 Synchronization

SubjectWindowsUNIX/PthreadsComments
Synch: CritSecDeleteCriticalSectionUse mutexes to emulate critical sections. Some systems provide proprietary equivalents.C library is not applicable
Synch: CritSecEnterCriticalSectionC library is not applicable
Synch: CritSecInitializeCriticalSection 
Synch: CritSecLeaveCriticalSection 
Synch: EventCloseHandle (event handle)pthread_cond_destroy 
Synch: EventCreateEventpthread_cond_init 
Synch: EventPulseEventpthread_cond_signalManual-reset event
Synch: EventResetEventN/A 
Synch: EventSetEventpthread_cond_broadcastAuto-reset event
Synch: EventWaitForSingleObject (event handle)pthread_cond_wait 
Synch: EventWaitForSingleObject (event handle)pthread_timed_wait 
Synch: MutexCloseHandle (mutex handle)pthread_mutex_destroy 
Synch: MutexCreateMutexpthread_mutex_init 
Synch: MutexReleaseMutexpthread_mutex_unlock 
Synch: MutexWaitForSingleObject(mutex handle)pthread_mutex_lock 
Synch: SemCreateSemaphoresemget 
Synch: SemN/AsemctlWindows does not directly support all these options
Synch: SemOpenSemaphoresemget 
Synch: SemReleaseSemaphoresemop (+) 
Synch: SemWaitForSingleObject(semaphore handle)semop (-)Windows can wait for only one count

3.4 IPC

SubjectWindowsUNIXC LibraryComments
IPCCallNamedPipeN/AN/ACreateFile, WriteFile, ReadFile, CloseHandle
IPCCloseHandle (pipe handle)close, msgctlpcloseNot part of the Standard C library—see Stevens
IPCConnectNamedPipeN/AN/A 
IPCCreateMailslotN/AN/A 
IPCCreateNamedPipemkfifo, msggetN/A 
IPCCreatePipepipepopenNot part of the Standard C library—see Stevens
IPCDuplicateHandledup, dup2, orfcntlN/AOr use file names CONIN$CONOUT$
IPCGetNamedPipeHandleStatestat, fstat, lstat64N/A 
IPCGetNamedPipeInfostat, fstat, lstatN/A 
IPCImpersonateNamedPipeClientN/AN/A 
IPCPeekNamedPipeN/AN/A 
IPCReadFile (named pipe handle)read (fifo), msgsndN/A 
IPCRevertToSelfN/AN/A 
IPCSetNamedPipeHandleStateN/AN/A 
IPCTransactNamedPipeN/AN/AWriteFile; ReadFile
IPCWriteFile (named pipe handle)write (fifo), msgrcvN/A 
Misc.GetComputerNameunameN/A 
Misc.SetComputerNameN/AN/A 
SecuritySetNamedPipeIdentityUse directory sticky bitN/A 

4. Misc

4.1 Security

SubjectWindowsUNIXComments
SecurityAddAccessAllowedAcechmod, fchmodC library does not support security

SecurityAddAccessDeniedAcechmod, fchmod
SecurityAddAuditAceN/A
SecurityCreatePrivateObjectSecurityN/A
SecurityDeleteAcechmod, fchmod
SecurityDestroyPrivateObjectSecurityN/A
SecurityGetAcestat*, fstat*, lstat
SecurityGetAclInformationstat*, fstat*, lstat
SecurityGetFileSecuritystat*, fstat*, lstat
SecurityGetPrivateObjectSecurityN/A
SecurityGetSecurityDescriptorDaclstat*, fstat*, lstat
SecurityGetUserNamegetlogin
SecurityInitializeAclN/A
SecurityInitializeSecurityDescriptorUmask
SecurityLookupAccountNamegetpwnam, getgrnam
SecurityLookupAccountSidgetpwuid, getuid, geteuid
SecurityN/Agetpwend, setpwent, endpwent
SecurityN/Agetgrent, setgrent, endgrent
SecurityN/ASetuid, seteuid, setreuid
SecurityN/ASetgid, setegid, setregid
SecurityOpenProcessTokengetgroups, setgroups, initgroups
SecuritySetFileSecuritychmod*, fchmod
SecuritySetPrivateObjectSecurityN/A
SecuritySetSecurityDescriptorDaclUmask
SecuritySetSecurityDescriptorGroupchown, fchown, lchown
SecuritySetSecurityDescriptorOwnerchown, fchown, lchown
SecuritySetSecurityDescriptorSaclN/A

4.2 Exception Handling

SubjectWindowsUNIXC Library
SEH_try – _exceptUse C library signalsUse C library signals
SEH_try – _finallyUse C library signalsUse C library signals
SEHAbnormalTerminationUse C library signalsUse C library signals
SEHGetExceptionCodeUse C library signalsUse C library signals
SEHRaiseExceptionUse C library signalssignal, raise
SignalsUse _finally blockUse C libraryatexit
SignalsUse C library or terminate processkillraise
SignalsUse C libraryUse C librarysignal
SignalsUse SEH, VEHsigemptysetN/A
SignalsUse SEH, VEHsigfillsetN/A
SignalsUse SEH, VEHsigaddsetN/A
SignalsUse SEH, VEHsigdelsetN/A
SignalsUse SEH, VEHsigismemberN/A
SignalsUse SEH, VEHsigprocmaskN/A
SignalsUse SEH, VEHsigpendingN/A
SignalsUse SEH, VEHsigactionN/A
SignalsUse SEH, VEHsigsetjmpN/A
SignalsUse SEH, VEHsiglongjmpN/A
SignalsUse SEH, VEHsigsuspendfN/A
SignalsUse SEH, VEHpsignalN/A
SignalsUse SEH, VEH, or C libraryUse C libraryabort
Note: Many UNIX vendors provide proprietary exception handling capabilities.

4.3 System Information & Time

SubjectWindowsUNIXC LibraryComments
System InfoGetDiskFreeSpaceN/AN/A 
System InfoGetSystemInfogetrusageN/A 
System InfoGetVersionunameN/A 
System InfoGetVolumeInformationN/AN/A 
System InfoGlobalMemoryStatusgetrlimitN/A 
System InfoVarious defined constantssysconf, pathconf, fpathconfN/A 
TimeGetSystemTimeUse C librarytime, gmtime 
TimeSee ls program, 
Use C libraryasctime 
TimeCompareFileTimeUse C librarydifftimeCompare "calendar" times
TimeFileTimeToLocalFileTime, FileTimeToSystemTimeUse C librarylocaltime 
TimeFileTimeToSystemTimeUse C librarygmtime 
TimeGetLocalTimeUse C librarytime, localtime 
TimeSee touch program, 
Use C librarystrftime 
TimeSetLocalTimeN/AN/A 
TimeSetSystemTimeN/AN/A 
TimeSubtract file timesUse C librarydifftime 
TimeSystemTimeToFileTimeUse C librarymktime 

from: http://blogs.msdn.com/b/csliu/archive/2009/03/20/windows-unix-and-ansi-c-api-comparison.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值