|
|
1.1 ! root 1: /* fifo_write.c -- Routines for writing to internally typed fifos. */ ! 2: #include <sys/typed.h> ! 3: ! 4: /* Write a typed space into a FIFO. */ ! 5: typed_space * ! 6: fifo_write(ffp, space) ! 7: FIFO *ffp; ! 8: typed_space *space; ! 9: { ! 10: return (fifo_write_untyped( ! 11: ffp, ! 12: space->ts_data, ! 13: (long) (space->ts_size - sizeof(typed_space)), ! 14: space->ts_type) ! 15: ); ! 16: } /* fifo_write() */ ! 17: ! 18: /* Write a chunk of data into an open fifo as a typed space. ! 19: * Takes a FIFO to be written to, ffp; a pointer to the data, datum; a ! 20: * size for the datum, size; and a type for the new space, type. ! 21: * ! 22: * Returns a pointer to the newly written space. Returns NULL if the ! 23: * new space could not be written. ! 24: * ! 25: * Note that while sizes throughout this package refer to TOTAL sizes ! 26: * including headers, the size argument here is ONLY for the datum. ! 27: * ! 28: * Only FIFOs of type T_FIFO_SIC are implimented. ! 29: */ ! 30: typed_space * ! 31: fifo_write_untyped(ffp, datum, size, type) ! 32: FIFO *ffp; ! 33: char *datum; ! 34: long size; ! 35: space_type type; ! 36: { ! 37: long needed_space; /* Total space we need to add. */ ! 38: typed_space *retval; /* Return the space we just wrote. */ ! 39: ! 40: /* Write MUST be set. */ ! 41: if (F_WRITE != F_WRITE & ffp->f_flags ) { ! 42: return(T_NULL); /* This ffp is not open for writing. */ ! 43: } ! 44: ! 45: /* From here to end of fifo_write_untyped() is really fifo_write_sic(). */ ! 46: ! 47: /* Check to see that there is enough space for the new datum. ! 48: * We need space for another typed_space header, size bytes of ! 49: * data, and space for a terminating typed_space header. ! 50: */ ! 51: needed_space = sizeof(typed_space) + size + sizeof(typed_space); ! 52: ! 53: if (ffp->f_space->ts_size < ! 54: ((char *)ffp->f_offset - (char *)ffp->f_space) + needed_space) { ! 55: return(T_NULL); /* Insufficient space. */ ! 56: } ! 57: ! 58: /* ASSERTION: There is enough space remaining in ffp->f_space for ! 59: * two more headers and the datum. ! 60: */ ! 61: ! 62: retval = ffp->f_offset; ! 63: ! 64: /* Create the new header. */ ! 65: ffp->f_offset->ts_size = sizeof(typed_space) + size; ! 66: ffp->f_offset->ts_type = type; ! 67: ! 68: /* Copy the datum in place. */ ! 69: memcpy(ffp->f_offset->ts_data, datum, size); ! 70: ! 71: /* Advance the write pointer. */ ! 72: ffp->f_offset += 1; /* Skip the header. */ ! 73: (char *) ffp->f_offset += size; /* Skip the data. */ ! 74: ! 75: /* Terminate the fifo. */ ! 76: ffp->f_offset->ts_size = (long) 0; ! 77: ffp->f_offset->ts_type = T_UNKNOWN; ! 78: ! 79: return(retval); ! 80: } /* fifo_write_untyped() */ ! 81:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.