News for hackers. Stuff that matters.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by ronsor on Thursday December 03, 2015 @10:38PM (#10674439)
I'll upload the source code tomorrow...

Edit: Its also running on my 4mb flash openwrt router, and has NO dependencies

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by sdegutis on Thursday December 03, 2015 @10:49PM (#10674473)
Excited to see the code. C isn't known for being great for writing high level applications like this, so I'm really curious what the source looks like. Especially since it has no dependencies!
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by jheriko on Thursday December 03, 2015 @11:30PM (#10674620)
you may be surprised how easy it is to write a http server that replies with html in C... its all just text going over sockets after all.

i did it myself a lot a long time ago by teaching myself, but you are right that using some full featured server and some high level language targetting web development has much more convenience, especially if you care about rich features and security.

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by emcrazyone on Friday December 04, 2015 @01:21AM (#10674983)
It is relatively easy. I've done it myself many moons ago.

I've followed Steve off and on over the years. He seems to prefer C++ as a web-app language so much so that he blogs about it and other things. I like his stuff. I discovered Steve through Joel On Software some years ago. If memory serves me, I think at one time he was publishing a Web CMS type engine written in C++ but I could have him confused with someone else (been awhile)

Here is his site: http://stevehanov.ca/blog/index.php?id=95

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by teaearlgraycold on Friday December 04, 2015 @12:06AM (#10674771)
They claim it's got no dependencies though - so somehow they've got their own sockets implementation crammed in there.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by jheriko on Friday December 04, 2015 @12:23AM (#10674835)
i doubt it tbh, i bet he means no /3rd party/ dependencies other than the ones that came with the development environment.

the C standard library and the usual set of headers and os functions that you get in most C environments is not what people tend to mean by dependencies....

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by fit2rule on Friday December 04, 2015 @08:45AM (#10676242)
POSIX?

Its quite possible to have a C-based sockets-/signals- handler in a single source file, say .. 48k lines of code or so. I've seen many robust system daemons with just such an implementation.

3rd party dependencies are definitely an issue that very few languages have managed to promote, since languages either want to promote (or demote) such circumstances as mass-package (i.e. mass usage of the language) in a broad commercial/industrial/social context.

But its not naive to write such things as a Wiki and a Blog in C. Just .. dangerous. I imagine there are, however, some good 3rd-party C libraries available to do less-dangerous implementations, however...

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by jheriko on Friday December 04, 2015 @11:10AM (#10677103)
it never seems to actually be posix, but yeah that kind of stuff.

it is interesting stuff.

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by ronsor on Friday December 04, 2015 @12:16PM (#10677560)
It's served from another httpd server, no sockets library was used. Just simple file I/O, string.h, and its own implementation of hashing
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by userbinator on Thursday December 03, 2015 @10:59PM (#10674519)
I wonder if it has no buffer overflows either. ;-)

C is definitely not known for easy and safe string processing, so I'm quite curious to see how it accomplishes that.

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by jhallenworld on Thursday December 03, 2015 @11:23PM (#10674598)
It's not too hard if you are willing to use fixed length buffers and safe calls like: strlcpy, strlcat, and snprintf.

Also not terribly hard to write a small arbitrary length string library as part of the project.

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by vardump on Friday December 04, 2015 @03:49AM (#10675293)
Not all implementations of snprintf behave the same way. Many are subtly broken.

Some don't nul terminate the string if it's longer than the destination buffer.

Also the return value can be -1 (correct behavior on failure, but it's often left unchecked) or more than destination buffer size! Fun times if you accumulate total written without range checking snprintf return value...

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by vardump on Friday December 04, 2015 @01:09PM (#10677939)
To add, notably this:

_snprintf, _snprintf_l, _snwprintf, _snwprintf_l -> https://msdn.microsoft.com/en-us/library/2ts7cx93.aspx

  "If len > count, count characters are stored in buffer, no null-terminator is appended, and a negative value is returned."
Uh, what?

I guess that's why it is _snprintf and not snprintf, huh?

They do provide secure [1] versions too, but you need to be careful which one you pick. Those secure versions terminate execution in some cases if buffer length is exceeded.

[1]: https://msdn.microsoft.com/en-us/library/f30dzcf6.aspx - better remember that _TRUNCATE flag.

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by jheriko on Thursday December 03, 2015 @11:45PM (#10674680)
its still not as easy as in languages with modern libraries.

a = "foo" + "bar"; is very useful so is b = a.split( "," ); or a = b.trim(); etc. C strings are rarely so convenient.

its more obvious with the more high level things you want. to do something like b = a.split( "," ); on a string that is not know until runtime you need dynamic allocations and you could use strtok to fill that memory with the results, but its an error-prone ballache by comparison.

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by kbenson on Friday December 04, 2015 @01:58AM (#10675074)
I still maintain that + is a terrible operator for concatenating strings, and results in quite a few types of bugs that are pervasive in many languages (usually from trying to automatically coerce non-matching operands).
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by mtdewcmu on Friday December 04, 2015 @02:30AM (#10675126)
I think I agree. PHP uses ., and I can't recall ever having a problem with that. However, I've been bitten by +.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by jheriko on Friday December 04, 2015 @11:09AM (#10677098)
i can accept that argument. basic used & and php uses . as mentioned by another comment. :)
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by krapp on Friday December 04, 2015 @12:57AM (#10674926)
Someone should totally build a dynamically typed language around C which is specifically meant for dealing with HTTP and serving HTML.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by frik on Friday December 04, 2015 @01:07AM (#10674952)
It's called PHP
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by mtdewcmu on Friday December 04, 2015 @01:42AM (#10675033)
I was going to say that.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by speps on Friday December 04, 2015 @04:24AM (#10675378)
Go works pretty well for that :)
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by ronsor on Friday December 04, 2015 @11:54AM (#10677405)
All data is checked to see whether it is larger than 3768 (the buffers are 4096)
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by fit2rule on Friday December 04, 2015 @08:41AM (#10676222)
Curiously enough, after 10 hours your work is still running, having survived a slashdot'ing. Well done! I applaud your bravado! Bravo!
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by jheriko on Thursday December 03, 2015 @11:32PM (#10674630)
> NO dependencies

not even sockets? because /that/ would be impressive.

Re:Show HN: Demo of Wiki and Forum coded in C under 80k by emcrazyone on Friday December 04, 2015 @01:18AM (#10674977)
I think what the OP meant was no 3rd party library dependencies such as a CGI library and that he's still dependent on OS system calls such as file I/O and sockets.
Re:Show HN: Demo of Wiki and Forum coded in C under 80k by z92 on Friday December 04, 2015 @03:00AM (#10675197)
You don't need sockets. I used xinetd instead. Got the idea from someone else on the net. Not uncommon. And performance isn't bad either just 10% less than what it could have been, even if every request spawns a process.

Unix processes creation is lightweight and fast, unlike Windows.