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

1.1       misho       1: /* $Id: testminiwget.c,v 1.3 2011/05/06 16:33:53 nanard Exp $ */
                      2: /* Project : miniupnp
                      3:  * Author : Thomas Bernard
                      4:  * Copyright (c) 2005-2011 Thomas Bernard
                      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];
                     23:        if(argc < 3) {
                     24:                fprintf(stderr, "Usage:\t%s url file\n", argv[0]);
                     25:                fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]);
                     26:                return 1;
                     27:        }
                     28:        /*data = miniwget(argv[1], &size);*/
                     29:        data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr));
                     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>