Skip to content

Commit 800384f

Browse files
committed
Not everywhere has strnlen
1 parent 5f12a9e commit 800384f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,15 @@ static char *apsw_strdup(const char *source)
340340
strcpy(res, source);
341341
return res;
342342
}
343+
344+
/* It is 2016 - why do I have to write this? */
345+
static size_t apsw_strnlen(const char *s, size_t maxlen)
346+
{
347+
size_t res=0;
348+
while(*s && res<maxlen)
349+
{
350+
s++;
351+
res++;
352+
}
353+
return res;
354+
}

src/vfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ apswvfspy_xGetLastError(APSWVFS *self)
12541254
memset(PyBytes_AS_STRING(text), 0, size);
12551255

12561256
errval=self->basevfs->xGetLastError(self->basevfs, size, PyBytes_AS_STRING(text));
1257-
msglen=strnlen(PyBytes_AS_STRING(text), size);
1257+
msglen=apsw_strnlen(PyBytes_AS_STRING(text), size);
12581258
if(msglen>0)
12591259
_PyBytes_Resize(&text, msglen);
12601260
else

0 commit comments

Comments
 (0)