Changeset 9001
- Timestamp:
- Sep 26, 2006, 5:28:52 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psSlurp.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psSlurp.c
r8996 r9001 5 5 * @author Joshua Hoblitt, University of Hawaii 6 6 * 7 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $8 * @date $Date: 2006-09-27 0 0:59:58$7 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-09-27 03:28:52 $ 9 9 * 10 10 * Copyright 2006 University of Hawaii … … 25 25 psString psSlurpFD(int fd) 26 26 { 27 psString str = NULL;28 size_t s trSize = 1;// bytes allocated - make sure there is room for '\0'29 size_t used = 0;// bytes actually used30 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 { 32 32 // increase the allocated string size 33 s trSize += SLURP_SIZE;34 str = psRealloc(str, s trSize);33 size += SLURP_SIZE; 34 str = psRealloc(str, size); 35 35 36 36 // read a block from the stream 37 ssize_tbytes = read(fd, str + used, SLURP_SIZE);37 bytes = read(fd, str + used, SLURP_SIZE); 38 38 if (bytes < 0) { 39 39 // it's an error 40 psError(PS_ERR_IO, true, "slurp failed ");40 psError(PS_ERR_IO, true, "slurp failed on read"); 41 41 psFree(str); 42 42 return NULL; 43 43 } 44 44 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; 49 47 50 used += bytes; 51 } 48 } while (bytes != 0); 52 49 53 50 // append '\0' to the end of the string
Note:
See TracChangeset
for help on using the changeset viewer.
