Add curl example (#42)

make -j8 o//examples/curl.com
    o//examples/curl.com http://justine.lol/ape.html
This commit is contained in:
Justine Tunney 2021-02-18 19:20:41 -08:00
parent 667ab245fe
commit 2c15efc249
29 changed files with 208 additions and 153 deletions

View file

@ -16,19 +16,30 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/str/str.h"
#include "net/http/uri.h"
/* TODO(jart): Unescape */
char *urislice2cstr(char *buf, size_t size, struct UriSlice slice,
const char *uristr, const char *defaultval) {
/* TODO(jart): Unescape */
if (slice.n && slice.n + 1 < size) {
memcpy(buf, uristr + slice.i, slice.n);
} else if (defaultval) {
memcpy(buf, defaultval, (slice.n = strlen(defaultval)));
} else {
slice.n = 0;
size_t n;
const char *p;
if (size) {
if (slice.n) {
p = uristr + slice.i;
n = slice.n;
} else if (defaultval) {
p = defaultval;
n = strlen(defaultval);
} else {
p = NULL;
n = 0;
}
n = MIN(n, size - 1);
memcpy(buf, p, n);
buf[n] = '\0';
}
buf[slice.n] = '\0';
return buf;
}