saving weight files as binaries, hell yeah

This commit is contained in:
Joseph Redmon
2015-02-06 18:53:53 -08:00
parent bfffadc755
commit 2f62fe33c9
9 changed files with 147 additions and 47 deletions

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <float.h>
#include <limits.h>
@ -148,6 +149,27 @@ char *fgetl(FILE *fp)
return line;
}
void read_all(int fd, char *buffer, size_t bytes)
{
size_t n = 0;
while(n < bytes){
int next = read(fd, buffer + n, bytes-n);
if(next <= 0) error("read failed");
n += next;
}
}
void write_all(int fd, char *buffer, size_t bytes)
{
size_t n = 0;
while(n < bytes){
size_t next = write(fd, buffer + n, bytes-n);
if(next <= 0) error("write failed");
n += next;
}
}
char *copy_string(char *s)
{
char *copy = malloc(strlen(s)+1);