- Main Page
- Data Structures
- Files
- Related Pages

- File List
- Globals

# fifoutil.h

Go to the documentation of this file.

    00001
    00019 #ifndef _FIFOUTIL_H
    00020 #define _FIFOUTIL_H
    00021
    00022 #include <unistd.h>
    00023
    00027 typedef struct FifoUtil_Obj {
    00028     size_t size;
    00029     int pipes[2];
    00030 } FifoUtil_Obj;
    00031
    00035 typedef FifoUtil_Obj *FifoUtil_Handle;
    00036
    00040 #define FIFOUTIL_SUCCESS 0
    00041 #define FIFOUTIL_FAILURE -1
    00042
    00049 static inline int FifoUtil_open(FifoUtil_Handle hFifo, size_t size)
    00050 {
    00051     if (pipe(hFifo->pipes)) {
    00052         return FIFOUTIL_FAILURE;
    00053     }
    00054
    00055     hFifo->size = size;
    00056
    00057     return FIFOUTIL_SUCCESS;
    00058 }
    00059
    00065 static inline int FifoUtil_close(FifoUtil_Handle hFifo)
    00066 {
    00067     int ret = FIFOUTIL_SUCCESS;
    00068
    00069     if (close(hFifo->pipes[0])) {
    00070         ret = FIFOUTIL_FAILURE;
    00071     }
    00072
    00073     if (close(hFifo->pipes[1])) {
    00074         ret = FIFOUTIL_FAILURE;
    00075     }
    00076
    00077     return ret;
    00078 }
    00079
    00086 static inline int FifoUtil_get(FifoUtil_Handle hFifo, void *buffer)
    00087 {
    00088     if (read(hQueue->pipes[0], buffer, hQueue->size) != hQueue->size) {
    00089         return FIFOUTIL_FAILURE;
    00090     }
    00091
    00092     return FIFOUTIL_SUCCESS;
    00093 }
    00094
    00101 static inline int FifoUtil_put(FifoUtil_Handle hFifo, void *buffer)
    00102 {
    00103     if (write(hQueue->pipes[1], buffer, hQueue->size) != hQueue->size) {
    00104         return FIFOUTIL_FAILURE;
    00105     }
    00106
    00107     return FIFOUTIL_SUCCESS;
    00108 }
    00109
    00110 #endif // _FIFOUTIL_H

Copyright 2006, Texas Instruments Incorporated