Changeset 8996
- Timestamp:
- Sep 26, 2006, 2:59:58 PM (20 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psSlurp.c
r8994 r8996 5 5 * @author Joshua Hoblitt, University of Hawaii 6 6 * 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 $ 9 9 * 10 10 * Copyright 2006 University of Hawaii … … 15 15 #endif 16 16 17 #include < stdio.h>17 #include <unistd.h> 18 18 19 19 #include "psError.h" … … 21 21 #include "psMemory.h" 22 22 23 # define SLURP_SIZE 102423 #define SLURP_SIZE 4096 24 24 25 psString psSlurp(int fd) 26 { 27 FILE *stream = fdopen(fd, "r"); 28 29 return psSlurpFile(stream); 30 } 31 32 psString psSlurpFile(FILE *stream) 25 psString psSlurpFD(int fd) 33 26 { 34 27 psString str = NULL; … … 42 35 43 36 // 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"); 55 41 psFree(str); 56 42 return NULL; 57 43 } 44 45 // is this the end of the file? 46 if (bytes == SLURP_SIZE) { 47 break; 48 } 49 50 used += bytes; 58 51 } 59 52 … … 63 56 return str; 64 57 } 58 59 psString psSlurpFile(FILE *stream) 60 { 61 return psSlurpFD(fileno(stream)); 62 } -
trunk/psLib/src/sys/psSlurp.h
r8994 r8996 2 2 #include <pslib.h> 3 3 4 psString psSlurp (int fd);4 psString psSlurpFD(int fd); 5 5 psString psSlurpFile(FILE *stream);
Note:
See TracChangeset
for help on using the changeset viewer.
