+#define _POSIX_C_SOURCE 200809L
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* mmap the file */
fd = open(path, O_RDONLY);
if (fd == -1) {
+ pkg->error = errno;
fprintf(stderr, "%s can't open %s: %s\n", __FUNCTION__, path,strerror(errno));
return 0;
}
if (fstat(fd, &sbuf) == -1) {
+ pkg->error = errno;
fprintf(stderr, "%s can't fstat %s: %s\n", __FUNCTION__, path,strerror(errno));
return 0;
}
/* not a regular file? */
if (!S_ISREG(sbuf.st_mode)) {
+ char *ftype;
+ switch (sbuf.st_mode & S_IFMT) {
+ case S_IFSOCK: ftype = "socket"; break;
+ case S_IFLNK : ftype = "symlink"; break;
+ case S_IFBLK : ftype = "block device"; break;
+ case S_IFDIR : ftype = "directory"; break;
+ case S_IFCHR : ftype = "character device"; break;
+ case S_IFIFO : ftype = "fifo"; break;
+ default: ftype = "unknown file type"; break;
+ }
/* TODO this is ok, just stored differently */
- fprintf(stderr, "%s non-regular files unsupported %s\n", __FUNCTION__, path);
+ fprintf(stderr, "%s can't import %s file: %s\n", __FUNCTION__, ftype, path);
+ pkg->error = EINVAL;
return 0;
}
content = mmap(0, sbuf.st_size, PROT_READ,MAP_PRIVATE, fd, 0);
if (!content) {
+ pkg->error = errno;
fprintf(stderr, "%s can't mmap %s: %s\n", __FUNCTION__, path,strerror(errno));
return 0;
}