Annotation of embedaddon/miniupnpc/testminiwget.c, revision 1.1.1.2

1.1.1.2 ! misho       1: /* $Id: testminiwget.c,v 1.4 2012/06/23 22:35:59 nanard Exp $ */
1.1       misho       2: /* Project : miniupnp
                      3:  * Author : Thomas Bernard
1.1.1.2 ! misho       4:  * Copyright (c) 2005-2012 Thomas Bernard
1.1       misho       5:  * This software is subject to the conditions detailed in the
                      6:  * LICENCE file provided in this distribution.
                      7:  * */
                      8: #include <stdio.h>
                      9: #include <stdlib.h>
                     10: #include "miniwget.h"
                     11: 
                     12: /**
                     13:  * This program uses the miniwget / miniwget_getaddr function
                     14:  * from miniwget.c in order to retreive a web ressource using
                     15:  * a GET HTTP method, and store it in a file.
                     16:  */
                     17: int main(int argc, char * * argv)
                     18: {
                     19:        void * data;
                     20:        int size, writtensize;
                     21:        FILE *f;
                     22:        char addr[64];
1.1.1.2 ! misho      23: 
1.1       misho      24:        if(argc < 3) {
                     25:                fprintf(stderr, "Usage:\t%s url file\n", argv[0]);
                     26:                fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]);
                     27:                return 1;
                     28:        }
1.1.1.2 ! misho      29:        data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0);
1.1       misho      30:        if(!data) {
                     31:                fprintf(stderr, "Error fetching %s\n", argv[1]);
                     32:                return 1;
                     33:        }
                     34:        printf("local address : %s\n", addr);
                     35:        printf("got %d bytes\n", size);
                     36:        f = fopen(argv[2], "wb");
                     37:        if(!f) {
                     38:                fprintf(stderr, "Cannot open file %s for writing\n", argv[2]);
                     39:                free(data);
                     40:                return 1;
                     41:        }
                     42:        writtensize = fwrite(data, 1, size, f);
                     43:        if(writtensize != size) {
                     44:                fprintf(stderr, "Could only write %d bytes out of %d to %s\n",
                     45:                        writtensize, size, argv[2]);
                     46:        } else {
                     47:                printf("%d bytes written to %s\n", writtensize, argv[2]);
                     48:        }
                     49:        fclose(f);
                     50:        free(data);
                     51:        return 0;
                     52: }
                     53: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>