On Tue, Aug 01, 2017 at 10:39:35PM +0200, Marco Leise via Digitalmars-d wrote: > Am Tue, 1 Aug 2017 10:50:59 -0700 > schrieb "H. S. Teoh via Digitalmars-d" > <digitalmars-d@puremagic.com>: > > > On Tue, Aug 01, 2017 at 05:12:38PM +0000, w0rp via Digitalmars-d wrote: > > > Direct OS function calls should probably all be treated as unsafe, > > > except for rare cases where the behaviour is very well defined in > > > standards and in actual implementations to be safe. The way to get > > > safe functions for OS functionality is to write wrapper functions > > > in D which prohibit unsafe calls. > > > > +1. > > I think I got it now! > > size_t strlen_safe(in char[] str) @trusted > { > foreach (c; str) > if (!c) > return strlen(str.ptr); > return str.length; > } > > :o) [...]
LOL, that's laughably inefficient. Instead of calling strlen, you might as well have just looped with an index and returned the index. :-P foreach (i, c; str) if (!c) return i; Oh wait, so we didn't need the wrapper after all. :-P T -- It's amazing how careful choice of punctuation can leave you hanging: