Mmm... that will fail since the last character is not null. Change:
char buffer[5] = {0};
strncpy(buffer, "This is a long string", sizeof buffer);
to: char buffer[5] = {0};
strncpy(buffer, "This is a long string", sizeof(buffer) - 1);
(I find sizeof() to be clearer than just sizeof in this case since "sizeof buffer - 1" looks awfully strange.