1 %************************************************************************
3 <sect1>The Posix library
4 <label id="Posix-library">
6 <nidx>Posix library</nidx>
7 <nidx>libraries, Posix</nidx>
9 %************************************************************************
11 The @Posix@ interface gives you access to the set of OS services
12 standardised by POSIX 1003.1b (or the <em>IEEE Portable Operating System
13 Interface for Computing Environments</em> - IEEE Std. 1003.1). The
14 interface is accessed by @import Posix@ and adding
15 @-syslib posix@ on your command-line.
17 <sect2>Posix data types
18 <label id="Posix data types">
20 <nidx>Posix, data types</nidx>
24 data ByteCount -- instances of : Eq Ord Num Real Integral Ix Enum Show
27 A @ByteCount@ is a primitive of type @unsigned@. At a minimum,
28 an conforming implementation must support values in the range
32 data ClockTick -- instances of : Eq Ord Num Real Integral Ix Enum Show
35 A @ClockTick@ is a primitive of type @clock_t@, which
36 is used to measure intervals of time in fractions of a second. The
37 resolution is determined by @getSysVar ClockTick@.
40 data DeviceID -- instances of : Eq Ord Num Real Integral Ix Enum Show
43 A @DeviceID@ is a primitive of type @dev_t@. It must
44 be an arithmetic type.
47 data EpochTime -- instances of : Eq Ord Num Real Integral Ix Enum Show
50 A @EpochTime@ is a primitive of type @time_t@, which is
51 used to measure seconds since the Epoch. At a minimum, the implementation
52 must support values in the range @[0, INT_MAX]@.
55 data FileID -- instances of : Eq Ord Num Real Integral Ix Enum Show
58 A @FileID@ is a primitive of type @ino_t@. It must
59 be an arithmetic type.
62 data FileMode -- instances of : Eq Ord Num Real Integral Ix Enum Show
65 A @FileMode@ is a primitive of type @mode_t@.
66 It must be an arithmetic type.
69 data FileOffset -- instances of : Eq Ord Num Real Integral Ix Enum Show
72 A @FileOffset@ is a primitive of type @off_t@. It must
73 be an arithmetic type.
76 data GroupID -- instances of : Eq Ord Num Real Integral Ix Enum Show
79 A @GroupID@ is a primitive of type @gid_t@. It must
80 be an arithmetic type.
82 data Limit -- instances of : Eq Ord Num Real Integral Ix Enum Show
85 A @Limit@ is a primitive of type @long@.
86 At a minimum, the implementation must support values in the range
87 @[LONG_MIN, LONG_MAX]@.
90 data LinkCount -- instances of : Eq Ord Num Real Integral Ix Enum Show
93 A @LinkCount@ is a primitive of type @nlink_t@. It must
94 be an arithmetic type.
97 data ProcessID -- instances of : Eq Ord Num Real Integral Ix Enum Show
98 type ProcessGroupID = ProcessID
101 A @ProcessID@ is a primitive of type @pid_t@. It
102 must be a signed arithmetic type.
104 data UserID -- instances of : Eq Ord Num Real Integral Ix Enum Show
107 A @UserID@ is a primitive of type @uid_t@. It
108 must be an arithmetic type.
113 A @DirStream@ is a primitive of type @DIR *@.
118 A @FileStatus@ is a primitive of type @struct stat@.
124 A @GroupEntry@ is a primitive of type @struct group@.
129 @ProcessTimes@ is a primitive structure containing a
130 @clock_t@ and a @struct tms@.
136 An @SignalSet@ is a primitive of type @sigset_t@.
142 A @SystemID@ is a primitive of type @struct utsname@.
145 data TerminalAttributes
147 @TerminalAttributes@ is a primitive of type @struct termios@.
153 A @UserEntry@ is a primitive of type @struct passwd@.
156 data BaudRate = B0 | B50 | B75 | B110 | B134 | B150 | B200 | B300 | B600
157 | B1200 | B1800 | B2400 | B4800 | B9600 | B19200 | B38400
162 intToFd :: Int -> Fd -- use with care.
164 data FdOption = AppendOnWrite
168 data ControlCharacter = EndOfFile
180 type FileLock = (LockRequest, SeekMode, FileOffset, FileOffset)
181 -- whence start length
183 data FlowAction = SuspendOutput | RestartOutput | TransmitStop | TransmitStart
185 data Handler = Default | Ignore | Catch (IO ())
187 data LockRequest = ReadLock | WriteLock | Unlock
190 data OpenMode = ReadOnly | WriteOnly | ReadWrite
192 data PathVar = LinkLimit
198 | SetOwnerAndGroupIsRestricted
199 | FileNamesAreNotTruncated
201 data QueueSelector = InputQueue | OutputQueue | BothQueues
205 data SysVar = ArgumentLimit
214 data TerminalMode = InterruptOnBreak -- BRKINT
216 | IgnoreBreak -- IGNBRK
218 | IgnoreParityErrors -- IGNPAR
220 | CheckParity -- INPCK
221 | StripHighBit -- ISTRIP
222 | StartStopInput -- IXOFF
223 | StartStopOutput -- IXON
224 | MarkParityErrors -- PARMRK
225 | ProcessOutput -- OPOST
226 | LocalMode -- CLOCAL
227 | ReadEnable -- CREAD
228 | TwoStopBits -- CSTOPB
229 | HangupOnClose -- HUPCL
230 | EnableParity -- PARENB
231 | OddParity -- PARODD
236 | ProcessInput -- ICANON
237 | ExtendedFunctions -- IEXTEN
238 | KeyboardInterrupts -- ISIG
239 | NoFlushOnInterrupt -- NOFLSH
240 | BackgroundWriteInterrupt -- TOSTOP
242 data TerminalState = Immediately | WhenDrained | WhenFlushed
244 data ProcessStatus = Exited ExitCode
250 <sect2>Posix Process Primitives
251 <label id="Process Primitives">
255 forkProcess :: IO (Maybe ProcessID)
258 @forkProcess@ calls @fork@, returning
259 @Just pid@ to the parent, where @pid@ is the
260 ProcessID of the child, and returning @Nothing@ to the
264 executeFile :: FilePath -- Command
265 -> Bool -- Search PATH?
266 -> [String] -- Arguments
267 -> Maybe [(String, String)] -- Environment
271 @executeFile cmd args env@ calls one of the
272 @execv*@ family, depending on whether or not the current
273 PATH is to be searched for the command, and whether or not an
274 environment is provided to supersede the process's current
275 environment. The basename (leading directory names suppressed) of
276 the command is passed to @execv*@ as @arg[0]@;
277 the argument list passed to @executeFile@ therefore begins
281 Search PATH? Supersede environ? Call
282 ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ ~~~~~~~
289 Note that @execvpe@ is not provided by the POSIX standard, and must
290 be written by hand. Care must be taken to ensure that the search path
291 is extracted from the original environment, and not from the
292 environment to be passed on to the new image.
294 A successful @executeFile@ overlays the current process image with
295 a new one, so it only returns on failure.
297 runProcess :: FilePath -- Command
298 -> [String] -- Arguments
299 -> Maybe [(String, String)] -- Environment (Nothing -> Inherited)
300 -> Maybe FilePath -- Working directory (Nothing -> inherited)
301 -> Maybe Handle -- stdin (Nothing -> inherited)
302 -> Maybe Handle -- stdout (Nothing -> inherited)
303 -> Maybe Handle -- stderr (Nothing -> inherited)
307 @runProcess@ is our candidate for the high-level OS-independent
310 @runProcess cmd args env wd inhdl outhdl errhdl@ runs @cmd@
311 (searching the current @PATH@) with arguments @args@. If
312 @env@ is @Just pairs@, the command is executed with the
313 environment specified by @pairs@ of variables and values;
314 otherwise, the command is executed with the current environment. If
315 @wd@ is @Just dir@, the command is executed with working
316 directory @dir@; otherwise, the command is executed in the current
317 working directory. If @{in,out,err@hdl} is @Just handle@, the
318 command is executed with the @Fd@ for @std{in,out,err@}
319 attached to the specified @handle@; otherwise, the @Fd@ for
320 @std{in,out,err@} is left unchanged.
323 getProcessStatus :: Bool -- Block?
324 -> Bool -- Stopped processes?
326 -> IO (Maybe ProcessStatus)
329 @getProcessStatus blk stopped pid@ calls @waitpid@, returning
330 @Just tc@, the @ProcessStatus@ for process @pid@ if it is
331 available, @Nothing@ otherwise. If @blk@ is @False@, then
332 @WNOHANG@ is set in the options for @waitpid@, otherwise not.
333 If @stopped@ is @True@, then @WUNTRACED@ is set in the
334 options for @waitpid@, otherwise not.
337 getGroupProcessStatus :: Bool -- Block?
338 -> Bool -- Stopped processes?
340 -> IO (Maybe (ProcessID, ProcessStatus))
343 @getGroupProcessStatus blk stopped pgid@ calls @waitpid@,
344 returning @Just (pid, tc)@, the @ProcessID@ and
345 @ProcessStatus@ for any process in group @pgid@ if one is
346 available, @Nothing@ otherwise. If @blk@ is @False@, then
347 @WNOHANG@ is set in the options for @waitpid@, otherwise not.
348 If @stopped@ is @True@, then @WUNTRACED@ is set in the
349 options for @waitpid@, otherwise not.
352 getAnyProcessStatus :: Bool -- Block?
353 -> Bool -- Stopped processes?
354 -> IO (Maybe (ProcessID, ProcessStatus))
357 @getAnyProcessStatus blk stopped@ calls @waitpid@, returning
358 @Just (pid, tc)@, the @ProcessID@ and @ProcessStatus@ for any
359 child process if one is available, @Nothing@ otherwise. If
360 @blk@ is @False@, then @WNOHANG@ is set in the options for
361 @waitpid@, otherwise not. If @stopped@ is @True@, then
362 @WUNTRACED@ is set in the options for @waitpid@, otherwise not.
365 exitImmediately :: ExitCode -> IO ()
368 @exitImmediately status@ calls @_exit@ to terminate the process
369 with the indicated exit @status@.
370 The operation never returns.
373 getEnvironment :: IO [(String, String)]
376 @getEnvironment@ parses the environment variable mapping provided by
377 @environ@, returning @(variable, value)@ pairs.
378 The operation never fails.
381 setEnvironment :: [(String, String)] -> IO ()
384 @setEnvironment@ replaces the process environment with the provided
385 mapping of @(variable, value)@ pairs.
388 getEnvVar :: String -> IO String
391 @getEnvVar var@ returns the value associated with variable @var@
392 in the current environment (identical functionality provided through
393 standard Haskell library function @System.getEnv@).
395 The operation may fail with:
398 <tag>@NoSuchThing@</tag>
399 The variable has no mapping in the current environment.
403 setEnvVar :: String -> String -> IO ()
406 @setEnvVar var val@ sets the value associated with variable @var@
407 in the current environment to be @val@. Any previous mapping is
411 removeEnvVar :: String -> IO ()
414 @removeEnvVar var@ removes any value associated with variable @var@
415 in the current environment. Deleting a variable for which there is no mapping
416 does not generate an error.
422 backgroundRead, sigTTIN :: Signal
423 backgroundWrite, sigTTOU :: Signal
424 continueProcess, sigCONT :: Signal
425 floatingPointException, sigFPE :: Signal
426 illegalInstruction, sigILL :: Signal
427 internalAbort, sigABRT :: Signal
428 keyboardSignal, sigINT :: Signal
429 keyboardStop, sigTSTP :: Signal
430 keyboardTermination, sigQUIT :: Signal
431 killProcess, sigKILL :: Signal
432 lostConnection, sigHUP :: Signal
433 openEndedPipe, sigPIPE :: Signal
434 processStatusChanged, sigCHLD :: Signal
435 realTimeAlarm, sigALRM :: Signal
436 segmentationViolation, sigSEGV :: Signal
437 softwareStop, sigSTOP :: Signal
438 softwareTermination, sigTERM :: Signal
439 userDefinedSignal1, sigUSR1 :: Signal
440 userDefinedSignal2, sigUSR2 :: Signal
442 signalProcess :: Signal -> ProcessID -> IO ()
445 @signalProcess int pid@ calls @kill@ to signal
446 process @pid@ with interrupt signal @int@.
449 raiseSignal :: Signal -> IO ()
452 @raiseSignal int@ calls @kill@ to signal the current process
453 with interrupt signal @int@.
456 signalProcessGroup :: Signal -> ProcessGroupID -> IO ()
459 @signalProcessGroup int pgid@ calls @kill@ to signal
460 all processes in group @pgid@ with interrupt signal @int@.
463 setStoppedChildFlag :: Bool -> IO Bool
466 @setStoppedChildFlag bool@ sets a flag which controls whether or
467 not the @NOCLDSTOP@ option will be used the next time a signal
468 handler is installed for @SIGCHLD@. If @bool@ is @True@ (the
469 default), @NOCLDSTOP@ will not be used; otherwise it will be. The
470 operation never fails.
473 queryStoppedChildFlag :: IO Bool
476 @queryStoppedChildFlag@ queries the flag which
477 controls whether or not the @NOCLDSTOP@ option will be used
478 the next time a signal handler is installed for @SIGCHLD@.
479 If @NOCLDSTOP@ will be used, it returns @False@;
480 otherwise (the default) it returns @True@.
481 The operation never fails.
484 emptySignalSet :: SignalSet
485 fullSignalSet :: SignalSet
486 addSignal :: Signal -> SignalSet -> SignalSet
487 deleteSignal :: Signal -> SignalSet -> SignalSet
488 inSignalSet :: Signal -> SignalSet -> Bool
490 installHandler :: Signal
492 -> Maybe SignalSet -- other signals to block
493 -> IO Handler -- old handler
496 @installHandler int handler iset@ calls @sigaction@ to install
497 an interrupt handler for signal @int@. If @handler@ is
498 @Default@, @SIG_DFL@ is installed; if @handler@ is
499 @Ignore@, @SIG_IGN@ is installed; if @handler@ is
500 @Catch action@, a handler is installed which will invoke @action@ as a
501 replacement for @main@. If @iset@ is @Just s@, then the
502 @sa_mask@ of the @sigaction@ structure is set to @s@;
503 otherwise it is cleared. The previously installed signal handler for
507 getSignalMask :: IO SignalSet
510 @getSignalMask@ calls @sigprocmask@ to determine the
511 set of interrupts which are currently being blocked.
514 setSignalMask :: SignalSet -> IO SignalSet
517 @setSignalMask mask@ calls @sigprocmask@ with
518 @SIG_SETMASK@ to block all interrupts in @mask@. The
519 previous set of blocked interrupts is returned.
522 blockSignals :: SignalSet -> IO SignalSet
525 @setSignalMask mask@ calls @sigprocmask@ with
526 @SIG_BLOCK@ to add all interrupts in @mask@ to the
527 set of blocked interrupts. The previous set of blocked interrupts is returned.
530 unBlockSignals :: SignalSet -> IO SignalSet
533 @setSignalMask mask@ calls @sigprocmask@ with
534 @SIG_UNBLOCK@ to remove all interrupts in @mask@ from the
535 set of blocked interrupts. The previous set of blocked interrupts is returned.
538 getPendingSignals :: IO SignalSet
541 @getPendingSignals@ calls @sigpending@ to obtain
542 the set of interrupts which have been received but are currently blocked.
545 awaitSignal :: Maybe SignalSet -> IO ()
548 @awaitSignal iset@ suspends execution until an interrupt is received.
549 If @iset@ is @Just s@, @awaitSignal@ calls
550 @sigsuspend@, installing @s@ as the new signal mask before
551 suspending execution; otherwise, it calls @pause@. If successful,
552 @awaitSignal@ does not return.
555 scheduleAlarm :: Int -> IO Int
558 @scheduleAlarm i@ calls @alarm@ to schedule a real time
559 alarm at least @i@ seconds in the future.
562 sleep :: Int -> IO ()
565 @sleep i@ calls @sleep@ to suspend execution of the
566 program until at least @i@ seconds have elapsed or a signal is
569 <sect2>Posix Process Environment
570 <label id="Process Environment">
572 <nidx>Posix, process environment</nidx>
575 getProcessID :: IO ProcessID
578 @getProcessID@ calls @getpid@ to obtain the @ProcessID@ for
582 getParentProcessID :: IO ProcessID
585 @getProcessID@ calls @getppid@ to obtain the @ProcessID@ for
586 the parent of the current process.
589 getRealUserID :: IO UserID
592 @getRealUserID@ calls @getuid@ to obtain the real @UserID@
593 associated with the current process.
596 getEffectiveUserID :: IO UserID
599 @getRealUserID@ calls @geteuid@ to obtain the effective
600 @UserID@ associated with the current process.
603 setUserID :: UserID -> IO ()
606 @setUserID uid@ calls @setuid@ to set the real, effective, and
607 saved set-user-id associated with the current process to @uid@.
610 getLoginName :: IO String
613 @getLoginName@ calls @getlogin@ to obtain the login name
614 associated with the current process.
617 getRealGroupID :: IO GroupID
620 @getRealGroupID@ calls @getgid@ to obtain the real @GroupID@
621 associated with the current process.
624 getEffectiveGroupID :: IO GroupID
627 @getEffectiveGroupID@ calls @getegid@ to obtain the effective
628 @GroupID@ associated with the current process.
631 setGroupID :: GroupID -> IO ()
634 @setGroupID gid@ calls @setgid@ to set the real, effective, and
635 saved set-group-id associated with the current process to @gid@.
638 getGroups :: IO [GroupID]
641 @getGroups@ calls @getgroups@ to obtain the list of
642 supplementary @GroupID@s associated with the current process.
645 getEffectiveUserName :: IO String
648 @getEffectiveUserName@ calls @cuserid@ to obtain a name
649 associated with the effective @UserID@ of the process.
652 getProcessGroupID :: IO ProcessGroupID
655 @getProcessGroupID@ calls @getpgrp@ to obtain the
656 @ProcessGroupID@ for the current process.
659 createProcessGroup :: ProcessID -> IO ProcessGroupID
662 @createProcessGroup pid@ calls @setpgid@ to make
663 process @pid@ a new process group leader.
666 joinProcessGroup :: ProcessGroupID -> IO ProcessGroupID
669 @joinProcessGroup pgid@ calls @setpgid@ to set the
670 @ProcessGroupID@ of the current process to @pgid@.
673 setProcessGroupID :: ProcessID -> ProcessGroupID -> IO ()
676 @setProcessGroupID pid pgid@ calls @setpgid@ to set the
677 @ProcessGroupID@ for process @pid@ to @pgid@.
680 createSession :: IO ProcessGroupID
683 @createSession@ calls @setsid@ to create a new session
684 with the current process as session leader.
687 systemName :: SystemID -> String
688 nodeName :: SystemID -> String
689 release :: SystemID -> String
690 version :: SystemID -> String
691 machine :: SystemID -> String
693 getSystemID :: IO SystemID
696 @getSystemID@ calls @uname@ to obtain information
697 about the current operating system.
700 > epochTime :: IO EpochTime
703 @epochTime@ calls @time@ to obtain the number of
704 seconds that have elapsed since the epoch (Jan 01 00:00:00 GMT 1970).
707 elapsedTime :: ProcessTimes -> ClockTick
708 userTime :: ProcessTimes -> ClockTick
709 systemTime :: ProcessTimes -> ClockTick
710 childUserTime :: ProcessTimes -> ClockTick
711 childSystemTime :: ProcessTimes -> ClockTick
713 getProcessTimes :: IO ProcessTimes
716 @getProcessTimes@ calls @times@ to obtain time-accounting
717 information for the current process and its children.
720 getControllingTerminalName :: IO FilePath
723 @getControllingTerminalName@ calls @ctermid@ to obtain
724 a name associated with the controlling terminal for the process. If a
725 controlling terminal exists,
726 @getControllingTerminalName@ returns the name of the
727 controlling terminal.
729 The operation may fail with:
732 <tag>@NoSuchThing@</tag>
733 There is no controlling terminal, or its name cannot be determined.
734 <tag>@SystemError@</tag>
735 Various other causes.
739 getTerminalName :: Fd -> IO FilePath
742 @getTerminalName fd@ calls @ttyname@ to obtain a name associated
743 with the terminal for @Fd@ @fd@. If @fd@ is associated
744 with a terminal, @getTerminalName@ returns the name of the
747 The operation may fail with:
750 <tag>@InappropriateType@</tag>
751 The channel is not associated with a terminal.
752 <tag>@NoSuchThing@</tag>
753 The channel is associated with a terminal, but it has no name.
754 <tag>@SystemError@</tag>
755 Various other causes.
759 queryTerminal :: Fd -> IO Bool
762 @queryTerminal fd@ calls @isatty@ to determine whether or
763 not @Fd@ @fd@ is associated with a terminal.
766 getSysVar :: SysVar -> IO Limit
769 @getSysVar var@ calls @sysconf@ to obtain the
770 dynamic value of the requested configurable system limit or option.
771 For defined system limits, @getSysVar@ returns the associated
772 value. For defined system options, the result of @getSysVar@
773 is undefined, but not failure.
775 The operation may fail with:
778 <tag>@NoSuchThing@</tag>
779 The requested system limit or option is undefined.
782 <sect2>Posix operations on files and directories
783 <label id="Files and Directories">
785 <nidx>Posix, files and directories</nidx>
788 openDirStream :: FilePath -> IO DirStream
791 @openDirStream dir@ calls @opendir@ to obtain a
792 directory stream for @dir@.
795 readDirStream :: DirStream -> IO String
798 @readDirStream dp@ calls @readdir@ to obtain the
799 next directory entry (@struct dirent@) for the open directory
800 stream @dp@, and returns the @d_name@ member of that
803 The operation may fail with:
807 End of file has been reached.
808 <tag>@SystemError@</tag>
809 Various other causes.
813 rewindDirStream :: DirStream -> IO ()
816 @rewindDirStream dp@ calls @rewinddir@ to reposition
817 the directory stream @dp@ at the beginning of the directory.
820 closeDirStream :: DirStream -> IO ()
823 @closeDirStream dp@ calls @closedir@ to close
824 the directory stream @dp@.
827 getWorkingDirectory :: IO FilePath
830 @getWorkingDirectory@ calls @getcwd@ to obtain the name
831 of the current working directory.
834 changeWorkingDirectory :: FilePath -> IO ()
837 @changeWorkingDirectory dir@ calls @chdir@ to change
838 the current working directory to @dir@.
841 nullFileMode :: FileMode -- ---------
842 ownerReadMode :: FileMode -- r--------
843 ownerWriteMode :: FileMode -- -w-------
844 ownerExecuteMode :: FileMode -- --x------
845 groupReadMode :: FileMode -- ---r-----
846 groupWriteMode :: FileMode -- ----w----
847 groupExecuteMode :: FileMode -- -----x---
848 otherReadMode :: FileMode -- ------r--
849 otherWriteMode :: FileMode -- -------w-
850 otherExecuteMode :: FileMode -- --------x
851 setUserIDMode :: FileMode -- --S------
852 setGroupIDMode :: FileMode -- -----S---
854 stdFileMode :: FileMode -- rw-rw-rw-
856 ownerModes :: FileMode -- rwx------
857 groupModes :: FileMode -- ---rwx---
858 otherModes :: FileMode -- ------rwx
859 accessModes :: FileMode -- rwxrwxrwx
861 unionFileModes :: FileMode -> FileMode -> FileMode
862 intersectFileModes :: FileMode -> FileMode -> FileMode
868 stdOutput = intToFd 1
884 -> Maybe FileMode -- Just x => O_CREAT, Nothing => must exist
889 @openFd path acc mode (OpenFileFlags app excl noctty nonblock trunc)@ calls
890 @open@ to obtain a @Fd@ for the file @path@ with access
891 mode @acc@. If @mode@ is @Just m@, the @O_CREAT@ flag is
892 set and the file's permissions will be based on @m@ if it does not
893 already exist; otherwise, the @O_CREAT@ flag is not set. The
894 arguments @app@, @excl@, @noctty@, @nonblock@, and
895 @trunc@ control whether or not the flags @O_APPEND@,
896 @O_EXCL@, @O_NOCTTY@, @O_NONBLOCK@, and @O_TRUNC@ are set,
900 createFile :: FilePath -> FileMode -> IO Fd
903 @createFile path mode@ calls @creat@ to obtain a @Fd@
904 for file @path@, which will be created with permissions based on
905 @mode@ if it does not already exist.
908 setFileCreationMask :: FileMode -> IO FileMode
911 @setFileCreationMask mode@ calls @umask@ to set
912 the process's file creation mask to @mode@. The previous file
913 creation mask is returned.
916 createLink :: FilePath -> FilePath -> IO ()
919 @createLink old new@ calls @link@ to create a
920 new path, @new@, linked to an existing file, @old@.
922 createDirectory :: FilePath -> FileMode -> IO ()
925 @createDirectory dir mode@ calls @mkdir@ to
926 create a new directory, @dir@, with permissions based on
930 createNamedPipe :: FilePath -> FileMode -> IO ()
933 @createNamedPipe fifo mode@ calls @mkfifo@ to
934 create a new named pipe, @fifo@, with permissions based on
938 removeLink :: FilePath -> IO ()
941 @removeLink path@ calls @unlink@ to remove the link
945 removeDirectory :: FilePath -> IO ()
948 @removeDirectory dir@ calls @rmdir@ to remove the
949 directory named @dir@.
952 rename :: FilePath -> FilePath -> IO ()
955 @rename old new@ calls @rename@ to rename a
956 file or directory from @old@ to @new@.
959 fileMode :: FileStatus -> FileMode
961 fileID :: FileStatus -> FileID
962 deviceID :: FileStatus -> DeviceID
964 linkCount :: FileStatus -> LinkCount
966 fileOwner :: FileStatus -> UserID
967 fileGroup :: FileStatus -> GroupID
968 fileSize :: FileStatus -> FileOffset
970 accessTime :: FileStatus -> EpochTime
971 modificationTime :: FileStatus -> EpochTime
972 statusChangeTime :: FileStatus -> EpochTime
974 isDirectory :: FileStatus -> Bool
975 isCharacterDevice :: FileStatus -> Bool
976 isBlockDevice :: FileStatus -> Bool
977 isRegularFile :: FileStatus -> Bool
978 isNamedPipe :: FileStatus -> Bool
980 getFileStatus :: FilePath -> IO FileStatus
983 @getFileStatus path@ calls @stat@ to get the
984 @FileStatus@ information for the file @path@.
987 getFdStatus :: Fd -> IO FileStatus
990 @getFdStatus fd@ calls @fstat@ to get the
991 @FileStatus@ information for the file associated with
995 queryAccess :: FilePath -> Bool -> Bool -> Bool -> IO Bool
998 @queryAccess path r w x@ calls @access@ to test the access
999 permissions for file @path@. The three arguments, @r@, @w@,
1000 and @x@ control whether or not @access@ is called with
1001 @R_OK@, @W_OK@, and @X_OK@ respectively.
1004 queryFile :: FilePath -> IO Bool
1007 @queryFile path@ calls @access@ with @F_OK@ to test for the
1008 existence for file @path@.
1011 setFileMode :: FilePath -> FileMode -> IO ()
1014 @setFileMode path mode@ calls @chmod@ to set the
1015 permission bits associated with file @path@ to @mode@.
1018 setOwnerAndGroup :: FilePath -> UserID -> GroupID -> IO ()
1021 @setOwnerAndGroup path uid gid@ calls @chown@ to
1022 set the @UserID@ and @GroupID@ associated with file
1023 @path@ to @uid@ and @gid@, respectively.
1026 setFileTimes :: FilePath -> EpochTime -> EpochTime -> IO ()
1029 @setFileTimes path atime mtime@ calls @utime@ to
1030 set the access and modification times associated with file
1031 @path@ to @atime@ and @mtime@, respectively.
1034 touchFile :: FilePath -> IO ()
1037 @touchFile path@ calls @utime@ to
1038 set the access and modification times associated with file
1039 @path@ to the current time.
1042 getPathVar :: PathVar -> FilePath -> IO Limit
1045 @getPathVar var path@ calls @pathconf@ to obtain the
1046 dynamic value of the requested configurable file limit or option associated
1047 with file or directory @path@. For
1048 defined file limits, @getPathVar@ returns the associated
1049 value. For defined file options, the result of @getPathVar@
1050 is undefined, but not failure.
1051 The operation may fail with:
1053 <tag>@NoSuchThing@</tag>
1054 The requested file limit or option is undefined.
1055 <tag>@SystemError@</tag>
1056 Various other causes.
1061 getFdVar :: PathVar -> Fd -> IO Limit
1064 @getFdVar var fd@ calls @fpathconf@ to obtain the
1065 dynamic value of the requested configurable file limit or option associated
1066 with the file or directory attached to the open channel @fd@.
1067 For defined file limits, @getFdVar@ returns the associated
1068 value. For defined file options, the result of @getFdVar@
1069 is undefined, but not failure.
1071 The operation may fail with:
1074 <tag>@NoSuchThing@</tag>
1075 The requested file limit or option is undefined.
1076 <tag>@SystemError@</tag>
1077 Various other causes.
1080 <sect2>Posix Input and Output Primitives
1081 <label id="Inut Output">
1083 <nidx>Posix, input/output</nidx>
1086 createPipe :: IO (Fd, Fd)
1089 @createPipe@ calls @pipe@ to create a pipe and returns a pair of
1090 @Fd@s, the first for writing and the second for reading.
1096 @dup fd@ calls @dup@ to duplicate @Fd@ @fd@ to
1100 dupTo :: Fd -> Fd -> IO ()
1103 @dupTo src dst@ calls @dup2@ to duplicate @Fd@
1104 @src@ to @Fd@ @dst@.
1107 fdClose :: Fd -> IO ()
1110 @fdClose fd@ calls @close@ to close @Fd@ @fd@.
1113 fdRead :: Fd -> ByteCount -> IO (String, ByteCount)
1116 @fdRead fd nbytes@ calls @read@ to read at most @nbytes@
1117 bytes from @Fd@ @fd@, and returns the result as a string
1118 paired with the number of bytes actually read.
1120 The operation may fail with:
1124 End of file has been reached.
1125 <tag>@SystemError@</tag>
1126 Various other causes.
1130 fdWrite :: Fd -> String -> IO ByteCount
1133 @fdWrite fd s@ calls @write@ to write
1134 the string @s@ to @Fd@ @fd@ as a
1135 contiguous sequence of bytes. It returns the number of bytes successfully
1139 queryFdOption :: FdOption -> Fd -> IO Bool
1142 @getFdOption opt fd@ calls @fcntl@ to determine whether or
1143 not the flag associated with @FdOption@ @opt@ is set for
1147 setFdOption :: Fd -> FdOption -> Bool -> IO ()
1150 @setFdOption fd opt val@ calls @fcntl@ to set the flag
1151 associated with @FdOption@ @opt@ on @Fd@ @fd@ to
1155 getLock :: Fd -> FileLock -> IO (Maybe (ProcessID, FileLock))
1158 @getLock fd lock@ calls @fcntl@ to get the first @FileLock@
1159 for @Fd@ @fd@ which blocks the @FileLock@ @lock@. If
1160 no such @FileLock@ exists, @getLock@ returns @Nothing@.
1161 Otherwise, it returns @Just (pid, block)@, where @block@ is the
1162 blocking @FileLock@ and @pid@ is the @ProcessID@ of the
1163 process holding the blocking @FileLock@.
1167 setLock :: Fd -> FileLock -> IO ()
1170 @setLock fd lock@ calls @fcntl@ with @F_SETLK@ to set or
1171 clear a lock segment for @Fd@ @fd@ as indicated by the
1172 @FileLock@ @lock@. @setLock@ does not block, but fails with
1173 @SystemError@ if the request cannot be satisfied immediately.
1176 waitToSetLock :: Fd -> FileLock -> IO ()
1179 @waitToSetLock fd lock@ calls @fcntl@ with @F_SETLKW@ to set
1180 or clear a lock segment for @Fd@ @fd@ as indicated by the
1181 @FileLock@ @lock@. If the request cannot be satisfied
1182 immediately, @waitToSetLock@ blocks until the request can be
1187 fdSeek :: Fd -> SeekMode -> FileOffset -> IO FileOffset
1190 @fdSeek fd whence offset@ calls @lseek@ to position the
1191 @Fd@ @fd@ at the given @offset@ from the starting location
1192 indicated by @whence@. It returns the resulting offset from the
1193 start of the file in bytes.
1195 <sect2>Posix, Device- and Class-Specific Functions
1196 <label id="Device Specific Functions">
1198 <nidx>Posix, device and class-specific functions</nidx>
1201 terminalMode :: TerminalMode -> TerminalAttributes -> Bool
1202 withMode :: TerminalAttributes -> TerminalMode -> TerminalAttributes
1203 withoutMode :: TerminalAttributes -> TerminalMode -> TerminalAttributes
1205 bitsPerByte :: TerminalAttributes -> Int
1206 withBits :: TerminalAttributes -> Int -> TerminalAttributes
1208 controlChar :: TerminalAttributes -> ControlCharacter -> Maybe Char
1209 withCC :: TerminalAttributes
1210 -> (ControlCharacter, Char)
1211 -> TerminalAttributes
1212 withoutCC :: TerminalAttributes
1214 -> TerminalAttributes
1216 inputTime :: TerminalAttributes -> Int
1217 withTime :: TerminalAttributes -> Int -> TerminalAttributes
1219 minInput :: TerminalAttributes -> Int
1220 withMinInput :: TerminalAttributes -> Int -> TerminalAttributes
1222 inputSpeed :: TerminalAttributes -> BaudRate
1223 withInputSpeed :: TerminalAttributes -> BaudRate -> TerminalAttributes
1225 outputSpeed :: TerminalAttributes -> BaudRate
1226 withOutputSpeed :: TerminalAttributes -> BaudRate -> TerminalAttributes
1228 getTerminalAttributes :: Fd -> IO TerminalAttributes
1231 @getTerminalAttributes fd@ calls @tcgetattr@ to obtain
1232 the @TerminalAttributes@ associated with @Fd@ @fd@.
1235 setTerminalAttributes :: Fd
1236 -> TerminalAttributes
1241 @setTerminalAttributes fd attr ts@ calls @tcsetattr@ to change
1242 the @TerminalAttributes@ associated with @Fd@ @fd@ to
1243 @attr@, when the terminal is in the state indicated by @ts@.
1246 sendBreak :: Fd -> Int -> IO ()
1249 @sendBreak fd duration@ calls @tcsendbreak@ to transmit a
1250 continuous stream of zero-valued bits on @Fd@ @fd@ for the
1251 specified implementation-dependent @duration@.
1254 drainOutput :: Fd -> IO ()
1257 @drainOutput fd@ calls @tcdrain@ to block until all output
1258 written to @Fd@ @fd@ has been transmitted.
1261 discardData :: Fd -> QueueSelector -> IO ()
1264 @discardData fd queues@ calls @tcflush@ to discard
1265 pending input and/or output for @Fd@ @fd@,
1266 as indicated by the @QueueSelector@ @queues@.
1269 controlFlow :: Fd -> FlowAction -> IO ()
1272 @controlFlow fd action@ calls @tcflow@ to control the
1273 flow of data on @Fd@ @fd@, as indicated by
1277 getTerminalProcessGroupID :: Fd -> IO ProcessGroupID
1280 @getTerminalProcessGroupID fd@ calls @tcgetpgrp@ to
1281 obtain the @ProcessGroupID@ of the foreground process group
1282 associated with the terminal attached to @Fd@ @fd@.
1285 setTerminalProcessGroupID :: Fd -> ProcessGroupID -> IO ()
1288 @setTerminalProcessGroupID fd pgid@ calls @tcsetpgrp@ to
1289 set the @ProcessGroupID@ of the foreground process group
1290 associated with the terminal attached to @Fd@
1293 <sect2>Posix System Databases
1294 <label id="System Database">
1296 <nidx>Posix, system databases</nidx>
1299 groupName :: GroupEntry -> String
1300 groupID :: GroupEntry -> GroupID
1301 groupMembers :: GroupEntry -> [String]
1303 getGroupEntryForID :: GroupID -> IO GroupEntry
1306 @getGroupEntryForID gid@ calls @getgrgid@ to obtain
1307 the @GroupEntry@ information associated with @GroupID@
1310 The operation may fail with:
1313 <tag>@NoSuchThing@</tag>
1314 There is no group entry for the GroupID.
1318 getGroupEntryForName :: String -> IO GroupEntry
1321 @getGroupEntryForName name@ calls @getgrnam@ to obtain
1322 the @GroupEntry@ information associated with the group called
1325 The operation may fail with:
1328 <tag>@NoSuchThing@</tag>
1329 There is no group entry for the name.
1333 userName :: UserEntry -> String
1334 userID :: UserEntry -> UserID
1335 userGroupID :: UserEntry -> GroupID
1336 homeDirectory :: UserEntry -> String
1337 userShell :: UserEntry -> String
1339 getUserEntryForID :: UserID -> IO UserEntry
1342 @getUserEntryForID gid@ calls @getpwuid@ to obtain
1343 the @UserEntry@ information associated with @UserID@
1345 The operation may fail with:
1348 <tag>@NoSuchThing@</tag>
1349 There is no user entry for the UserID.
1353 getUserEntryForName :: String -> IO UserEntry
1356 @getUserEntryForName name@ calls @getpwnam@ to obtain
1357 the @UserEntry@ information associated with the user login
1360 The operation may fail with:
1363 <tag>@NoSuchThing@</tag>
1364 There is no user entry for the name.
1368 <label id="Error reporting and handling">
1370 <nidx>Posix, errors</nidx>
1373 getErrorCode :: IO ErrorCode
1376 @getErrorCode@ returns the current value of the external
1377 variable @errno@. It never fails.
1380 setErrorCode :: ErrorCode -> IO ()
1383 @setErrorCode err@ sets the external
1384 variable @errno@ to @err@. It never fails.
1387 noError :: ErrorCode
1390 argumentListTooLong, e2BIG :: ErrorCode
1391 badFd, eBADF :: ErrorCode
1392 brokenPipe, ePIPE :: ErrorCode
1393 directoryNotEmpty, eNOTEMPTY :: ErrorCode
1394 execFormatError, eNOEXEC :: ErrorCode
1395 fileAlreadyExists, eEXIST :: ErrorCode
1396 fileTooLarge, eFBIG :: ErrorCode
1397 filenameTooLong, eNAMETOOLONG :: ErrorCode
1398 improperLink, eXDEV :: ErrorCode
1399 inappropriateIOControlOperation, eNOTTY :: ErrorCode
1400 inputOutputError, eIO :: ErrorCode
1401 interruptedOperation, eINTR :: ErrorCode
1402 invalidArgument, eINVAL :: ErrorCode
1403 invalidSeek, eSPIPE :: ErrorCode
1404 isADirectory, eISDIR :: ErrorCode
1405 noChildProcess, eCHILD :: ErrorCode
1406 noLocksAvailable, eNOLCK :: ErrorCode
1407 noSpaceLeftOnDevice, eNOSPC :: ErrorCode
1408 noSuchOperationOnDevice, eNODEV :: ErrorCode
1409 noSuchDeviceOrAddress, eNXIO :: ErrorCode
1410 noSuchFileOrDirectory, eNOENT :: ErrorCode
1411 noSuchProcess, eSRCH :: ErrorCode
1412 notADirectory, eNOTDIR :: ErrorCode
1413 notEnoughMemory, eNOMEM :: ErrorCode
1414 operationNotImplemented, eNOSYS :: ErrorCode
1415 operationNotPermitted, ePERM :: ErrorCode
1416 permissionDenied, eACCES :: ErrorCode
1417 readOnlyFileSystem, eROFS :: ErrorCode
1418 resourceBusy, eBUSY :: ErrorCode
1419 resourceDeadlockAvoided, eDEADLK :: ErrorCode
1420 resourceTemporarilyUnavailable, eAGAIN :: ErrorCode
1421 tooManyLinks, eMLINK :: ErrorCode
1422 tooManyOpenFiles, eMFILE :: ErrorCode
1423 tooManyOpenFilesInSystem, eNFILE :: ErrorCode