mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-30 15:13:37 +03:00
3e1f6aba56
Co-authored-by: Stiopa Koltsov <stepan.koltsov@gmail.com>
31 lines
790 B
Idris
31 lines
790 B
Idris
module System.File.Process
|
|
|
|
import public System.File.Error
|
|
import public System.File.Mode
|
|
import System.File.Support
|
|
import public System.File.Types
|
|
|
|
%foreign "C:fflush,libc 6"
|
|
prim__flush : FilePtr -> PrimIO Int
|
|
%foreign support "idris2_popen"
|
|
prim__popen : String -> String -> PrimIO FilePtr
|
|
%foreign support "idris2_pclose"
|
|
prim__pclose : FilePtr -> PrimIO ()
|
|
|
|
export
|
|
fflush : HasIO io => (h : File) -> io ()
|
|
fflush (FHandle f)
|
|
= ignore $ primIO (prim__flush f)
|
|
|
|
export
|
|
popen : HasIO io => String -> Mode -> io (Either FileError File)
|
|
popen f m = do
|
|
ptr <- primIO (prim__popen f (modeStr m))
|
|
if prim__nullAnyPtr ptr /= 0
|
|
then returnError
|
|
else pure (Right (FHandle ptr))
|
|
|
|
export
|
|
pclose : HasIO io => File -> io ()
|
|
pclose (FHandle h) = primIO (prim__pclose h)
|