IPCPOSIX на примере QNX Neutrino (Отчет о выполнении научно-исследовательской работы), страница 5

      {

            printf(" CLIENT ERR (chan2 creating) \n");

            return -1;

      }

      int f_read;

      int f_write;

      f_read = open(chan1,O_RDONLY);

      if (!f_read)

      {

            printf("\nCLIENT ERR (chan1 openning)");

            return -1;

      }

      f_write = open(chan2,O_WRONLY);

      if (!f_write)

      {

            printf("\n CLIENT ERR (chan2 openning)");

            return -1;

      }

      client(f_read,f_write);

      close(f_read);

      close(f_write);

      unlink("chan1");

      unlink("chan2");

      return 0;

};

void client(int fdr, int fdw)

{

      char FNamebuf[c_bsize];

      char

buf[c_bsize];

      int num;

      num = read(fdr,FNamebuf,c_bsize);

      if( num < 0)

      {

            printf("\n CLIENT ERR (reading)");

            return -1;

      }    

      int f_in;  

      f_in=fopen(FNamebuf,"r");

      if (!f_in)

      {

            printf("\n CLIENT ERR (openning file %s)", FNamebuf);

            return -1;

      }

      int i=0;

      while(      (fscanf(f_in,"%c",&buf[i]))!=EOF)

            i++;

      close(f_in);

      printf("client read from file %s\n [%s]\n" ,FNamebuf,buf);

      if (write(fdw,buf,strlen(buf))<0)

      {

            printf("\n CLIENT ERR (writing)");

            return -1;

      }

      return;

}

Server.c

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <string.h>

#include <errno.h>

const int c_bsize=256;

char* chan1="chan1";

char* chan2="chan2";

char* FName;

int main (int argc, char* argv[])

{

      if(argc < 2)

      {

            printf("Input file \n");

            return -1;

      }

      FName = argv[1];

      printf("file name %s \n", FName);

      int k = mkfifo("chan1", 0666);

      if ((k=-1)&&(errno!=EEXIST))

      {

            printf("SERVER ERR (chan1) \n");

            return -1;

      }

      k = mkfifo(chan2, 0666);

      if ((k=-1)&&(errno!=EEXIST))

      {

            printf("SERVER ERR (chan2) \n");

            return -1;

      }

      int f_read;

      int f_write;

      f_write = open("chan1",O_WRONLY);

      if (!f_write)

      {

            printf("\nSERVER ERR (problem with writing ch1) \n");

            return -1;

      }

      f_read = open("chan2",O_RDONLY);

      if (!f_read)

      {

            printf("\n SERVER ERR (problem with reading ch2) \n");

            return -1;

      }

      server(f_read,f_write);

      close(f_read);   

      close(f_write);

      return 0;

}

void server(int fdr, int fdw)

{

      char buf[c_bsize];     

      int num;

            printf("file name2 %s %d \n", FName, strlen(FName));

      if (write(fdw,FName,strlen(FName)+1)<0)

      {

            printf("\nSERVER ERR (writing)");