int http_status (int fd, int no) { http_code *c; char buf[128]; int rc; STATUS_CHECK(no); STATUS_ASSIGN(no,c); sprintf (buf, HTTP_PROTOCOL" %d %s\r\n", c->num, c->str); rc = write (fd, buf, strlen(buf)); return (rc); }
/* TODO: don't malloc name - on the stack */ chc_status_t con_create(unsigned int fd, struct syd_obj **obj) { STATUS_INIT(status); int snprintf_result = 0; char *name = NULL; struct con_context *context = NULL; struct syd_obj *local_obj = NULL; if (NULL == obj) { STATUS_LABEL(status, CHC_CON_INVALID); goto cleanup; } context = (struct con_context *)vzalloc(sizeof(*context)); if (NULL == context) { STATUS_LABEL(status, CHC_CON_VZALLOC); goto cleanup; } context->fd = fd; name = (char *)vzalloc(sizeof(COR_MAX_NAME)); if (NULL == name) { STATUS_LABEL(status, CHC_CON_VZALLOC); goto cleanup; } /* TODO: validate null termination */ snprintf_result = snprintf(name, COR_MAX_NAME, CON_PATTERN, fd); if (0 > snprintf_result) { STATUS_LABEL(status, CHC_CON_SNPRINTF); goto cleanup; } local_obj = (struct syd_obj *)vzalloc(sizeof(*local_obj)); if (NULL == local_obj) { STATUS_LABEL(status, CHC_CON_VZALLOC); goto cleanup; } STATUS_ASSIGN(status, syd_create(name, context, &g_con_ops)); if (STATUS_IS_ERROR(status)) { goto cleanup; } STATUS_LABEL(status, CHC_SUCCESS); cleanup: if (STATUS_IS_SUCCESS(status)) { *obj = local_obj; } else { if (NULL != local_obj) { vfree(local_obj); } if (NULL != context) { vfree(context); } if (NULL != name) { vfree(name); } } return status; }