7 int Open (const char* Name, int Flags)
10 printf ("Opening %s: ", Name);
11 fd = open (Name, Flags);
18 void Write (int fd, const void* Buf, unsigned Size)
21 Res = write (fd, Buf, Size);
22 printf ("Writing %u bytes to %d: %d\n", Size, fd, Res);
27 int Read (int fd, void* Buf, unsigned Size)
30 Res = read (fd, Buf, Size);
31 printf ("Reading %u bytes from %d: %d\n", Size, fd, Res);
32 return Res > 0? Res : 0;
39 printf ("Closing %d: %d\n", fd, close (fd));
48 static const char text1[] = "This goes into file #1\n";
49 static const char text2[] = "This goes into file #2\n";
50 static const char text3[] = "This goes into file #3\n";
51 static const char text4[] = "This goes into file #4\n";
55 fd1 = Open ("foobar1", O_WRONLY|O_CREAT|O_TRUNC);
56 fd2 = Open ("foobar2", O_WRONLY|O_CREAT|O_TRUNC);
58 Write (fd1, text1, sizeof (text1) - 1);
59 Write (fd2, text2, sizeof (text2) - 1);
60 Write (fd1, text1, sizeof (text1) - 1);
61 Write (fd2, text2, sizeof (text2) - 1);
66 fd1 = Open ("foobar3", O_WRONLY|O_CREAT|O_TRUNC);
67 fd2 = Open ("foobar4", O_WRONLY|O_CREAT|O_TRUNC);
69 Write (fd1, text3, sizeof (text3) - 1);
70 Write (fd2, text4, sizeof (text4) - 1);
71 Write (fd1, text3, sizeof (text3) - 1);
72 Write (fd2, text4, sizeof (text4) - 1);
77 fd1 = Open ("foobar1", O_RDONLY);
78 Res = Read (fd1, Buf, sizeof (Buf));
79 printf ("%.*s", Res, Buf);
80 Res = Read (fd1, Buf, sizeof (Buf));