mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-22 10:30:29 +00:00
Make minor improvements
This commit is contained in:
parent
221817e537
commit
4864565198
41 changed files with 394 additions and 367 deletions
|
@ -31,12 +31,9 @@
|
|||
|
||||
void lookup(const char *name) {
|
||||
int rc;
|
||||
struct addrinfo hints = (struct addrinfo){.ai_family = AF_INET,
|
||||
.ai_socktype = SOCK_STREAM,
|
||||
.ai_protocol = IPPROTO_TCP,
|
||||
.ai_flags = AI_NUMERICSERV};
|
||||
struct addrinfo *addrs = NULL;
|
||||
switch ((rc = getaddrinfo(name, "80", &hints, &addrs))) {
|
||||
struct addrinfo *ai = NULL;
|
||||
struct addrinfo hint = {AI_NUMERICSERV, AF_INET, SOCK_STREAM, IPPROTO_TCP};
|
||||
switch ((rc = getaddrinfo(name, "80", &hint, &ai))) {
|
||||
case EAI_SUCCESS:
|
||||
break;
|
||||
case EAI_SYSTEM:
|
||||
|
@ -47,8 +44,8 @@ void lookup(const char *name) {
|
|||
gai_strerror(rc));
|
||||
exit(1);
|
||||
}
|
||||
if (addrs) {
|
||||
for (struct addrinfo *addr = addrs; addr; addr = addr->ai_next) {
|
||||
if (ai) {
|
||||
for (struct addrinfo *addr = ai; addr; addr = addr->ai_next) {
|
||||
const unsigned char *ip =
|
||||
addr->ai_family == AF_INET
|
||||
? (const unsigned char *)&((struct sockaddr_in *)addr->ai_addr)
|
||||
|
@ -70,7 +67,7 @@ void lookup(const char *name) {
|
|||
ip[3]);
|
||||
printf("%-12s = %s\n", "ai_canonname", addr->ai_canonname);
|
||||
}
|
||||
freeaddrinfo(addrs);
|
||||
freeaddrinfo(ai);
|
||||
} else {
|
||||
fprintf(stderr, "%s: %s\n", name, "no results");
|
||||
}
|
||||
|
|
|
@ -202,7 +202,6 @@ static const struct ContentTypeExtension {
|
|||
{"z", "application/zlib"}, //
|
||||
{"zip", "application/zip"}, //
|
||||
{"zst", "application/zstd"}, //
|
||||
{"zst", "application/zstd"}, //
|
||||
};
|
||||
|
||||
static const char kRegCode[][8] = {
|
||||
|
@ -1941,7 +1940,7 @@ td { padding-right: 3em; }\r\n\
|
|||
}
|
||||
|
||||
static const char *MergeNames(const char *a, const char *b) {
|
||||
return FreeLater(xasprintf("%s.ru_utime", a));
|
||||
return FreeLater(xasprintf("%s.%s", a, b));
|
||||
}
|
||||
|
||||
static void AppendLong1(const char *a, long x) {
|
||||
|
@ -2212,7 +2211,7 @@ static int LuaRoute(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int LuaRespond(lua_State *L, char *respond(unsigned, const char *)) {
|
||||
static int LuaRespond(lua_State *L, char *R(unsigned, const char *)) {
|
||||
char *p;
|
||||
int code;
|
||||
size_t reasonlen;
|
||||
|
@ -2223,11 +2222,11 @@ static int LuaRespond(lua_State *L, char *respond(unsigned, const char *)) {
|
|||
unreachable;
|
||||
}
|
||||
if (lua_isnoneornil(L, 2)) {
|
||||
luaheaderp = respond(code, GetHttpReason(code));
|
||||
luaheaderp = R(code, GetHttpReason(code));
|
||||
} else {
|
||||
reason = lua_tolstring(L, 2, &reasonlen);
|
||||
if (reasonlen < 128 && (p = EncodeHttpHeaderValue(reason, reasonlen, 0))) {
|
||||
luaheaderp = respond(code, p);
|
||||
luaheaderp = R(code, p);
|
||||
free(p);
|
||||
} else {
|
||||
luaL_argerror(L, 2, "invalid");
|
||||
|
@ -2802,7 +2801,7 @@ static int LuaSetHeader(lua_State *L) {
|
|||
}
|
||||
switch (h) {
|
||||
case kHttpConnection:
|
||||
if (evallen != 5 || memcasecmp(eval, "close", 5)) {
|
||||
if (SlicesEqualCase(eval, evallen, "close", 5)) {
|
||||
luaL_argerror(L, 2, "unsupported");
|
||||
unreachable;
|
||||
}
|
||||
|
@ -3017,11 +3016,11 @@ static int LuaHasControlCodes(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int LuaIsValid(lua_State *L, bool IsValid(const char *, size_t)) {
|
||||
static int LuaIsValid(lua_State *L, bool V(const char *, size_t)) {
|
||||
size_t size;
|
||||
const char *data;
|
||||
data = luaL_checklstring(L, 1, &size);
|
||||
lua_pushboolean(L, IsValid(data, size));
|
||||
lua_pushboolean(L, V(data, size));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue