Sign In
Scalability Notes
[Read -> Think -> Write]
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
RSS for comments
Search
Advanced search options...
Search In:
Everything
Blogs
Forums
People
Groups
Places
Pages
Date range:
All Time
Last Year
Last 6 Months
Last 3 Months
Last Month
Last Week
Last Two Days
Tags
database
distributed system
engineering
hpc
network
parallel
scalability
search
Archive
Archives
December 2010
(1)
September 2010
(1)
August 2010
(1)
April 2010
(1)
February 2010
(2)
January 2010
(4)
December 2009
(1)
November 2009
(1)
October 2009
(1)
September 2009
(1)
August 2009
(4)
June 2009
(2)
May 2009
(1)
April 2009
(1)
March 2009
(2)
February 2009
(4)
January 2009
(1)
Windows, Unix and ANSI C API Comparison
MSDN Blogs
>
Scalability Notes
>
Windows, Unix and ANSI C API Comparison
Windows, Unix and ANSI C API Comparison
changl
20 Mar 2009 10:12 AM
Comments
1
The "
Windows System Programming
"(3E) has a great appendix about Windows, Unix, C Library API comparison. It's obvious that this appendix lacks of many APIs in Memory, DLL and Security related areas, but it is still very helpful for referencing when doing system programming on windows platform.
Original content can be found here:
http://my.safaribooksonline.com/0321256190/app02
1. I/O
1. 1 File & Directory
Subject
Windows
UNIX
C Library
Comments
Console I/O
AllocConsole
terminal I/O
N/A
Console I/O
FreeConsole
terminal I/O
N/A
Console I/O
ReadConsole
read
getc, scanf, gets
Console I/O
SetConsoleMode
ioctl
N/A
Console I/O
WriteConsole
write
putc, printf, puts
Directory Mgt
CreateDirectory
mkdir
*
N/A
Make a new directory
Directory Mgt
FindClose
closedir
*
N/A
Close a directory search handle
Directory Mgt
FindFirstFile
opendir
*
,
readdir
*
N/A
Find first file matching a pattern
Directory Mgt
FindNextFile
readdir
*
N/A
Find subsequent files
Directory Mgt
GetCurrentDirectory
getcwd
*
N/A
Directory Mgt
GetFullPathName
N/A
N/A
Directory Mgt
GetSystemDirectory
Well-known pathnames
N/A
Directory Mgt
RemoveDirectory
rmdir, unlink
*
remove
Directory Mgt
SearchPath
Use
opendir, readdir
N/A
Search for a file on a specified path
Directory Mgt
SetCurrentDirectory
chdir
*
, fchdir
N/A
Change the working directory
Error Handling
FormatMessage
strerror
perror
Error Handling
GetLastError
errno
errno
Global variable
Error Handling
SetLastError
errno
errno
Global variable
File Locking
LockFile
fcntl (cmd=F_GETLK,
..)
N/A
File Locking
LockFileEx
fcntl (cmd=F_GETLK,
..)
N/A
File Locking
UnlockFile
fcntl (cmd=F_GETLK,
..)
N/A
File Locking
UnlockFileEx
fcntl (cmd=F_GETLK,
..)
N/A
File System
CloseHandle
(file handle)
close
*
fclose
CloseHandle
is not limited to files
File System
CopyFile
open; read; write; close
fopen; fread; fwrite; fclose
Duplicate a file
File System
CreateFile
open
*
,
creat
*
fopen
Open/create a file
File System
DeleteFile
unlink
*
remove
Delete a file
File System
FlushFileBuffers
fsynch
fflush
Write file buffers
File System
GetFileAttributes
stat
*
,
fstat
*
, lstat
N/A
File System
GetFileInformationByHandle
stat
*
,
fstat
*
, lstat
N/A
Fill structure with file info
File System
GetFileSize
stat
*
,
fstat
*
, lstat
ftell, fseek
Get length of file in bytes
File System
GetFileTime
stat
*
,
fstat
*
, lstat
N/A
File System
GetFileType
stat
*
,
fstat
*
, lstat
N/A
Check for character stream device or file
File System
GetStdHandle
Use file desc 0, 1, or 2
Use
stdin
,
stdout
,
stderr
File System
GetTempFileName
Use C library
tmpnam
Create a unique file name
File System
GetTempFileName, CreateFile
Use C library
tmpfile
Create a temporary file
File System
GetTempPath
/temp path
N/A
Directory for temp files
File System
MoveFile, MoveFileEx
Use C library
rename
Rename a file or directory
File System
CreateHardLink
link,
unlink
*
N/A
Windows does not support links
File System
N/A
symlink
N/A
Create a symbolic link
File System
N/A
readlink
N/A
Read name in a symbolic link
File System
N/A,
ReadFile
returns 0 bytes
N/A,
read
returns 0 bytes
feof
Rest for end of file
File System
N/A, use multiple
ReadFile
s
readv
N/A, use multiple
freads
Scatter read
File System
N/A, use multiple
WriteFile
s
writev
N/A, use multiple
fwrites
Gather write
File System
ReadFile
read
fread
Read data from a file
File System
SetEndOfFile
chsize
*
N/A
File System
SetFileAttributes
fcntl
N/A
File System
SetFilePointer
lseek
fseek
Set file pointer
FileSystem
SetFilePointer
(to 0)
lseek (0)
rewind
File System
SetFileTime
utime
*
N/A
File System
SetStdHandle
close,
dup
*
,
dup2
*
,
or
fcntl
freopen
dup2
or
fcntl
File System
WriteFile
write
fwrite
Write data to a file
1.2 Async I/O
Subject
Windows
UNIX
C Library
Comments
Asynch I/O
GetOverlappedResult
N/A
N/A
Asynch I/O
ReadFileEx
N/A
N/A
Extended I/O with completion routine
Asynch I/O
SleepEx
N/A
N/A
Alertable wait
Asynch I/O
WaitForMultipleObjects
(file handles)
poll, select
N/A
Asynch I/O
WaitForMultipleObjectsEx
N/A
N/A
Alertable wait
Asynch I/O
WriteFileEx
N/A
N/A
Extended I/O with completion routine
Asynch I/O
WaitForSingleObjectEx
waitpid
N/A
Alertable wait
2. Memory & DLL
Subject
Windows
UNIX
C Library
Mapped Files
CreateFileMapping
shmget
N/A
Mapped Files
MapViewOfFile
mmap, shmat
N/A
Mapped Files
MapViewOfFileEx
mmap, shmat
N/A
Mapped Files
OpenFileMapping
shmget
N/A
Mapped Files
UnmapViewOfFile
munmap, shmdt, shmctl
N/A
Memory Mgt
GetProcessHeap
N/A
N/A
Memory Mgt
GetSystemInfo
N/A
N/A
Memory Mgt
HeapAlloc
sbrk
,
brk
, or C library
malloc, calloc
Memory Mgt
HeapCreate
N/A
N/A
Memory Mgt
HeapDestroy
N/A
N/A
Memory Mgt
HeapFree
Use C library
free
Memory Mgt
HeapReAlloc
Use C library
realloc
Memory Mgt
HeapSize
N/A
N/A
Shared Memory
CloseHandle
(map handle)
shmctl
N/A
Shared Memory
CreateFileMapping, OpenFileMapping
shmget
N/A
Shared Memory
MapViewOfFile
shmat
N/A
Shared Memory
UnmapViewOfFile
shmdt
N/A
DLLs
LoadLibrary
dlopen
N/A
DLLs
FreeLibrary
dlclose
N/A
DLLs
GetProcAddress
dlsyn
N/A
DLLs
DllMain
pthread_once
N/A
3. Process & Thread
3.1 Process
Subject
Windows
UNIX
C Library
Comments
Process Mgt
CreateProcess
fork ();
execl ()
*
, system()
N/A
There are 6
execxx
functions
Process Mgt
ExitProcess
_exit
exit
Process Mgt
GetCommandLine
argv []
argv []
Process Mgt
GetCurrentProcess
getpid
*
N/A
Process Mgt
GetCurrentProcessId
getpid
*
N/A
Process Mgt
GetEnvironmentStrings
N/A
getenv
Process Mgt
GetEnvironmentVariable
N/A
getenv
Process Mgt
GetExitCodeProcess
wait, waitpid
N/A
Process Mgt
GetProcessTimes
times, wait3, wait4
N/A
Process Mgt
GetProcessWorkingSetSize
wait3, wait4
N/A
Process Mgt
N/A
execl
*
, execv
*
, execle
*
, execve
*
, execlp
*
, execvp
*
N/A
Windows does not have a direct equivalent
Process Mgt
N/A
fork, vfork
N/A
Windows does not have a direct equivalent
Process Mgt
N/A
getppid
N/A
No parent/child relationships in Windows
Process Mgt
N/A
getgid, getegid
N/A
No process groups in Windows
Process Mgt
N/A
getpgrp
N/A
Process Mgt
N/A
setpgid
N/A
Process Mgt
N/A
setsid
N/A
Process Mgt
N/A
tcgetpgrp
N/A
Process Mgt
N/A
tcsetpgrp
N/A
Process Mgt
OpenProcess
N/A
N/A
Process Mgt
SetEnvironmentVariable
putenv
N/A
putenv
is not part of the Standard C library
Process Mgt
TerminateProcess
kill
N/A
Synch: Process
WaitForMultipleObjects
(process handles)
waitpid
N/A
Synch: Process
WaitForSingleObject
(process handle)
wait, waitpid
N/A
Timers
KillTimer
alarm (0)
N/A
Timers
SetTimer
alarm
N/A
Timers
Sleep
sleep
N/A
Timers
Sleep
poll
or
select
, no file descriptor
N/A
3.2 Thread
Subject
Windows
UNIX/Pthreads
Comments
Thread Mgt
CreateRemoteThread
N/A
TLS
TlsAlloc
pthread_key_alloc
TLS
TlsFree
pthread_key_delete
TLS
TlsGetValue
pthread_getspecific
TLS
TlsSetValue
pthread_setspecific
Thread Mgt
CreateThread, _beginthreadex
pthread_create
Thread Mgt
ExitThread, _endthreadex
pthread_exit
Thread Mgt
GetCurrentThread
pthread_self
Thread Mgt
GetCurrentThreadId
N/A
Thread Mgt
GetExitCodeThread
pthread_yield
Thread Mgt
ResumeThread
N/A
Thread Mgt
SuspendThread
N/A
Thread Mgt
TerminateThread
pthread_cancel
pthread_cancel
is safer
Thread Mgt
WaitForSingleObject
(thread handle)
pthread_join
Thread Priority
GetPriorityClass
pthread_attr_getschedpolicy, getpriority
Thread Priority
GetThreadPriority
pthread_attr_getschedparam
Thread Priority
SetPriorityClass
pthread_attr_setschedpolicy, setpriority, nice
Thread Priority
SetThreadPriority
pthread_attr_setschedparam
Note
: Pthreads, while a part of all modern UNIX offerings, are available on non-UNIX systems as well.
3.3 Synchronization
Subject
Windows
UNIX/Pthreads
Comments
Synch: CritSec
DeleteCriticalSection
Use mutexes to emulate critical sections. Some systems provide proprietary equivalents.
C library is not applicable
Synch: CritSec
EnterCriticalSection
C library is not applicable
Synch: CritSec
InitializeCriticalSection
Synch: CritSec
LeaveCriticalSection
Synch: Event
CloseHandle
(event handle)
pthread_cond_destroy
Synch: Event
CreateEvent
pthread_cond_init
Synch: Event
PulseEvent
pthread_cond_signal
Manual-reset event
Synch: Event
ResetEvent
N/A
Synch: Event
SetEvent
pthread_cond_broadcast
Auto-reset event
Synch: Event
WaitForSingleObject
(event handle)
pthread_cond_wait
Synch: Event
WaitForSingleObject
(event handle)
pthread_timed_wait
Synch: Mutex
CloseHandle
(mutex handle)
pthread_mutex_destroy
Synch: Mutex
CreateMutex
pthread_mutex_init
Synch: Mutex
ReleaseMutex
pthread_mutex_unlock
Synch: Mutex
WaitForSingleObject
(mutex handle)
pthread_mutex_lock
Synch: Sem
CreateSemaphore
semget
Synch: Sem
N/A
semctl
Windows does not directly support all these options
Synch: Sem
OpenSemaphore
semget
Synch: Sem
ReleaseSemaphore
semop (+)
Synch: Sem
WaitForSingleObject
(semaphore handle)
semop (-)
Windows can wait for only one count
3.4 IPC
Subject
Windows
UNIX
C Library
Comments
IPC
CallNamedPipe
N/A
N/A
CreateFile, WriteFile, ReadFile, CloseHandle
IPC
CloseHandle
(pipe handle)
close, msgctl
pclose
Not part of the Standard C library—see Stevens
IPC
ConnectNamedPipe
N/A
N/A
IPC
CreateMailslot
N/A
N/A
IPC
CreateNamedPipe
mkfifo, msgget
N/A
IPC
CreatePipe
pipe
popen
Not part of the Standard C library—see Stevens
IPC
DuplicateHandle
dup, dup2
,
or
fcntl
N/A
Or use file names
CONIN$
,
CONOUT$
IPC
GetNamedPipeHandleState
stat, fstat
, lstat64
N/A
IPC
GetNamedPipeInfo
stat, fstat
, lstat
N/A
IPC
ImpersonateNamedPipeClient
N/A
N/A
IPC
PeekNamedPipe
N/A
N/A
IPC
ReadFile
(named pipe handle)
read
(fifo)
, msgsnd
N/A
IPC
RevertToSelf
N/A
N/A
IPC
SetNamedPipeHandleState
N/A
N/A
IPC
TransactNamedPipe
N/A
N/A
WriteFile; ReadFile
IPC
WriteFile
(named pipe handle)
write
(fifo)
, msgrcv
N/A
Misc.
GetComputerName
uname
N/A
Misc.
SetComputerName
N/A
N/A
Security
SetNamedPipeIdentity
Use directory sticky bit
N/A
4. Misc
4.1 Security
Subject
Windows
UNIX
Comments
Security
AddAccessAllowedAce
chmod, fchmod
C library does not support security
Security
AddAccessDeniedAce
chmod, fchmod
Security
AddAuditAce
N/A
Security
CreatePrivateObjectSecurity
N/A
Security
DeleteAce
chmod, fchmod
Security
DestroyPrivateObjectSecurity
N/A
Security
GetAce
stat
*
,
fstat
*
, lstat
Security
GetAclInformation
stat
*
,
fstat
*
, lstat
Security
GetFileSecurity
stat
*
,
fstat
*
, lstat
Security
GetPrivateObjectSecurity
N/A
Security
GetSecurityDescriptorDacl
stat
*
,
fstat
*
, lstat
Security
GetUserName
getlogin
Security
InitializeAcl
N/A
Security
InitializeSecurityDescriptor
Umask
Security
LookupAccountName
getpwnam, getgrnam
Security
LookupAccountSid
getpwuid, getuid, geteuid
Security
N/A
getpwend, setpwent, endpwent
Security
N/A
getgrent, setgrent, endgrent
Security
N/A
Setuid, seteuid, setreuid
Security
N/A
Setgid, setegid, setregid
Security
OpenProcessToken
getgroups, setgroups, initgroups
Security
SetFileSecurity
chmod
*
, fchmod
Security
SetPrivateObjectSecurity
N/A
Security
SetSecurityDescriptorDacl
Umask
Security
SetSecurityDescriptorGroup
chown, fchown, lchown
Security
SetSecurityDescriptorOwner
chown, fchown, lchown
Security
SetSecurityDescriptorSacl
N/A
4.2 Exception Handling
Subject
Windows
UNIX
C Library
SEH
_try – _except
Use C library signals
Use C library signals
SEH
_try – _finally
Use C library signals
Use C library signals
SEH
AbnormalTermination
Use C library signals
Use C library signals
SEH
GetExceptionCode
Use C library signals
Use C library signals
SEH
RaiseException
Use C library signals
signal, raise
Signals
Use
_finally
block
Use C library
atexit
Signals
Use C library or terminate process
kill
raise
Signals
Use C library
Use C library
signal
Signals
Use SEH, VEH
sigemptyset
N/A
Signals
Use SEH, VEH
sigfillset
N/A
Signals
Use SEH, VEH
sigaddset
N/A
Signals
Use SEH, VEH
sigdelset
N/A
Signals
Use SEH, VEH
sigismember
N/A
Signals
Use SEH, VEH
sigprocmask
N/A
Signals
Use SEH, VEH
sigpending
N/A
Signals
Use SEH, VEH
sigaction
N/A
Signals
Use SEH, VEH
sigsetjmp
N/A
Signals
Use SEH, VEH
siglongjmp
N/A
Signals
Use SEH, VEH
sigsuspendf
N/A
Signals
Use SEH, VEH
psignal
N/A
Signals
Use SEH, VEH, or C library
Use C library
abort
Note
: Many UNIX vendors provide proprietary exception handling capabilities.
4.3 System Information & Time
Subject
Windows
UNIX
C Library
Comments
System Info
GetDiskFreeSpace
N/A
N/A
System Info
GetSystemInfo
getrusage
N/A
System Info
GetVersion
uname
N/A
System Info
GetVolumeInformation
N/A
N/A
System Info
GlobalMemoryStatus
getrlimit
N/A
System Info
Various defined constants
sysconf, pathconf, fpathconf
N/A
Time
GetSystemTime
Use C library
time, gmtime
Time
See
ls
program,
Use C library
asctime
Time
CompareFileTime
Use C library
difftime
Compare "calendar" times
Time
FileTimeToLocalFileTime, FileTimeToSystemTime
Use C library
localtime
Time
FileTimeToSystemTime
Use C library
gmtime
Time
GetLocalTime
Use C library
time, localtime
Time
See
touch
program,
Use C library
strftime
Time
SetLocalTime
N/A
N/A
Time
SetSystemTime
N/A
N/A
Time
Subtract file times
Use C library
difftime
Time
SystemTimeToFileTime
Use C library
mktime
1 Comments
Blog - Comment List MSDN TechNet
Comments
Loading...
Leave a Comment
Name
Comment
Please add 6 and 2 and type the answer here:
Post