slirp: avoid compiler warnings for tftp when building with Visual Studio

This commit is contained in:
Mark Pizzolato 2015-10-15 16:04:33 -07:00
parent 40a3e8b635
commit de84430a8d
2 changed files with 10 additions and 10 deletions

View file

@ -37,9 +37,9 @@ static inline void tftp_session_update(struct tftp_session *spt)
static void tftp_session_terminate(struct tftp_session *spt) static void tftp_session_terminate(struct tftp_session *spt)
{ {
if (spt->fd >= 0) { if (spt->f != NULL) {
close(spt->fd); fclose(spt->f);
spt->fd = -1; spt->f = NULL;
} }
g_free(spt->filename); g_free(spt->filename);
spt->slirp = NULL; spt->slirp = NULL;
@ -68,7 +68,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
found: found:
memset(spt, 0, sizeof(*spt)); memset(spt, 0, sizeof(*spt));
memcpy(&spt->client_ip, &tp->ip.ip_src, sizeof(spt->client_ip)); memcpy(&spt->client_ip, &tp->ip.ip_src, sizeof(spt->client_ip));
spt->fd = -1; spt->f = NULL;
spt->client_port = tp->udp.uh_sport; spt->client_port = tp->udp.uh_sport;
spt->slirp = slirp; spt->slirp = slirp;
@ -102,18 +102,18 @@ static int tftp_read_data(struct tftp_session *spt, uint32_t block_nr,
{ {
int bytes_read = 0; int bytes_read = 0;
if (spt->fd < 0) { if (spt->f == NULL) {
spt->fd = open(spt->filename, O_RDONLY | O_BINARY); spt->f = fopen(spt->filename, "rb");
} }
if (spt->fd < 0) { if (spt->f == NULL) {
return -1; return -1;
} }
if (len) { if (len) {
lseek(spt->fd, block_nr * 512, SEEK_SET); fseek(spt->f, block_nr * 512, SEEK_SET);
bytes_read = read(spt->fd, buf, len); bytes_read = fread(buf, 1, len, spt->f);
} }
return bytes_read; return bytes_read;

View file

@ -35,7 +35,7 @@ struct tftp_t {
struct tftp_session { struct tftp_session {
Slirp *slirp; Slirp *slirp;
char *filename; char *filename;
int fd; FILE *f;
struct in_addr client_ip; struct in_addr client_ip;
uint16_t client_port; uint16_t client_port;