13 #define SUFFICIENT_SPRINTF_SPACE 256 17 int buffered, written, status;
19 va_start(args, format);
24 while(written<buffered) {
25 status = write(fd, &buffer[written], buffered-written);
26 assert(status>=0 &&
"Write failed");
29 assert(written==buffered &&
"Wrote more data than given");
38 ssize_t bytes_read, status;
40 assert(fd>1 &&
"Invalid file descriptor");
41 assert(0==fstat(fd, &s) &&
"Couldn't determine file size");
43 assert(len>0 &&
"File is empty");
44 p = (
char *)malloc(len+1);
46 while( bytes_read<len ) {
47 status =
read(fd, &p[bytes_read], len-bytes_read);
48 assert(status>=0 &&
"read() failed");
59 assert(n>=0 &&
"Invalid section number");
64 while(i<n && (*s)!=(
char)0) {
66 if( s[0]==
'%' && s[1]==
'%' && s[2]==
'\n' ) {
79 assert(s!=
NULL &&
"Invalid input string");
83 while( s[k]!=(
char)0 && s[k+1]!=(
char)0 && s[k+2]!=(
char)0
84 && !(s[k]==
'\n' && s[k+1]==
'%' && s[k+2]==
'%') ) {
98 #define generate_parse_TYPE_array(TYPE, STRTOTYPE) \ 99 int parse_##TYPE##_array(char *s, TYPE *arr, int n) { \ 100 char *line, *endptr; \ 104 assert(s!=NULL && "Invalid input string"); \ 106 line = strtok(s,"\n"); \ 107 while( line!=NULL && i<n ) { \ 110 v = (TYPE)(STRTOTYPE(line, &endptr)); \ 111 if( (*endptr)!=(char)0 ) { \ 112 fprintf(stderr, "Invalid input: line %d of section\n", i); \ 121 line[strlen(line)] = '\n'; \ 122 line = strtok(NULL,"\n"); \ 125 line[strlen(line)] = '\n'; \ 131 #define strtol_10(a,b) strtol(a,b,10) 147 assert(fd>1 &&
"Invalid file descriptor");
153 status = write(fd, &arr[written], n-written);
154 assert(status>=0 &&
"Write failed");
159 status = write(fd,
"\n", 1);
160 assert(status>=0 &&
"Write failed");
167 #define generate_write_TYPE_array(TYPE, FORMAT) \ 168 int write_##TYPE##_array(int fd, TYPE *arr, int n) { \ 170 assert(fd>1 && "Invalid file descriptor"); \ 171 for( i=0; i<n; i++ ) { \ 172 fd_printf(fd, "%" FORMAT "\n", arr[i]); \ 190 assert(fd>1 &&
"Invalid file descriptor");
#define generate_parse_TYPE_array(TYPE, STRTOTYPE)
#define SUFFICIENT_SPRINTF_SPACE
#define generate_write_TYPE_array(TYPE, FORMAT)
int parse_string(char *s, char *arr, int n)
static const uint32_t k[]
int write_string(int fd, char *arr, int n)
int write_section_header(int fd)
char * find_section_start(char *s, int n)
static int fd_printf(int fd, const char *format,...)
short int read(short int *data)