Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/user/testbin/ft2/ft2.c
738 views
1
#include <unistd.h>
2
#include <stdio.h>
3
#include <stdlib.h>
4
5
#define BUF_SIZE 128
6
7
int main( int argc, char *argv[] ) {
8
int fd_stdout;
9
int fd_in;
10
char buf[BUF_SIZE];
11
int nread;
12
13
(void)argc;
14
(void)argv;
15
16
//attempt to open stdout
17
fd_stdout = open( "con:", O_WRONLY );
18
if( fd_stdout == -1 )
19
return -1;
20
21
//attempt to open input file
22
fd_in = open( "/hello.txt", O_RDONLY );
23
if( fd_in == -1 ) {
24
close( fd_stdout );
25
return -1;
26
}
27
28
//read and output to stdout
29
while( ( nread = read( fd_in, buf, sizeof( buf ) ) ) > 0 )
30
write( fd_stdout, buf, nread );
31
32
//close the files
33
close( fd_in );
34
close( fd_stdout );
35
36
return 0;
37
}
38
39