Nut/OS  4.10.3
API Reference
null.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2000-2004 by ETH Zurich
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
00021  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /* @file null.c - a nut/os null device driver
00035  * @brief A /dev/null device driver
00036  * This can be useful if your application might write unwanted output to stdout.
00037  * With this deveice you can redirect stdout to the nullDev which discards any output
00038  * Any IOCTL will result in OK, and any read will give back zero read bytes
00039  *
00040  * 2005.06.21 Matthias Ringwald <matthias.ringwald@inf.ethz.ch>
00041  *
00042  */
00043 
00044 #include <compiler.h>
00045 #include <stdlib.h>
00046 
00047 #include <sys/file.h>
00048 #include <sys/device.h>
00049 
00054 
00060 static NUTFILE *NullOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc)
00061 {
00062     NUTFILE *nf;
00063 
00064     nf = malloc(sizeof(NUTFILE));
00065 
00066     // enter data
00067     nf->nf_next = 0;
00068     nf->nf_dev = dev;
00069 
00070     return nf;
00071 }
00072 
00073 
00079 static int NullWrite(NUTFILE * nf, CONST void *buffer, int len)
00080 {
00081     return len;
00082 }
00083 #ifdef __HARVARD_ARCH__
00084 static int NullWriteP(NUTFILE * nf, PGM_P buffer, int len)
00085 {
00086     return len;
00087 }
00088 #endif
00089 
00090 
00091 
00092  
00098 static int NullRead(NUTFILE * nf, void *buffer, int len)
00099 {
00100     // test for read len. len == 0 => flush fd
00101     if (len == 0){
00102         return 0;
00103     }
00104 
00105         // otherwise also just return 0 bytes without blocking
00106     return 0;
00107 }
00108 
00114 static int NullClose(NUTFILE * nf)
00115 {
00116         if (nf)
00117                 free (nf);
00118     return 0;
00119 }
00120 
00136 int NullIOCTL(NUTDEVICE * dev, int req, void *conf)
00137 {
00138     return 0;
00139 }
00140 
00141 /* ======================= Devices ======================== */
00145 NUTDEVICE devNull = {
00146     0,                          
00147     {'n', 'u', 'l', 'l', 0, 0, 0, 0, 0},
00149     0,                          
00150     0,                          
00151     0,                          
00152     0,                          
00154     0,                          
00155     0,                          
00157     NullIOCTL,                  
00158     NullRead,
00159     NullWrite,
00160 #ifdef __HARVARD_ARCH__
00161     NullWriteP,
00162 #endif
00163     NullOpen,
00164     NullClose,
00165     0
00166 };
00167 
00168