<commit_before>#define NULL ((void *) 0)

#include <k/sys.h>
#include <k/log.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

const char *content = "<!doctype html>"
                    "<html><head><title>K-OS</title></head><body><center><h1 style='font-size:90pt'>K-OS</h1><center><p>Welcome.</p></html>";

#define LINE_ENDING "\r\n"

static void send_str(int fd, const char *str) {
    send(socket, str, strlen(str), 0);
}

int main() {
    int fds = socket(AF_INET, SOCK_STREAM, 0);

    struct sockaddr_in local;
    local.sin_family = AF_INET;
    local.sin_port = htons(80);
    local.sin_addr.s_addr = INADDR_ANY;

    if(bind(fds, (struct sockaddr *) &local, sizeof(struct sockaddr_in))) {
        log("ERR: bind");
        return 1;
    }

    if(listen(fds, 128)) {
        log("ERR: listen");
        return 2;
    }

    while(1) {
        int fd = accept(fds, NULL, 0);

        send_str(fd, "HTTP/1.1 200 OK" LINE_ENDING);
        send_str(fd, "Content-Type: text/html" LINE_ENDING);
        send_str(fd, "Content-Type: ");

        char content_len[64];
        itoa(strlen(content), content_len, 10);
        send_str(fd, content_len);
        send_str(fd, LINE_ENDING);

        send_str(fd, LINE_ENDING "Connection: close" LINE_ENDING LINE_ENDING);

        send_str(fd, content);

        shutdown(fd, SHUT_RDWR);
<commit_msg>Fixed a copypasta bug in libc/example/httpserver.c<commit_after>#define NULL ((void *) 0)

#include <k/sys.h>
#include <k/log.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

const char *content = "<!doctype html>"
                    "<html><head><title>K-OS</title></head><body><center><h1 style='font-size:90pt'>K-OS</h1><center><p>Welcome.</p></html>";

#define LINE_ENDING "\r\n"

static void send_str(int fd, const char *str) {
    send(socket, str, strlen(str), 0);
}

int main() {
    int fds = socket(AF_INET, SOCK_STREAM, 0);

    struct sockaddr_in local;
    local.sin_family = AF_INET;
    local.sin_port = htons(80);
    local.sin_addr.s_addr = INADDR_ANY;

    if(bind(fds, (struct sockaddr *) &local, sizeof(struct sockaddr_in))) {
        log("ERR: bind");
        return 1;
    }

    if(listen(fds, 128)) {
        log("ERR: listen");
        return 2;
    }

    while(1) {
        int fd = accept(fds, NULL, 0);

        send_str(fd, "HTTP/1.1 200 OK" LINE_ENDING);
        send_str(fd, "Content-Type: text/html" LINE_ENDING);
        send_str(fd, "Content-Length: ");

        char content_len[64];
        itoa(strlen(content), content_len, 10);
        send_str(fd, content_len);
        send_str(fd, LINE_ENDING);

        send_str(fd, LINE_ENDING "Connection: close" LINE_ENDING LINE_ENDING);

        send_str(fd, content);

        shutdown(fd, SHUT_RDWR);

{'fraction_non_alphanumeric': 0.1645127488648271, 'fraction_numerical': 0.01746419839329375, 'mean_word_length': 2.99442119944212, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6479419', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1064, 'n_words': 219}