5 ms·
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. Especial
by sdegutis 11y ago
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!
- userbinator 11y agoI 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.
- jhallenworld 11y agoIt'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.
- jheriko 11y agoits 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.
- krapp 11y agoSomeone should totally build a dynamically typed language around C which is specifically meant for dealing with HTTP and serving HTML.
- kbenson 11y agoI 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).
- vardump 11y agoNot 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...
- vardump 11y agoTo add, notably this: _snprintf, _snprintf_l, _snwprintf, _snwprintf_l -> https://msdn.microsoft.com/en-us/library/2ts7cx93.aspx 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 https://msdn.microsoft.com/en-us/library/f30dzcf6.aspx - better remember that _TRUNCATE flag.
- ronsor 11y agoAll data is checked to see whether it is larger than 3768 (the buffers are 4096)
- jheriko 11y agoyou 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.
- teaearlgraycold 11y agoThey claim it's got no dependencies though - so somehow they've got their own sockets implementation crammed in there.
- jheriko 11y agoi 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....
- fit2rule 11y agoPOSIX? 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...
- jheriko 11y agoit never seems to actually be posix, but yeah that kind of stuff. it is interesting stuff.