add uc_read_fd function

This commit is contained in:
Nils O. Selåsdal
2014-03-13 23:16:50 +01:00
parent 092074bbfc
commit b93e5b6d5b
2 changed files with 21 additions and 5 deletions
+13 -5
View File
@@ -10,9 +10,8 @@
#define CHUNK_SZ 1024
char *
uc_read_file(const char *f, size_t *length, size_t max)
uc_read_fd(int fd, size_t *length, size_t max)
{
int fd;
char *s = NULL;
char *p;
struct stat statb;
@@ -20,9 +19,6 @@ uc_read_file(const char *f, size_t *length, size_t max)
*length = 0;
if ((fd = open(f, O_RDONLY)) == -1)
return NULL;
if (fstat(fd, &statb) == -1) {
goto out_close;
}
@@ -85,3 +81,15 @@ out_close:
return s;
}
char *
uc_read_file(const char *f, size_t *length, size_t max)
{
int fd;
if ((fd = open(f, O_RDONLY)) == -1) {
*length = 0;
return NULL;
}
return uc_read_fd(fd, length, max);
}