"Fossies" - the Fresh Open Source Software Archive

Member "balance-3.57/butils.c" (28 Apr 2015, 731 Bytes) of package /linux/privat/balance-3.57.tar.gz:


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. For more information about "butils.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2000-2004,2005 by Inlab Software GmbH, Gruenwald, Germany.
    3  * All rights reserved.
    4  *
    5  */
    6 
    7 /*
    8  * $Id: butils.c,v 1.1 2010/01/29 10:40:16 t Exp $
    9  */
   10 
   11 #include <balance.h>
   12 
   13 char* butils_rcsid="$Id: butils.c,v 1.1 2010/01/29 10:40:16 t Exp $";
   14 
   15 unsigned int hash_fold(char* s, int len)
   16 {
   17   unsigned int rc = 0;
   18   int i;
   19   for (i=0; i<len; i++) {
   20     rc = s[i] + 31 * rc;
   21   }
   22 
   23   return(rc);
   24 }
   25 
   26 ssize_t writen(int fd, unsigned char *ptr, size_t nbytes)
   27 {
   28   int nleft;
   29   ssize_t nwritten;
   30 
   31   nleft = nbytes;
   32 
   33   while (nleft > 0) {
   34     nwritten = write(fd, ptr, nleft);
   35     if (nwritten <= 0) {
   36       return (nwritten);    /* error */
   37     }
   38     nleft -= nwritten;
   39     ptr += nwritten;
   40   }
   41 
   42   return (nbytes - nleft);
   43 }
   44