rafael2k / fog

Automatically exported from code.google.com/p/fog
1 stars 1 forks source link

strnlen not available on GCC 4.4.2 (MacPorts) #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
On GCC 4.4.2 on Mac OS X (Snow Leopard) installed via MacPorts, there
doesn't seem to be the strnlen function available. On MinGW it's the same
thing, so perhaps the nlen function in StringUtils.h should look something
like this (unfortunately I don't know, how the Compiler Macros a really
called, so I used some pseudo macros): 

FOG_INLINE sysuint_t nlen(const char* s, sysuint_t maxlen) 
{
#ifdef FOG_MINGW || (FOG_MAC && GCC_44)
  for(int i=0; i<maxlen; ++i) 
    if(s[i] == '\0') 
      return i;
  return -1;
#else
  return ::strnlen(s, maxlen);
#endif
}

Original issue reported on code.google.com by niels.pf...@gmail.com on 23 Nov 2009 at 12:04

GoogleCodeExporter commented 9 years ago
Accepted

Original comment by kobalicek.petr on 23 Nov 2009 at 10:55

GoogleCodeExporter commented 9 years ago
Fixed in my local copy, will be commited later

Original comment by kobalicek.petr on 27 Nov 2009 at 8:35

GoogleCodeExporter commented 9 years ago
Should be fixed, please verify

Original comment by kobalicek.petr on 12 Dec 2009 at 2:10

GoogleCodeExporter commented 9 years ago
Ok, no problem anymore

Original comment by niels.pf...@gmail.com on 12 Dec 2009 at 2:44

GoogleCodeExporter commented 9 years ago
According to 
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strlen.html the 
implementation of nlen should return maxlen rather -1 if null is not 
encountered.

Original comment by partow on 19 Dec 2010 at 7:10

GoogleCodeExporter commented 9 years ago
Since r259 nlen looks like that:
FOG_INLINE sysuint_t nlen(const char* str, sysuint_t maxlen)
{
  const char* p = str;
  if (!p) return 0;
  const char* end = str + maxlen;

  while (p < end && *p) p++;
  return (sysuint_t)(p - str);
}

That's ok, right?

Original comment by niels.pf...@gmail.com on 19 Dec 2010 at 8:13

GoogleCodeExporter commented 9 years ago
That's okay.

I think we should export these functions and make optimized non-inlined 
variants. After my commit I'd like to solve this.

I temporary reopened this to make this visible

Original comment by kobalicek.petr on 5 Feb 2011 at 1:59

GoogleCodeExporter commented 9 years ago
This is definitely fixed, because Fog contains now own strnlen functionality. 

Original comment by kobalicek.petr on 10 Oct 2011 at 7:36