Skip to content

Commit

Permalink
rename FSTRM_RES_* to fstrm_res_*
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Edmonds committed Apr 16, 2014
1 parent 4a16d15 commit e687aa9
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 152 deletions.
70 changes: 35 additions & 35 deletions fstrm/control.c
Expand Up @@ -80,9 +80,9 @@ fstrm_control_get_type(struct fstrm_control *c, fstrm_control_type *type)
case FSTRM_CONTROL_START: /* FALLTHROUGH */
case FSTRM_CONTROL_STOP:
*type = c->type;
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
default:
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}
}

Expand All @@ -94,9 +94,9 @@ fstrm_control_set_type(struct fstrm_control *c, fstrm_control_type type)
case FSTRM_CONTROL_START: /* FALLTHROUGH */
case FSTRM_CONTROL_STOP:
c->type = type;
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
default:
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}
}

Expand All @@ -108,9 +108,9 @@ fstrm_control_get_field_content_type(struct fstrm_control *c,
if (c->content_type != NULL) {
*content_type = c->content_type;
*len_content_type = c->len_content_type;
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
} else {
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}
}

Expand All @@ -120,13 +120,13 @@ fstrm_control_set_field_content_type(struct fstrm_control *c,
size_t len_content_type)
{
if (len_content_type > FSTRM_MAX_CONTROL_FIELD_CONTENT_TYPE_LENGTH)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
if (c->content_type != NULL)
my_free(c->content_type);
c->len_content_type = len_content_type;
c->content_type = my_malloc(len_content_type);
memmove(c->content_type, content_type, len_content_type);
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}

fstrm_res
Expand All @@ -144,84 +144,84 @@ fstrm_control_decode(struct fstrm_control *c,
if (flags & FSTRM_CONTROL_FLAG_WITH_HEADER) {
/* Read the outer frame length. */
if (!fs_load_be32(&buf, &len, &val))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/* The outer frame length must be zero, since this is a control frame. */
if (val != 0)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/* Read the control frame length. */
if (!fs_load_be32(&buf, &len, &val))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/* Enforce maximum control frame size. */
if (val > FSTRM_MAX_CONTROL_FRAME_LENGTH)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/*
* Require that the control frame length matches the number of
* bytes remaining in 'buf'.
*/
if (val != len)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
} else {
/* Enforce maximum control frame size. */
if (len_control_frame > FSTRM_MAX_CONTROL_FRAME_LENGTH)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}

/* Read the control frame type. */
if (!fs_load_be32(&buf, &len, &val))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
switch (val) {
case FSTRM_CONTROL_ACCEPT: /* FALLTHROUGH */
case FSTRM_CONTROL_START: /* FALLTHROUGH */
case FSTRM_CONTROL_STOP:
c->type = (fstrm_control_type) val;
break;
default:
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}

/* Read any control frame fields. */
while (len > 0) {
/* Read the control frame field type. */
if (!fs_load_be32(&buf, &len, &val))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

switch (val) {
case FSTRM_CONTROL_FIELD_CONTENT_TYPE: {
/* Read the length of the "Content Type" payload. */
if (!fs_load_be32(&buf, &len, &val))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
c->len_content_type = val;

/*
* Sanity check the length field. It cannot be larger
* than 'len', the number of bytes remaining in 'buf'.
*/
if (c->len_content_type > len)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/* Enforce limit on "Content Type" payload length. */
if (c->len_content_type > FSTRM_MAX_CONTROL_FIELD_CONTENT_TYPE_LENGTH)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/* Read the "Content Type" payload. */
c->content_type = my_malloc(c->len_content_type);
if (!fs_load_bytes(c->content_type, c->len_content_type, &buf, &len))
{
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}

break;
}
default:
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}
}

return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}

fstrm_res
Expand Down Expand Up @@ -251,18 +251,18 @@ fstrm_control_encoded_size(struct fstrm_control *c,

/* Enforce limit on "Content Type" payload length. */
if (c->len_content_type > FSTRM_MAX_CONTROL_FIELD_CONTENT_TYPE_LENGTH)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/* The "Content Type" payload. */
len += c->len_content_type;
}

/* Sanity check. */
if (len > FSTRM_MAX_CONTROL_FRAME_LENGTH)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

*len_control_frame = len;
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}

fstrm_res
Expand All @@ -276,15 +276,15 @@ fstrm_control_encode(struct fstrm_control *c,

/* Calculate the size of the control frame. */
res = fstrm_control_encoded_size(c, &encoded_size, flags);
if (res != FSTRM_RES_SUCCESS)
if (res != fstrm_res_success)
return res;

/*
* The caller must have provided a large enough buffer to serialize the
* control frame.
*/
if (*len_control_frame < encoded_size)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/*
* Now actually serialize the control frame.
Expand All @@ -295,7 +295,7 @@ fstrm_control_encode(struct fstrm_control *c,
if (flags & FSTRM_CONTROL_FLAG_WITH_HEADER) {
/* Escape: 32-bit BE integer. Zero. */
if (!fs_store_be32(&buf, &len, 0))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/*
* Frame length: 32-bit BE integer.
Expand All @@ -305,27 +305,27 @@ fstrm_control_encode(struct fstrm_control *c,
* total length.
*/
if (!fs_store_be32(&buf, &len, encoded_size - 2 * sizeof(uint32_t)))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}

/* Control type: 32-bit BE integer. */
if (!fs_store_be32(&buf, &len, c->type))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

if (c->content_type != NULL) {
/* FSTRM_CONTROL_FIELD_CONTENT_TYPE: 32-bit BE integer. */
if (!fs_store_be32(&buf, &len, FSTRM_CONTROL_FIELD_CONTENT_TYPE))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/* Length of the "Content Type" payload: 32-bit BE integer. */
if (!fs_store_be32(&buf, &len, c->len_content_type))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/* The "Content Type" string itself. */
if (!fs_store_bytes(&buf, &len, c->content_type, c->len_content_type))
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}

*len_control_frame = encoded_size;
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}
26 changes: 13 additions & 13 deletions fstrm/file_writer.c
Expand Up @@ -41,7 +41,7 @@ fs_file_writer_open(void *data)

/* Nothing to do if the file descriptor is already opened. */
if (w->opened)
return FSTRM_RES_SUCCESS;
return fstrm_res_success;

/* Open the file descriptor. Request close-on-exec if available. */
int open_flags = O_CREAT | O_WRONLY | O_TRUNC;
Expand All @@ -51,7 +51,7 @@ fs_file_writer_open(void *data)
w->fd = open(w->file_path, open_flags,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (w->fd < 0)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

/*
* Request close-on-exec if available. There is nothing that can be done
Expand All @@ -70,7 +70,7 @@ fs_file_writer_open(void *data)
#endif

w->opened = true;
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}

static fstrm_res
Expand All @@ -82,7 +82,7 @@ fs_file_writer_close(void *data)
close(w->fd);
w->opened = false;

return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}

static fstrm_res
Expand All @@ -100,25 +100,25 @@ fs_file_writer_write(void *data,
written = writev(w->fd, iov, iovcnt);
} while (written == -1 && errno == EINTR);
if (written == -1)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
if (cur == 0 && written == (ssize_t) nbytes)
return FSTRM_RES_SUCCESS;
return fstrm_res_success;

while (written >= (ssize_t) iov[cur].iov_len)
written -= iov[cur++].iov_len;

if (cur == iovcnt)
return FSTRM_RES_SUCCESS;
return fstrm_res_success;

iov[cur].iov_base = (void *)
((char *) iov[cur].iov_base + written);
iov[cur].iov_len -= written;
}
} else {
return FSTRM_RES_FAILURE;
return fstrm_res_failure;
}

return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}

static fstrm_res
Expand All @@ -131,18 +131,18 @@ fs_file_writer_create(struct fstrm_io *io __attribute__((__unused__)),
(const struct fstrm_file_writer_options *) opt;

if (wopt->magic != FS_FILE_WRITER_OPTIONS_MAGIC)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

if (wopt->file_path == NULL)
return FSTRM_RES_FAILURE;
return fstrm_res_failure;

w = my_calloc(1, sizeof(*w));
w->file_path = my_strdup(wopt->file_path);

(void) fs_file_writer_open(w);

*data = w;
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}

static fstrm_res
Expand All @@ -152,7 +152,7 @@ fs_file_writer_destroy(void *data)
(void) fs_file_writer_close(w);
my_free(w->file_path);
my_free(w);
return FSTRM_RES_SUCCESS;
return fstrm_res_success;
}

struct fstrm_file_writer_options *
Expand Down

0 comments on commit e687aa9

Please sign in to comment.