Skip to content

Commit

Permalink
Not everywhere has strnlen
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerbinns committed Apr 29, 2016
1 parent 5f12a9e commit 800384f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,15 @@ static char *apsw_strdup(const char *source)
strcpy(res, source);
return res;
}

/* It is 2016 - why do I have to write this? */
static size_t apsw_strnlen(const char *s, size_t maxlen)
{
size_t res=0;
while(*s && res<maxlen)
{
s++;
res++;
}
return res;
}
2 changes: 1 addition & 1 deletion src/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ apswvfspy_xGetLastError(APSWVFS *self)
memset(PyBytes_AS_STRING(text), 0, size);

errval=self->basevfs->xGetLastError(self->basevfs, size, PyBytes_AS_STRING(text));
msglen=strnlen(PyBytes_AS_STRING(text), size);
msglen=apsw_strnlen(PyBytes_AS_STRING(text), size);
if(msglen>0)
_PyBytes_Resize(&text, msglen);
else
Expand Down

0 comments on commit 800384f

Please sign in to comment.