//pipe/server.с #include #include #include #include #include #include #include #include #include #define MAXLINE 180 void server(char * read, char * write) { FILE *readfd, *writefd, *fd; ssize_t n; char buff[MAXLINE+1]; printf("Server wait...\n"); readfd=fopen(read,"r"); //printf("Descriptors: read=%p, write=%p\n", readfd, writefd); /* получение полного имени из канала IPC */ fgets(buff,MAXLINE,readfd); printf("Server get %s.",buff); n=strlen(buff); printf("Get %d bytes\n",n); fclose(readfd); writefd=fopen(write,"w"); buff[n] = '\0'; /* полное имя завершается 0 */ fd = fopen(buff, "r"); printf("Desc=%p\n", fd); if (!fd) { /* 4error must tell client */ snprintf(buff+n, sizeof(buff)-n,": can't open %s\n",strerror(errno)); //n = strlen(buff); printf("Sending error:%s\n",buff); fprintf(writefd, "%s",buff); } else { /* файл успешно открыт и копируется в канал */ printf("Server sending responce\n"); while ( (fgets(buff, MAXLINE,fd)) > 0) { fprintf(writefd,"%s",buff); //printf("Server sent %d bytes\n",n); } fclose(fd); fclose(writefd); } }