tabs->spaces

This commit is contained in:
Nils O. Selåsdal
2013-11-22 20:06:05 +01:00
parent 3e05476694
commit 9090de0663
31 changed files with 1214 additions and 1214 deletions
+18 -18
View File
@@ -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;
}