Check the return value of I/O operations for failure

This commit is contained in:
Nathan Binkert 2008-09-19 09:11:42 -07:00
parent f066db7fcd
commit ea83cedcf6
3 changed files with 13 additions and 5 deletions

View file

@ -65,7 +65,9 @@ HexFile::loadSections(Port *memPort)
Addr MemAddr;
uint32_t Data;
while (!feof(fp)) {
fgets(Line, 64, fp);
char *ret = fgets(Line, sizeof(Line), fp);
if (!ret)
panic("malformed file");
parseLine(Line, &MemAddr, &Data);
if (MemAddr != 0) {
// Now, write to memory

View file

@ -346,14 +346,16 @@ uint8_t
BaseRemoteGDB::getbyte()
{
uint8_t b;
::read(fd, &b, 1);
if (::read(fd, &b, 1) != 1)
warn("could not read byte from debugger");
return b;
}
void
BaseRemoteGDB::putbyte(uint8_t b)
{
::write(fd, &b, 1);
if (::write(fd, &b, 1) != 1)
warn("could not write byte to debugger");
}
// Send a packet to gdb

View file

@ -182,8 +182,12 @@ EtherTap::recvPacket(EthPacketPtr packet)
DPRINTF(Ethernet, "EtherTap output len=%d\n", packet->length);
DDUMP(EthernetData, packet->data, packet->length);
uint32_t len = htonl(packet->length);
write(socket, &len, sizeof(len));
write(socket, packet->data, packet->length);
ssize_t ret = write(socket, &len, sizeof(len));
if (ret != sizeof(len))
return false;
ret = write(socket, packet->data, packet->length);
if (ret != packet->length)
return false;
interface->recvDone();