IPC via named pipe: Difference between revisions

Added FreeBASIC
m (→‎{{header|Wren}}: Minor tidy)
(Added FreeBASIC)
 
Line 103:
return 0;
}</syntaxhighlight>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">#Include "file.bi"
 
Type FileInfo
As String path
As Integer oflag
End Type
 
Function OpenFile(file As FileInfo) As Integer
Dim As Integer f = Freefile
Open file.path For Binary Access Read Write As #f
If Lof(f) > 0 Then
Print "Error opening file"
Return -1
End If
Return f
End Function
 
Function ReadFromFile(f As Integer, Byref buf As String, size As Integer) As Integer
Get #f, , buf
Return Len(buf)
End Function
 
Sub WriteToFile(f As Integer, buf As String, size As Integer)
Put #f, , buf
End Sub
 
Dim As FileInfo inputFile
inputFile.path = "in.fifo"
inputFile.oflag = 0
 
Dim As FileInfo outputFile
outputFile.path = "out.fifo"
outputFile.oflag = 1
 
Dim As Integer entrada = OpenFile(inputFile)
Dim As Integer salida = OpenFile(outputFile)
 
If entrada = -1 Or salida = -1 Then
Print "Error opening files"
End
End If
 
Dim As String buffer
Dim As Integer bytesRead
Do
bytesRead = ReadFromFile(entrada, buffer, 64)
If bytesRead > 0 Then WriteToFile(salida, buffer, bytesRead)
Loop</syntaxhighlight>
 
=={{header|Go}}==
2,139

edits