shttp

A small http server written in C

git clone git://git.janzachar.dev/shttp.git


0#include "unistd.h"
1#include "super.h"
2#include <locale.h>
3
4
5
6long getsize(FILE *fp) {
7	long cur = ftell(fp);
8	if (cur == -1) return -1;
9	if (fseek(fp, 0, SEEK_END)) return -1;
10
11	long end = ftell(fp);
12	if (end == -1) return -1;
13	if (fseek(fp, cur, SEEK_SET)) return -1;
14
15	return end-cur; 
16}
17
18int main()
19{
20	if (!setlocale(LC_TIME, "C")) {
21		perror("setlocale()");
22		return 1;
23	}
24
25	struct sock sock;
26	sock_fill(&sock, IP, PORT);
27	sock_open(&sock);
28
29	printf("Up and running!\n");
30	sock_on(&sock, handle);
31
32	printf("\rShutting down...\n");
33	shutdown(sock.fd, SHUT_RDWR);
34	close(sock.fd);
35	return 0;
36}
37
38