IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9001


Ignore:
Timestamp:
Sep 26, 2006, 5:28:52 PM (20 years ago)
Author:
Paul Price
Message:

Fixing problem caused by wrong exit condition. Tidied up code some too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psSlurp.c

    r8996 r9001  
    55 *  @author Joshua Hoblitt, University of Hawaii
    66 *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-09-27 00:59:58 $
     7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-09-27 03:28:52 $
    99 *
    1010 *  Copyright 2006 University of Hawaii
     
    2525psString psSlurpFD(int fd)
    2626{
    27     psString str    = NULL;
    28     size_t strSize  = 1; // bytes allocated -  make sure there is room for '\0'
    29     size_t used     = 0; // bytes actually used
    30 
    31     for (;;) {
     27    psString str = NULL;                // String to which to write
     28    size_t size  = 1;                  // bytes allocated -  make sure there is room for '\0'
     29    size_t used = 0;                    // bytes actually used
     30    ssize_t bytes;                      // Number of bytes read
     31    do {
    3232        // increase the allocated string size
    33         strSize += SLURP_SIZE;
    34         str = psRealloc(str, strSize);
     33        size += SLURP_SIZE;
     34        str = psRealloc(str, size);
    3535
    3636        // read a block from the stream
    37         ssize_t bytes = read(fd, str + used, SLURP_SIZE);
     37        bytes = read(fd, str + used, SLURP_SIZE);
    3838        if (bytes < 0) {
    3939            // it's an error
    40             psError(PS_ERR_IO, true, "slurp failed");
     40            psError(PS_ERR_IO, true, "slurp failed on read");
    4141            psFree(str);
    4242            return NULL;
    4343        }
    4444
    45         // is this the end of the file?
    46         if (bytes == SLURP_SIZE) {
    47             break;
    48         }
     45        // Increase the size of the known string
     46        used += bytes;
    4947
    50         used += bytes;
    51     }
     48    } while (bytes != 0);
    5249
    5350    // append '\0' to the end of the string
Note: See TracChangeset for help on using the changeset viewer.