tabs->spaces
This commit is contained in:
+18
-18
@@ -1,9 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "ucore/read_file.h"
|
||||
|
||||
#define CHUNK_SZ 1024
|
||||
@@ -11,34 +11,34 @@
|
||||
char *
|
||||
uc_read_file(const char *f, size_t *length, size_t max)
|
||||
{
|
||||
int fd;
|
||||
char *s = NULL;
|
||||
char *p;
|
||||
struct stat statb;
|
||||
int fd;
|
||||
char *s = NULL;
|
||||
char *p;
|
||||
struct stat statb;
|
||||
size_t alloc_sz;
|
||||
|
||||
*length = 0;
|
||||
|
||||
if ((fd = open(f, O_RDONLY)) == -1)
|
||||
return NULL;
|
||||
if ((fd = open(f, O_RDONLY)) == -1)
|
||||
return NULL;
|
||||
|
||||
if (fstat(fd, &statb) == -1) {
|
||||
if (fstat(fd, &statb) == -1) {
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
if ((statb.st_mode & S_IFMT) == S_IFREG) {
|
||||
if ((statb.st_mode & S_IFMT) == S_IFREG) {
|
||||
if ((size_t)statb.st_size > max) {
|
||||
errno = EMSGSIZE;
|
||||
goto out_close;
|
||||
}
|
||||
alloc_sz = (size_t) statb.st_size + 1; // + 1 to avoid one realloc
|
||||
s = malloc((size_t) alloc_sz + 1); //+1 for nul terminator
|
||||
} else {
|
||||
s = malloc((size_t) alloc_sz + 1); //+1 for nul terminator
|
||||
} else {
|
||||
alloc_sz = CHUNK_SZ;
|
||||
s = malloc(alloc_sz + 1); //+1 for nul terminator
|
||||
}
|
||||
|
||||
if (s == NULL) {
|
||||
if (s == NULL) {
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,6 @@ out_err_free:
|
||||
s = NULL;
|
||||
out_close:
|
||||
close(fd);
|
||||
return s;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user