Below is a simple implementation of getinfo
Note that you do not need an extra array and most of the work is done by
snprintf.
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
int getinfo(char *path, char *buf, int bufsize) {
int i;
struct stat statbuf;
int needed;
if (stat(path, &statbuf) == -1)
return -1;
needed = snprintf(buf,bufsize,"%s %lld %lld\n",path,
(long long)statbuf.st_mtime, (long long)statbuf.st_size);
if (needed >= bufsize)
return -1;
for (i=0;i<strlen(path);i++)
if (buf[i] == ' ')
buf[i] = '%';
return 0;
}