IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8996


Ignore:
Timestamp:
Sep 26, 2006, 2:59:58 PM (20 years ago)
Author:
jhoblitt
Message:

rename psSlurp() -> psSlurpFD()
change psSlurpFile() to be a wrapper around psSlurpFD() (instead of vice versa)

Location:
trunk/psLib/src/sys
Files:
2 edited

Legend:

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

    r8994 r8996  
    55 *  @author Joshua Hoblitt, University of Hawaii
    66 *
    7  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-09-27 00:43:31 $
     7 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-09-27 00:59:58 $
    99 *
    1010 *  Copyright 2006 University of Hawaii
     
    1515#endif
    1616
    17 #include <stdio.h>
     17#include <unistd.h>
    1818
    1919#include "psError.h"
     
    2121#include "psMemory.h"
    2222
    23 # define SLURP_SIZE 1024
     23#define SLURP_SIZE 4096
    2424
    25 psString psSlurp(int fd)
    26 {
    27     FILE *stream = fdopen(fd, "r");
    28 
    29     return psSlurpFile(stream);
    30 }
    31 
    32 psString psSlurpFile(FILE *stream)
     25psString psSlurpFD(int fd)
    3326{
    3427    psString str    = NULL;
     
    4235
    4336        // read a block from the stream
    44         size_t bytes = fread(str + used, 1, SLURP_SIZE, stream);
    45         used += bytes;
    46 
    47         // is this the end of the file or an error?
    48         if (bytes != SLURP_SIZE) {
    49             if (feof(stream)) {
    50                 // eof
    51                 break;
    52             }
    53             // else - it's an error
    54             psError(PS_ERR_UNKNOWN, true, "slurp failed");
     37        ssize_t bytes = read(fd, str + used, SLURP_SIZE);
     38        if (bytes < 0) {
     39            // it's an error
     40            psError(PS_ERR_IO, true, "slurp failed");
    5541            psFree(str);
    5642            return NULL;
    5743        }
     44
     45        // is this the end of the file?
     46        if (bytes == SLURP_SIZE) {
     47            break;
     48        }
     49
     50        used += bytes;
    5851    }
    5952
     
    6356    return str;
    6457}
     58
     59psString psSlurpFile(FILE *stream)
     60{
     61    return psSlurpFD(fileno(stream));
     62}
  • trunk/psLib/src/sys/psSlurp.h

    r8994 r8996  
    22#include <pslib.h>
    33
    4 psString psSlurp(int fd);
     4psString psSlurpFD(int fd);
    55psString psSlurpFile(FILE *stream);
Note: See TracChangeset for help on using the changeset viewer.