summaryrefslogtreecommitdiffhomepage
path: root/common
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@slbdata.se>2010-02-01 23:10:58 +0100
committerSamuel Lidén Borell <samuel@slbdata.se>2010-02-01 23:10:58 +0100
commit4b4651de4e00ea2165a34c23b0676ec6f2c22d79 (patch)
tree602082c24836727880abdc3259b5c1a0de089c4a /common
parentacc706985d308951b28e95fe40586ef375be835f (diff)
downloadfribid-4b4651de4e00ea2165a34c23b0676ec6f2c22d79.tar.gz
fribid-4b4651de4e00ea2165a34c23b0676ec6f2c22d79.tar.bz2
fribid-4b4651de4e00ea2165a34c23b0676ec6f2c22d79.zip
Refactoring and warning fixes in pipe.c
Diffstat (limited to 'common')
-rw-r--r--common/pipe.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/common/pipe.c b/common/pipe.c
index 81d37b8..ab3caaf 100644
--- a/common/pipe.c
+++ b/common/pipe.c
@@ -69,11 +69,7 @@ void pipe_waitData(FILE *file) {
}
int pipe_readCommand(FILE *in) {
- int command = 0;
- if (fscanf(in, " %d;", &command) != 1) {
- pipeError();
- }
- return command;
+ return pipe_readInt(in);
}
void pipe_sendCommand(FILE *out, int command) {
@@ -90,10 +86,13 @@ void pipe_flush(FILE *out) {
}
void pipe_readData(FILE *in, char **data, int *length) {
- if ((fscanf(in, "%d;", length) != 1) || (*length < 0)) {
- pipeError();
+ *length = pipe_readInt(in);
+ if (*length <= 0) {
*length = 0;
+ *data = NULL;
+ return;
}
+
*data = malloc(*length);
if ((*data == NULL) || (fread(*data, *length, 1, in) != 1)) {
pipeError();
@@ -103,12 +102,8 @@ void pipe_readData(FILE *in, char **data, int *length) {
}
char *pipe_readString(FILE *in) {
- int length = -1;
- fscanf(in, "%d;", &length);
- if (length < 0) {
- pipeError();
- return strdup("");
- }
+ int length = pipe_readInt(in);
+ if (length <= 0) return strdup("");
char *data = malloc(length +1);
if (!data) {
@@ -117,7 +112,7 @@ char *pipe_readString(FILE *in) {
}
data[length] = '\0';
- if ((length == 0) || (fread(data, length, 1, in) == 1)) {
+ if (fread(data, length, 1, in) == 1) {
return data;
} else {
pipeError();
@@ -137,7 +132,7 @@ char *pipe_readOptionalString(FILE *in) {
int pipe_readInt(FILE *in) {
int value = -1;
- if (fscanf(in, "%d;", &value) != 1) {
+ if (fscanf(in, " %d;", &value) != 1) {
pipeError();
}
return value;