I was tasked to make a file copy over ipc shared memory. The problem is that getc randomly yeilds EOF after 32k char.
FILE* file;
int znak;
file = fopen("./source","r");
if(file != NULL)
{
while(feof(file) == 0)
{
znak = getc(file);
if(znak != EOF)
{
czekaj(0);
*adres = znak;
sygnal(1);
}
}
wait(0); //Wait for your turn
*adres = EOF;
signal(1); //Let other process go
}
Writing part as requested
int znak
FILE *plik;
plik = fopen("./plik_klient", "w");
fclose(plik);
.....
plik = fopen("./result","a");
if(plik != NULL)
{
while(znak != EOF)
{
wait(1); //Opuszczenie semafora
znak=*adres;
if(znak != EOF)
{
fputc(znak,plik);
signal(0);
}
}
}
As a result of work other process reads the info and writes it into file.
-rw-r--r--. 1 ficekba inf-17 32769 01-11 21:15 result
-rw-r--r--. 1 ficekba inf-17 1000000 01-11 21:13 source
As you can see result file has exactly 32k