Changeset: 49e6c8b613f4 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=49e6c8b613f4 Modified Files: common/stream/stream.c common/stream/stream.h Branch: Jul2017 Log Message:
Layout. diffs (truncated from 1358 to 300 lines): diff --git a/common/stream/stream.c b/common/stream/stream.c --- a/common/stream/stream.c +++ b/common/stream/stream.c @@ -116,15 +116,15 @@ #endif #ifndef EWOULDBLOCK -#define EWOULDBLOCK EAGAIN +#define EWOULDBLOCK EAGAIN #endif #ifndef EINTR -#define EINTR EAGAIN +#define EINTR EAGAIN #endif #ifndef INVALID_SOCKET -#define INVALID_SOCKET (-1) +#define INVALID_SOCKET (-1) #endif #ifdef NATIVE_WIN32 @@ -132,8 +132,8 @@ #define fileno(fd) _fileno(fd) #endif -#define UTF8BOM "\xEF\xBB\xBF" /* UTF-8 encoding of Unicode BOM */ -#define UTF8BOMLENGTH 3 /* length of above */ +#define UTF8BOM "\xEF\xBB\xBF" /* UTF-8 encoding of Unicode BOM */ +#define UTF8BOMLENGTH 3 /* length of above */ #ifdef _MSC_VER /* use intrinsic functions on Windows */ @@ -164,7 +164,7 @@ struct stream { char isutf8; /* known to be UTF-8 due to BOM */ short type; /* ascii/binary */ char *name; - unsigned int timeout; /* timeout in ms */ + unsigned int timeout; /* timeout in ms */ int (*timeout_func)(void); /* callback function: NULL/true -> return */ union { void *p; @@ -172,18 +172,18 @@ struct stream { SOCKET s; } stream_data; int errnr; - ssize_t (*read) (stream *s, void *buf, size_t elmsize, size_t cnt); - ssize_t (*write) (stream *s, const void *buf, size_t elmsize, size_t cnt); - void (*close) (stream *s); - void (*clrerr) (stream *s); - char *(*error) (stream *s); - void (*destroy) (stream *s); - int (*flush) (stream *s); - int (*fsync) (stream *s); - int (*fgetpos) (stream *s, lng *p); - int (*fsetpos) (stream *s, lng p); - void (*update_timeout) (stream *s); - int (*isalive) (stream *s); + ssize_t (*read)(stream *s, void *buf, size_t elmsize, size_t cnt); + ssize_t (*write)(stream *s, const void *buf, size_t elmsize, size_t cnt); + void (*close)(stream *s); + void (*clrerr)(stream *s); + char *(*error)(stream *s); + void (*destroy)(stream *s); + int (*flush)(stream *s); + int (*fsync)(stream *s); + int (*fgetpos)(stream *s, lng *p); + int (*fsetpos)(stream *s, lng p); + void (*update_timeout)(stream *s); + int (*isalive)(stream *s); }; int @@ -340,12 +340,13 @@ mnstr_read(stream *s, void *buf, size_t if (s == NULL || buf == NULL) return -1; #ifdef STREAM_DEBUG - fprintf(stderr, "read %s " SZFMT " " SZFMT "\n", s->name ? s->name : "<unnamed>", elmsize, cnt); + fprintf(stderr, "read %s " SZFMT " " SZFMT "\n", + s->name ? s->name : "<unnamed>", elmsize, cnt); #endif assert(s->access == ST_READ); if (s->errnr) return -1; - return (*s->read) (s, buf, elmsize, cnt); + return s->read(s, buf, elmsize, cnt); } /* Read one line (seperated by \n) of at most maxcnt-1 characters from @@ -359,7 +360,8 @@ mnstr_readline(stream *s, void *buf, siz if (s == NULL || buf == NULL) return -1; #ifdef STREAM_DEBUG - fprintf(stderr, "readline %s " SZFMT "\n", s->name ? s->name : "<unnamed>", maxcnt); + fprintf(stderr, "readline %s " SZFMT "\n", + s->name ? s->name : "<unnamed>", maxcnt); #endif assert(s->access == ST_READ); if (s->errnr) @@ -371,7 +373,7 @@ mnstr_readline(stream *s, void *buf, siz return 0; } for (;;) { - switch ((*s->read)(s, start, 1, 1)) { + switch (s->read(s, start, 1, 1)) { case 1: /* successfully read a character, * check whether it is the line @@ -416,12 +418,13 @@ mnstr_write(stream *s, const void *buf, if (s == NULL || buf == NULL) return -1; #ifdef STREAM_DEBUG - fprintf(stderr, "write %s " SZFMT " " SZFMT "\n", s->name ? s->name : "<unnamed>", elmsize, cnt); + fprintf(stderr, "write %s " SZFMT " " SZFMT "\n", + s->name ? s->name : "<unnamed>", elmsize, cnt); #endif assert(s->access == ST_WRITE); if (s->errnr) return -1; - return (*s->write) (s, buf, elmsize, cnt); + return s->write(s, buf, elmsize, cnt); } void @@ -431,7 +434,7 @@ mnstr_settimeout(stream *s, unsigned int s->timeout = ms; s->timeout_func = func; if (s->update_timeout) - (*s->update_timeout)(s); + s->update_timeout(s); } } @@ -442,7 +445,7 @@ mnstr_close(stream *s) #ifdef STREAM_DEBUG fprintf(stderr, "close %s\n", s->name ? s->name : "<unnamed>"); #endif - (*s->close) (s); + s->close(s); } } @@ -451,9 +454,10 @@ mnstr_destroy(stream *s) { if (s) { #ifdef STREAM_DEBUG - fprintf(stderr, "destroy %s\n", s->name ? s->name : "<unnamed>"); + fprintf(stderr, "destroy %s\n", + s->name ? s->name : "<unnamed>"); #endif - (*s->destroy) (s); + s->destroy(s); } } @@ -462,7 +466,7 @@ mnstr_error(stream *s) { if (s == NULL) return "Connection terminated"; - return (*s->error) (s); + return s->error(s); } /* flush buffer, return 0 on success, non-zero on failure */ @@ -478,7 +482,7 @@ mnstr_flush(stream *s) if (s->errnr) return -1; if (s->flush) - return (*s->flush) (s); + return s->flush(s); return 0; } @@ -489,13 +493,14 @@ mnstr_fsync(stream *s) if (s == NULL) return -1; #ifdef STREAM_DEBUG - fprintf(stderr, "fsync %s (%d)\n", s->name ? s->name : "<unnamed>", s->errnr); + fprintf(stderr, "fsync %s (%d)\n", + s->name ? s->name : "<unnamed>", s->errnr); #endif assert(s->access == ST_WRITE); if (s->errnr) return -1; if (s->fsync) - return (*s->fsync) (s); + return s->fsync(s); return 0; } @@ -510,7 +515,7 @@ mnstr_fgetpos(stream *s, lng *p) if (s->errnr) return -1; if (s->fgetpos) - return (*s->fgetpos) (s, p); + return s->fgetpos(s, p); return 0; } @@ -525,7 +530,7 @@ mnstr_fsetpos(stream *s, lng p) if (s->errnr) return -1; if (s->fsetpos) - return (*s->fsetpos) (s, p); + return s->fsetpos(s, p); return 0; } @@ -537,7 +542,7 @@ mnstr_isalive(stream *s) if (s->errnr) return -1; if (s->isalive) - return (*s->isalive)(s); + return s->isalive(s); return 1; } @@ -563,7 +568,7 @@ mnstr_clearerr(stream *s) if (s != NULL) { s->errnr = MNSTR_NO__ERROR; if (s->clrerr) - (*s->clrerr) (s); + s->clrerr(s); } } @@ -589,7 +594,8 @@ mnstr_set_byteorder(stream *s, char bige if (s == NULL) return; #ifdef STREAM_DEBUG - fprintf(stderr, "mnstr_set_byteorder %s\n", s->name ? s->name : "<unnamed>"); + fprintf(stderr, "mnstr_set_byteorder %s\n", + s->name ? s->name : "<unnamed>"); #endif assert(s->access == ST_READ); s->type = ST_BIN; @@ -666,7 +672,7 @@ error(stream *s) switch (s->errnr) { case MNSTR_OPEN_ERROR: - snprintf(buf, sizeof(buf), "error could not open file %.100s\n", + snprintf(buf, sizeof(buf), "error could not open file %.100s\n", s->name); return strdup(buf); case MNSTR_READ_ERROR: @@ -715,7 +721,8 @@ create_stream(const char *name) s->update_timeout = NULL; s->isalive = NULL; #ifdef STREAM_DEBUG - fprintf(stderr, "create_stream %s -> " PTRFMT "\n", name ? name : "<unnamed>", PTRFMTCAST s); + fprintf(stderr, "create_stream %s -> " PTRFMT "\n", + name ? name : "<unnamed>", PTRFMTCAST s); #endif return s; } @@ -736,8 +743,7 @@ file_read(stream *s, void *buf, size_t e if (elmsize && cnt && !feof(fp)) { if (ferror(fp) || - ((rc = fread(buf, elmsize, cnt, fp)) == 0 && - ferror(fp))) { + ((rc = fread(buf, elmsize, cnt, fp)) == 0 && ferror(fp))) { s->errnr = MNSTR_READ_ERROR; return -1; } @@ -881,14 +887,14 @@ file_fsetpos(stream *s, lng p) size_t getFileSize(stream *s) { - if (s->read == file_read) { - struct stat stb; - - if (fstat(fileno((FILE *) s->stream_data.p), &stb) == 0) - return (size_t) stb.st_size; - /* we shouldn't get here... */ - } - return 0; /* unknown */ + if (s->read == file_read) { + struct stat stb; + + if (fstat(fileno((FILE *) s->stream_data.p), &stb) == 0) + return (size_t) stb.st_size; + /* we shouldn't get here... */ + } + return 0; /* unknown */ } static stream * @@ -941,9 +947,7 @@ open_stream(const char *filename, const /* if a text file is opened for reading, and it starts with * the UTF-8 encoding of the Unicode Byte Order Mark, skip the * mark, and mark the stream as being a UTF-8 stream */ - if (flags[0] == 'r' && - flags[1] != 'b' && - file_fgetpos(s, &pos) == 0) { + if (flags[0] == 'r' && flags[1] != 'b' && file_fgetpos(s, &pos) == 0) { if (file_read(s, buf, 1, UTF8BOMLENGTH) == UTF8BOMLENGTH && strncmp(buf, UTF8BOM, UTF8BOMLENGTH) == 0) s->isutf8 = 1; @@ -1415,8 +1419,8 @@ open_bzwastream(const char *filename, co _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list