miniupnpc: improve testupnpreplyparse
This commit is contained in:
parent
f67b29e912
commit
1f5ca16931
|
@ -1,7 +1,7 @@
|
||||||
/* $Id: testupnpreplyparse.c,v 1.4 2014/01/27 11:45:19 nanard Exp $ */
|
/* $Id: testupnpreplyparse.c,v 1.4 2014/01/27 11:45:19 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2006-2014 Thomas Bernard
|
* (c) 2006-2017 Thomas Bernard
|
||||||
* This software is subject to the conditions detailed
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* in the LICENCE file provided within the distribution */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -55,8 +55,8 @@ test_parsing(const char * buf, int len, FILE * f)
|
||||||
int main(int argc, char * * argv)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
FILE * f;
|
FILE * f;
|
||||||
char buffer[4096];
|
char * buffer;
|
||||||
int l;
|
long l;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
if(argc<2)
|
if(argc<2)
|
||||||
|
@ -70,7 +70,25 @@ int main(int argc, char * * argv)
|
||||||
fprintf(stderr, "Error : can not open file %s\n", argv[1]);
|
fprintf(stderr, "Error : can not open file %s\n", argv[1]);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
l = fread(buffer, 1, sizeof(buffer)-1, f);
|
if(fseek(f, 0, SEEK_END) < 0) {
|
||||||
|
perror("fseek");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
l = (int)ftell(f);
|
||||||
|
if(l < 0) {
|
||||||
|
perror("ftell");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(fseek(f, 0, SEEK_SET) < 0) {
|
||||||
|
perror("fseek");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
buffer = malloc(l + 1);
|
||||||
|
if(buffer == NULL) {
|
||||||
|
fprintf(stderr, "Error: failed to allocate %ld bytes\n", l+1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
l = fread(buffer, 1, l, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
f = NULL;
|
f = NULL;
|
||||||
buffer[l] = '\0';
|
buffer[l] = '\0';
|
||||||
|
@ -91,6 +109,7 @@ int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
free(buffer);
|
||||||
return ok ? 0 : 3;
|
return ok ? 0 : 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue