"Fossies" - the Fresh Open Source Software Archive

Member "mlmmj-1.3.0/contrib/receivestrip/mlmmj_src/writen.c" (6 Jul 2010, 1674 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) 2002, 2003 Mads Martin Joergensen <mmj at mmj.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 <unistd.h>
   26 #include <errno.h>
   27 
   28 /**
   29  * write n bytes to a descriptor 
   30  */
   31 
   32 ssize_t writen(int fd, const void *vptr, size_t n)
   33 {
   34     size_t nleft;
   35     ssize_t nwritten;
   36     const char *ptr;
   37 
   38     ptr = (const char*)vptr;
   39     nleft = n;
   40     while(nleft > 0) {
   41         if((nwritten = write(fd, ptr, nleft)) < 0) {
   42             if(errno == EINTR) {
   43                 nwritten = 0; /* and call write() again */
   44             } else {
   45                 return -1; /* error, caller can check errno */
   46             }
   47         }
   48         nleft -= nwritten;
   49         ptr += nwritten;
   50     }
   51     return n;
   52 }