It's more helpful to see "...bar/baz.json" instead of "/long/path/to".
{
if(error)
{
+ size_t length;
+
error->text[0] = '\0';
error->line = -1;
error->column = -1;
error->position = 0;
- strncpy(error->source, source, JSON_ERROR_SOURCE_LENGTH);
- error->source[JSON_ERROR_SOURCE_LENGTH - 1] = '\0';
+ length = strlen(source);
+ if(length < JSON_ERROR_SOURCE_LENGTH)
+ strcpy(error->source, source);
+ else {
+ size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
+ strcpy(error->source, "...");
+ strcpy(error->source + 3, source + extra);
+ }
}
}