8 FILE* Fopen (const char* Name, const char* Mode)
11 printf ("Opening %s(%s): ", Name, Mode);
12 F = fopen (Name, Mode);
14 printf ("Ok (%d)\n", fileno (F));
16 printf (strerror (errno));
23 void Fwrite (FILE* F, const void* Buf, unsigned Size)
26 Res = fwrite (Buf, 1, Size, F);
27 printf ("Writing %u bytes to %d: %u\n", Size, fileno (F), Res);
32 int Fread (FILE* F, void* Buf, unsigned Size)
35 Res = fread (Buf, 1, Size, F);
36 printf ("Reading %u bytes from %d: %u\n", Size, fileno (F), Res);
37 return Res > 0? Res : 0;
44 printf ("Closing %d:", fileno (F));
45 if (fclose (F) == 0) {
48 printf (strerror (errno));
59 static const char text1[] = "This goes into file #1\n";
60 static const char text2[] = "This goes into file #2\n";
61 static const char text3[] = "This goes into file #3\n";
62 static const char text4[] = "This goes into file #4\n";
66 F1 = Fopen ("foobar1", "w");
67 F2 = Fopen ("foobar2", "w");
69 Fwrite (F1, text1, sizeof (text1) - 1);
70 Fwrite (F2, text2, sizeof (text2) - 1);
71 Fwrite (F1, text1, sizeof (text1) - 1);
72 Fwrite (F2, text2, sizeof (text2) - 1);
77 F1 = Fopen ("foobar3", "w");
78 F2 = Fopen ("foobar4", "w");
80 Fwrite (F1, text3, sizeof (text3) - 1);
81 Fwrite (F2, text4, sizeof (text4) - 1);
82 Fwrite (F1, text3, sizeof (text3) - 1);
83 Fwrite (F2, text4, sizeof (text4) - 1);
88 F1 = Fopen ("foobar1", "r");
89 Res = Fread (F1, Buf, sizeof (Buf));
90 printf ("%.*s", Res, Buf);
91 Res = Fread (F1, Buf, sizeof (Buf));