Changeset 698a217
- Timestamp:
- 04/23/06 14:21:02 (15 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- e4e95499
- Parents:
- 4315572b
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libtraceio-stdio.c
r4315572b r698a217 5 5 #include <stdio.h> 6 6 #include <stdlib.h> 7 8 #include <errno.h> /* for debugging */9 7 10 8 struct libtrace_io_t { … … 17 15 18 16 if (ret==(int)len) { 19 printf("read %i bytes\n",ret);20 17 return len; 21 18 } … … 23 20 /* EOF or an Error occurred */ 24 21 if (ferror(io->file)) { 25 int err=errno;26 perror("fread");27 errno=err;28 22 /* errno will be set */ 29 23 return -1; 30 24 } 31 32 printf("eof\n");33 25 34 26 return 0; /* EOF */ … … 61 53 ssize_t libtrace_io_write(libtrace_io_t *io, const void *buf, size_t len) 62 54 { 63 return fwrite(buf,len,1,io->file); 55 int ret=fwrite(buf,1,len,io->file); 56 if (ret==len) { 57 return ret; 58 } 59 60 /* Error occurred? */ 61 if (ferror(io->file)) 62 return -1; /* errno will already be set */ 63 64 return 0; /* eof */ 64 65 } 65 66 -
lib/libtraceio.h
redb18ce r698a217 10 10 typedef struct libtrace_io_t libtrace_io_t; 11 11 12 /** read a block from a file 13 * @param io the io file object 14 * @param buf the buffer to read into 15 * @param len the number of bytes to read 16 * 17 * @returns -1 on error (with errno set), 0 on eof, otherwise the number of bytes 18 * read. 19 */ 12 20 ssize_t libtrace_io_read(libtrace_io_t *io, void *buf, size_t len); 21 /** open a file from a file descriptor (like fdopen(3)) 22 * @param fd file descriptor to read 23 * @param mode text string to represent what mode to read the file in. 24 * 25 * @returns io object, or NULL on error. 26 */ 13 27 libtrace_io_t *libtrace_io_fdopen(int fd, const char *mode); 28 /** open a file from a path name 29 * @param path pathname to read 30 * @param mode text string to represent what mode to read the file in. 31 * 32 * @returns io object, or NULL on error. 33 */ 14 34 libtrace_io_t *libtrace_io_open(const char *path, const char *mode); 35 /** close a file and free all of it's resources. 36 * @param io io object 37 * 38 * This function doesn't return anything. In theory it could return an error 39 * but seriously, if it did return an error, what would you do about it? 40 */ 15 41 void libtrace_io_close(libtrace_io_t *io); 42 43 /** write a block of data to a file 44 * @param io libtrace io object to write to 45 * @param buf buffer to write to 46 * @param len number of bytes to write 47 * 48 * @returns the number of bytes successfully written, or -1 on error with 49 * errno set 50 */ 16 51 ssize_t libtrace_io_write(libtrace_io_t *io, const void *buf, size_t len); 17 52 off_t libtrace_io_seek(libtrace_io_t *io, off_t offset, int whence);
Note: See TracChangeset
for help on using the changeset viewer.