add uc_read_fd function
This commit is contained in:
@@ -21,6 +21,14 @@ extern "C" {
|
||||
char *
|
||||
uc_read_file(const char *file_name, size_t *length, size_t max);
|
||||
|
||||
/** Read the content of a file descriptor as a stream.
|
||||
* @see uc_read_file
|
||||
* This is similar but reads from a file descriptor,
|
||||
* of any type as long as it supports the read() call.
|
||||
*/
|
||||
char *
|
||||
uc_read_fd(int fd, size_t *length, size_t max);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+13
-5
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user