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>3456long getsize(FILE *fp) {7 long cur = ftell(fp);8 if (cur == -1) return -1;9 if (fseek(fp, 0, SEEK_END)) return -1;1011 long end = ftell(fp);12 if (end == -1) return -1;13 if (fseek(fp, cur, SEEK_SET)) return -1;1415 return end-cur;16}1718int main()19{20 if (!setlocale(LC_TIME, "C")) {21 perror("setlocale()");22 return 1;23 }2425 struct sock sock;26 sock_fill(&sock, IP, PORT);27 sock_open(&sock);2829 printf("Up and running!\n");30 sock_on(&sock, handle);3132 printf("\rShutting down...\n");33 shutdown(sock.fd, SHUT_RDWR);34 close(sock.fd);35 return 0;36}3738