📄 http.c
字号:
/* * * Copyright (c) Sigma Designs, Inc. 2005. All rights reserved. * */#include "rmlibhttp/include/rmlibhttp.h"#include <sys/param.h>#include <stdio.h>#include <time.h>#include "http.h"static unsigned char http_buffer[HTTPBUFSIZE];int http_get(char *uri, char *custom_header){ FILE *out = NULL; HTTPFile *in = NULL; int total = 0, read = 0; unsigned long int start_time = (unsigned long int) time(NULL); RMHTTPFlags flags = 0; if (uri == NULL) goto error; if (custom_header != NULL){ fetchSetCustomHeader(custom_header); flags |= RM_HTTP_CUSTOM_HEADER; } in = fetchOpen(uri, flags); if (in == NULL) goto error; out = fopen(DEFAULTPATH, "w"); if (out == NULL) goto error; do { int written; unsigned long int time_elapsed; read = fetchRead(http_buffer, HTTPBUFSIZE, in); if (read > 0){ written = fwrite(http_buffer, 1, read, out); if (written != read){ printf("\nError writing output : %d\n", ferror(out)); goto error; } } else if (read < 0) { printf("\nError reading input : %d\n", fetchLastErrCode); goto error; } total+=read; time_elapsed = (unsigned long int)time(NULL) - start_time; if (time_elapsed != 0) printf("\rRead : %d KB (%ld KB/s)", total / 1024, total / 1024 / time_elapsed); else printf("\rRead : %d KB", total / 1024); } while (read != 0); printf("\n"); fclose(out); fetchClose(in); return(0);error: if (out) fclose(out); if (in) fetchClose(in); return(-1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -