aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/catapult_dct2000.c
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2007-09-25 19:59:50 +0000
committerBill Meier <wmeier@newsguy.com>2007-09-25 19:59:50 +0000
commit151a51d956d21667f3afb8c4cfce7701b6f2f80d (patch)
tree7c161590a20ad84de6c0e23b88122a1929ffcf48 /wiretap/catapult_dct2000.c
parent4d4c9a4d34535c89b4f4a6e695ce19f6c5cfa600 (diff)
Add error checking for fwrites; replacement for one of patches provided in bug #1864
svn path=/trunk/; revision=22964
Diffstat (limited to 'wiretap/catapult_dct2000.c')
-rw-r--r--wiretap/catapult_dct2000.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c
index c621ed6948..25772359db 100644
--- a/wiretap/catapult_dct2000.c
+++ b/wiretap/catapult_dct2000.c
@@ -570,9 +570,24 @@ int catapult_dct2000_dump_can_write_encap(int encap)
/*****************************************/
/* Write a single packet out to the file */
/*****************************************/
+
+static gboolean do_fwrite(const void *data, size_t size, size_t count, FILE *stream, int *err_p) {
+ size_t nwritten;
+
+ nwritten = fwrite(data, size, count, stream);
+ if (nwritten != count) {
+ if (nwritten == 0 && ferror(stream))
+ *err_p = errno;
+ else
+ *err_p = WTAP_ERR_SHORT_WRITE;
+ return FALSE;
+ }
+ return TRUE;
+}
+
gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const union wtap_pseudo_header *pseudo_header,
- const guchar *pd, int *err _U_)
+ const guchar *pd, int *err)
{
guint32 n;
line_prefix_info_t *prefix = NULL;
@@ -591,14 +606,18 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
wdh->dump.dct2000 = g_malloc(sizeof(catapult_dct2000_t));
/* Write out saved first line */
- fwrite(file_externals->firstline, 1, file_externals->firstline_length, wdh->fh);
- fwrite("\n", 1, 1, wdh->fh);
+ if (! do_fwrite(file_externals->firstline, 1, file_externals->firstline_length, wdh->fh, err))
+ return FALSE;
+ if (! do_fwrite("\n", 1, 1, wdh->fh, err))
+ return FALSE;
/* Also write out saved second line with timestamp corresponding to the
opening time of the log.
*/
- fwrite(file_externals->secondline, 1, file_externals->secondline_length, wdh->fh);
- fwrite("\n", 1, 1, wdh->fh);
+ if (! do_fwrite(file_externals->secondline, 1, file_externals->secondline_length, wdh->fh, err))
+ return FALSE;
+ if (! do_fwrite("\n", 1, 1, wdh->fh, err))
+ return FALSE;
/* Allocate the dct2000-specific dump structure */
wdh->dump.dct2000 = g_malloc(sizeof(catapult_dct2000_t));
@@ -622,7 +641,8 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
(const void*)&(pseudo_header->dct2000.seek_off));
/* Write out text before timestamp */
- fwrite(prefix->before_time, 1, strlen(prefix->before_time), wdh->fh);
+ if (! do_fwrite(prefix->before_time, 1, strlen(prefix->before_time), wdh->fh, err))
+ return FALSE;
/* Calculate time of this packet to write, relative to start of dump */
if (phdr->ts.nsecs >= wdh->dump.dct2000->start_time.nsecs)
@@ -639,16 +659,19 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
}
/* Write out the calculated timestamp */
- fwrite(time_string, 1, strlen(time_string), wdh->fh);
+ if (! do_fwrite(time_string, 1, strlen(time_string), wdh->fh, err))
+ return FALSE;
/* Write out text between timestamp and start of hex data */
if (prefix->after_time == NULL)
{
- fwrite(" l ", 1, strlen(" l "), wdh->fh);
+ if (! do_fwrite(" l ", 1, strlen(" l "), wdh->fh, err))
+ return FALSE;
}
else
{
- fwrite(prefix->after_time, 1, strlen(prefix->after_time), wdh->fh);
+ if (! do_fwrite(prefix->after_time, 1, strlen(prefix->after_time), wdh->fh, err))
+ return FALSE;
}
@@ -684,7 +707,8 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/**************************************/
/* Remainder is encapsulated protocol */
- fwrite("$", 1, 1, wdh->fh);
+ if (! do_fwrite("$", 1, 1, wdh->fh, err))
+ return FALSE;
/* Each binary byte is written out as 2 hex string chars */
for (; n < phdr->len; n++)
@@ -694,11 +718,13 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
c[1] = char_from_hex((guchar)(pd[n] & 0x0f));
/* Write both hex chars of byte together */
- fwrite(c, 1, 2, wdh->fh);
+ if (! do_fwrite(c, 1, 2, wdh->fh, err))
+ return FALSE;
}
/* End the line */
- fwrite("\n", 1, 1, wdh->fh);
+ if (! do_fwrite("\n", 1, 1, wdh->fh, err))
+ return FALSE;
return TRUE;
}