/* program taken from J.Kehres Slow Control , 19/2/91 */ #include #include int create_pipe(pipe_name,structure_size) char *pipe_name; int structure_size; { int _gs_count; /* count of characters in pipe */ char residual_buffer[8]; /* receives residual pipe bytes */ int pipe_path; /* returned by function create_pipe */ int read_length; /* number of characters read from pipes */ int ev_value; /* value for setting semaphore stt_event_id if pipe cannot be created. */ /* Try to open pipe_name if it still exists: 1. read any residual data from pipe 2. close pipe_path */ if (( pipe_path = open(pipe_name, S_IREAD )) < 0) { /* fprintf(stderr,"status, no previous pipe_path \n"); */ } else { fprintf(stderr,"status, pipe_path: %d \n", pipe_path); _gs_count = _gs_rdy(pipe_path); if (_gs_count > 0 ) while (_gs_count > 0) { printf("status, residual bytes: %d ,pipe_name: %s \n", _gs_count,pipe_name); read_length = read(pipe_path, residual_buffer,sizeof(residual_buffer)); _gs_count = _gs_rdy(pipe_path); } close(pipe_path); } /* create also opens a path to the pipe and allows the specification of the length of the pipe buffer. We are NOT using fopen to open a file, because we want to fill the pipe with the write function which will complete uninterrupted by a time slicing. Function write uses a path. Functions fprint and fwrite use FILE pointers, not paths, and to use these functions the pipe would have to be opened with function fopen. */ if ((pipe_path = create(pipe_name, S_IREAD | S_IWRITE | S_ISIZE, S_IREAD | S_IWRITE, structure_size )) < 0) { fprintf(stderr," create pipe failure %s. Error %d. \n", pipe_name,errno); exit(errno); } else { /* fprintf(stderr," create pipe success %s, path: %d \n", pipe_name, pipe_path); */ } return pipe_path; }