"Fossies" - the Fresh Open Source Software Archive

Member "mlmmj-1.3.0/contrib/receivestrip/mlmmj_src/dumpfd2fd.c" (6 Jul 2010, 1625 Bytes) of package /linux/privat/mlmmj-1.3.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj dot dk>
    2  *
    3  * $Id$
    4  *
    5  * Permission is hereby granted, free of charge, to any person obtaining a copy
    6  * of this software and associated documentation files (the "Software"), to
    7  * deal in the Software without restriction, including without limitation the
    8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    9  * sell copies of the Software, and to permit persons to whom the Software is
   10  * furnished to do so, subject to the following conditions:
   11  *
   12  * The above copyright notice and this permission notice shall be included in
   13  * all copies or substantial portions of the Software.
   14  *
   15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   21  * IN THE SOFTWARE.
   22  */
   23 
   24 #include <sys/types.h>
   25 #include <sys/stat.h>
   26 #include <fcntl.h>
   27 #include <unistd.h>
   28 #include <errno.h>
   29 
   30 #include "wrappers.h"
   31 
   32 #define DUMPBUF 4096
   33 
   34 int dumpfd2fd(int infd, int outfd)
   35 {
   36     size_t n;
   37     char buf[DUMPBUF];
   38 
   39     while((n = read(infd, &buf, sizeof(buf))) != 0) {
   40         if(n < 0) {
   41             if(errno == EINTR)
   42                 continue;
   43             else
   44                 return -1; /* Caller can check errno */
   45         }
   46         if(writen(outfd, &buf, n) < 0)
   47             return -1; /* Caller can check errno */
   48     }
   49     
   50     return 0;
   51 }