Coding style change
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ void stdin_read_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
ssize_t len = read(fd->fd, buf, sizeof buf);
|
||||
printf("Read %d bytes\n", len);
|
||||
iomux_unregister_fd(mux, fd);
|
||||
if(len > 0) {
|
||||
if (len > 0) {
|
||||
s_fd.what = MUX_EV_READ;
|
||||
iomux_register_fd(mux, &s_fd);
|
||||
}
|
||||
|
||||
+4
-4
@@ -10,7 +10,7 @@ void stdin_read_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
{
|
||||
char buf[4096];
|
||||
ssize_t len = read(fd->fd, buf, sizeof buf);
|
||||
if(len <= 0) {
|
||||
if (len <= 0) {
|
||||
perror("read");
|
||||
fprintf(stderr,"Unregister stdin fd %d\n", fd->fd);
|
||||
iomux_unregister_fd(mux, fd);
|
||||
@@ -25,7 +25,7 @@ void pipe_read_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
{
|
||||
char buf[4095];
|
||||
ssize_t len = read(fd->fd, buf, sizeof buf);
|
||||
if(len <= 0) {
|
||||
if (len <= 0) {
|
||||
perror("pipe read");
|
||||
printf("Unregister pipe fd %d [stdout]\n", fd->fd);
|
||||
fprintf(stderr,"Unregister pipe fd %d[stderr]\n", fd->fd);
|
||||
@@ -72,10 +72,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
rc = iomux_register_fd(mux1, &fd1);
|
||||
if(rc != 0)
|
||||
if (rc != 0)
|
||||
printf("Cannot register fd1: %s\n", strerror(rc));
|
||||
rc = iomux_register_fd(mux2, &fd2);
|
||||
if(rc != 0)
|
||||
if (rc != 0)
|
||||
printf("Cannot register fdw: %s\n", strerror(rc));
|
||||
pthread_create(&tid,NULL,writer,mux2);
|
||||
iomux_run(mux1);
|
||||
|
||||
+11
-11
@@ -26,15 +26,15 @@ void in_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
size_t left = BUFLEN - copy_ctx->w_idx;
|
||||
ssize_t rc;
|
||||
left /= 2;
|
||||
if(left == 0)
|
||||
if (left == 0)
|
||||
left++;
|
||||
|
||||
|
||||
rc = read(fd->fd, ©_ctx->buffer[copy_ctx->w_idx], left);
|
||||
if(rc <= 0) {
|
||||
if(rc == -1 && errno == EAGAIN) {
|
||||
if (rc <= 0) {
|
||||
if (rc == -1 && errno == EAGAIN) {
|
||||
return;
|
||||
} else if(rc == -1) {
|
||||
} else if (rc == -1) {
|
||||
perror("read");
|
||||
}
|
||||
iomux_unregister_fd(mux, fd);
|
||||
@@ -43,13 +43,13 @@ void in_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
|
||||
copy_ctx->w_idx += rc;
|
||||
|
||||
if(!copy_ctx->out_running) {
|
||||
if (!copy_ctx->out_running) {
|
||||
copy_ctx->out.what = MUX_EV_WRITE;
|
||||
iomux_register_fd(mux, ©_ctx->out);
|
||||
copy_ctx->out_running = 1;
|
||||
}
|
||||
|
||||
if(copy_ctx->w_idx == BUFLEN) {
|
||||
if (copy_ctx->w_idx == BUFLEN) {
|
||||
iomux_unregister_fd(mux, fd);
|
||||
}
|
||||
}
|
||||
@@ -61,8 +61,8 @@ void out_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
size_t len = copy_ctx->w_idx - copy_ctx->r_idx;
|
||||
|
||||
rc = write(1, ©_ctx->buffer[copy_ctx->r_idx], len);
|
||||
if(rc <= 0) {
|
||||
if(rc == -1 && errno == EAGAIN) {
|
||||
if (rc <= 0) {
|
||||
if (rc == -1 && errno == EAGAIN) {
|
||||
return;
|
||||
} else {
|
||||
perror("write");
|
||||
@@ -72,10 +72,10 @@ void out_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
copy_ctx->out_running = 0;
|
||||
} else {
|
||||
copy_ctx->r_idx += rc;
|
||||
if(copy_ctx->r_idx == copy_ctx->w_idx) {
|
||||
if (copy_ctx->r_idx == copy_ctx->w_idx) {
|
||||
iomux_unregister_fd(mux, fd);
|
||||
copy_ctx->out_running = 0;
|
||||
if(copy_ctx->w_idx == BUFLEN) {
|
||||
if (copy_ctx->w_idx == BUFLEN) {
|
||||
copy_ctx->w_idx = 0;
|
||||
copy_ctx->r_idx = 0;
|
||||
iomux_register_fd(mux, ©_ctx->in);
|
||||
@@ -88,7 +88,7 @@ void out_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
int set_nonblocking(int fd)
|
||||
{
|
||||
int flags = fcntl(fd,F_GETFL,NULL);
|
||||
if(flags < 0 ) {
|
||||
if (flags < 0 ) {
|
||||
return flags;
|
||||
}
|
||||
return fcntl(fd,F_SETFL,flags | O_NONBLOCK);
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ int main(int argc, char *argv)
|
||||
{
|
||||
size_t i;
|
||||
SAlloc *s = uc_new_salloc(36 * 100);
|
||||
for(i = 0; i < 100; i++) {
|
||||
for (i = 0; i < 100; i++) {
|
||||
void *p = uc_s_alloc(s, 36);
|
||||
memset(p,7,36);
|
||||
}
|
||||
@@ -16,7 +16,7 @@ int main(int argc, char *argv)
|
||||
uc_free_salloc(s);
|
||||
|
||||
s = uc_new_salloc(85 * 100);
|
||||
for(i = 0; i < 100 * 3; i++) {
|
||||
for (i = 0; i < 100 * 3; i++) {
|
||||
void *p = uc_s_alloc(s, 85);
|
||||
memset(p,7,85);
|
||||
}
|
||||
|
||||
+8
-8
@@ -7,7 +7,7 @@ START_TEST (test_bitvec_1)
|
||||
struct bitvec v = BITVEC_STATIC_INIT(s);
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < sizeof s * 8; i++)
|
||||
for (i = 0; i < sizeof s * 8; i++)
|
||||
fail_if(get_bit(&v, i), "bit %zu is not 0", i);
|
||||
END_TEST
|
||||
|
||||
@@ -16,10 +16,10 @@ START_TEST (test_bitvec_2)
|
||||
struct bitvec v = BITVEC_STATIC_INIT(s);
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < sizeof s * 8; i++)
|
||||
for (i = 0; i < sizeof s * 8; i++)
|
||||
set_bit(&v, i);
|
||||
|
||||
for(i = 0; i < sizeof s * 8; i++)
|
||||
for (i = 0; i < sizeof s * 8; i++)
|
||||
fail_if(get_bit(&v, i) != 1 , "bit %zu is not 1", i);
|
||||
END_TEST
|
||||
|
||||
@@ -28,13 +28,13 @@ START_TEST (test_bitvec_clearbit)
|
||||
struct bitvec v = BITVEC_STATIC_INIT(s);
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < sizeof(unsigned long) * 8; i++)
|
||||
for (i = 0; i < sizeof(unsigned long) * 8; i++)
|
||||
fail_if(get_bit(&v, i) != 1 , "bit %zu is not 1", i);
|
||||
|
||||
for(i = 0; i < sizeof(unsigned long) * 8; i++)
|
||||
for (i = 0; i < sizeof(unsigned long) * 8; i++)
|
||||
clear_bit(&v, i);
|
||||
|
||||
for(i = 0; i < sizeof(unsigned long) * 8; i++)
|
||||
for (i = 0; i < sizeof(unsigned long) * 8; i++)
|
||||
fail_if(get_bit(&v, i) != 0 , "bit %zu is not 0", i);
|
||||
|
||||
END_TEST
|
||||
@@ -58,12 +58,12 @@ START_TEST (test_bitvec_setall_clearall)
|
||||
|
||||
set_all(v);
|
||||
|
||||
for(i = 0; i < 511; i++)
|
||||
for (i = 0; i < 511; i++)
|
||||
fail_if(get_bit(v, i) != 1 , "bit %zu is not 1", i);
|
||||
|
||||
clear_all(v);
|
||||
|
||||
for(i = 0; i < sizeof(unsigned long) * 8; i++)
|
||||
for (i = 0; i < sizeof(unsigned long) * 8; i++)
|
||||
fail_if(get_bit(v, i) != 0 , "bit %zu is not 0", i);
|
||||
|
||||
END_TEST
|
||||
|
||||
+4
-2
@@ -263,7 +263,7 @@ START_TEST (test_logfile_full_filesystem)
|
||||
fail_if(dest == NULL, "Cannot open /dev/full");
|
||||
uc_log_add_destination(dest);
|
||||
|
||||
for(i = 0; i < 1024; i++) {
|
||||
for (i = 0; i < 1024; i++) {
|
||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
|
||||
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
|
||||
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d\n", 1);
|
||||
@@ -374,11 +374,13 @@ Suite *logging_suite(void)
|
||||
tcase_add_test(tc1, test_logfile_loglevel_surpressed_module);
|
||||
tcase_add_test(tc1, test_logfile_reopen_files);
|
||||
tcase_add_test(tc1, test_logfile_remove_dest);
|
||||
if(access("/dev/full", R_OK) == 0) {
|
||||
|
||||
if (access("/dev/full", R_OK) == 0) {
|
||||
tcase_add_test(tc1, test_logfile_full_filesystem);
|
||||
} else {
|
||||
puts("Cannot access /dev/full. Not testing test_logfile_full_filesystem");
|
||||
}
|
||||
|
||||
tcase_add_test(tc1, test_logfile_invalid_file);
|
||||
tcase_add_test(tc2, test_logfile_invalid_file_after_reopen);
|
||||
tcase_add_test(tc1, test_logfile_raw);
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ main (int argc, char *argv[])
|
||||
int number_failed = 0;
|
||||
|
||||
SRunner *sr = srunner_create (NULL);
|
||||
if(xml_output)
|
||||
if (xml_output)
|
||||
srunner_set_xml(sr, "result.xml");
|
||||
|
||||
srunner_add_suite(sr, bitvec_suite());
|
||||
@@ -39,7 +39,7 @@ main (int argc, char *argv[])
|
||||
number_failed = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
if(number_failed)
|
||||
if (number_failed)
|
||||
printf("ERROR: %d tests failed\n", number_failed);
|
||||
|
||||
return (number_failed != 0) ;
|
||||
|
||||
+10
-10
@@ -17,7 +17,7 @@ START_TEST (test_thread_queue_length)
|
||||
int i;
|
||||
|
||||
fail_if(uc_thread_queue_init(&queue, 100) != 0);
|
||||
for(i = 0; i < 51; i++) {
|
||||
for (i = 0; i < 51; i++) {
|
||||
struct thr_msg *msg = malloc(sizeof *msg);
|
||||
fail_if(msg == NULL);
|
||||
msg->msg.msgtype = 1;
|
||||
@@ -34,7 +34,7 @@ START_TEST (test_thread_queue_one_thread)
|
||||
int i;
|
||||
|
||||
fail_if(uc_thread_queue_init(&queue, 100) != 0);
|
||||
for(i = 0; i < 51; i++) {
|
||||
for (i = 0; i < 51; i++) {
|
||||
struct thr_msg *msg = malloc(sizeof *msg);
|
||||
fail_if(msg == NULL);
|
||||
msg->msg.msgtype = 0;
|
||||
@@ -42,7 +42,7 @@ START_TEST (test_thread_queue_one_thread)
|
||||
fail_if(uc_thread_queue_add(&queue, &msg->msg) != 0);
|
||||
}
|
||||
|
||||
for(i = 0; i < 51; i++) {
|
||||
for (i = 0; i < 51; i++) {
|
||||
struct uc_threadmsg *msg;
|
||||
struct thr_msg *my_msg;
|
||||
fail_if(uc_thread_queue_get(&queue, NULL, &msg) != 0);
|
||||
@@ -70,7 +70,7 @@ START_TEST (test_thread_queue_walk)
|
||||
int i;
|
||||
|
||||
fail_if(uc_thread_queue_init(&queue, 100) != 0);
|
||||
for(i = 0; i < 51; i++) {
|
||||
for (i = 0; i < 51; i++) {
|
||||
struct thr_msg *msg = malloc(sizeof *msg);
|
||||
fail_if(msg == NULL);
|
||||
msg->a = i;
|
||||
@@ -91,7 +91,7 @@ static void *test_thread_queue_reader_writer_func(void *arg)
|
||||
struct uc_threadqueue *queue = arg;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||
for (i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||
struct uc_threadmsg *msg;
|
||||
struct thr_msg *my_msg;
|
||||
fail_if(uc_thread_queue_get(queue, NULL, &msg) != 0);
|
||||
@@ -113,7 +113,7 @@ START_TEST (test_thread_queue_reader_writer)
|
||||
fail_if(pthread_create(&tid, NULL, test_thread_queue_reader_writer_func, &queue) != 0);
|
||||
sched_yield();
|
||||
|
||||
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||
for (i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||
struct thr_msg *msg = malloc(sizeof *msg);
|
||||
fail_if(msg == NULL);
|
||||
msg->a = i;
|
||||
@@ -137,7 +137,7 @@ START_TEST (test_thread_queue_reader_writer_len_1)
|
||||
fail_if(pthread_create(&tid, NULL, test_thread_queue_reader_writer_func, &queue) != 0);
|
||||
sched_yield();
|
||||
|
||||
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||
for (i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||
struct thr_msg *msg = malloc(sizeof *msg);
|
||||
fail_if(msg == NULL);
|
||||
msg->a = i;
|
||||
@@ -162,7 +162,7 @@ void *test_thread_queue_multiple_writers_func(void *arg)
|
||||
struct uc_threadqueue *queue = arg;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||
for (i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||
struct thr_msg *msg = malloc(sizeof *msg);
|
||||
fail_if(msg == NULL);
|
||||
msg->a = i;
|
||||
@@ -185,13 +185,13 @@ START_TEST (test_thread_queue_multiple_writers)
|
||||
fail_if(pthread_create(&tid2, NULL, test_thread_queue_multiple_writers_func, &queue) != 0);
|
||||
fail_if(pthread_create(&tid3, NULL, test_thread_queue_multiple_writers_func, &queue) != 0);
|
||||
|
||||
for(i = 0; i < READER_WRITER_NUM_MSG * 3; i++) {
|
||||
for (i = 0; i < READER_WRITER_NUM_MSG * 3; i++) {
|
||||
struct uc_threadmsg *msg;
|
||||
struct thr_msg *my_msg;
|
||||
fail_if(uc_thread_queue_get(&queue, NULL, &msg) != 0);
|
||||
my_msg = (struct thr_msg *)msg;
|
||||
|
||||
if(my_msg->a == READER_WRITER_NUM_MSG - 1)
|
||||
if (my_msg->a == READER_WRITER_NUM_MSG - 1)
|
||||
count_max++;
|
||||
|
||||
free(my_msg);
|
||||
|
||||
+7
-7
@@ -15,10 +15,10 @@ void *reader(void *arg)
|
||||
{
|
||||
int i;
|
||||
int last;
|
||||
for(i = 0; i < CNT/2; i++) {
|
||||
for (i = 0; i < CNT/2; i++) {
|
||||
struct uc_threadmsg *msg;
|
||||
struct my_msg *my;
|
||||
if(uc_thread_queue_get(&queue, NULL, &msg) != 0) {
|
||||
if (uc_thread_queue_get(&queue, NULL, &msg) != 0) {
|
||||
printf("uc_threadqueue_get failed\n");
|
||||
return NULL;
|
||||
}
|
||||
@@ -39,25 +39,25 @@ int main(int argc, char *argv[])
|
||||
|
||||
uc_thread_queue_init(&queue, 100);
|
||||
|
||||
if(pthread_create(&tid1, NULL, reader, NULL) != 0) {
|
||||
if (pthread_create(&tid1, NULL, reader, NULL) != 0) {
|
||||
perror("pthread_create");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(pthread_create(&tid2, NULL, reader, NULL) != 0) {
|
||||
if (pthread_create(&tid2, NULL, reader, NULL) != 0) {
|
||||
perror("pthread_create");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(i = 0; i < CNT; i++) {
|
||||
for (i = 0; i < CNT; i++) {
|
||||
struct my_msg *msg = malloc(sizeof *msg);
|
||||
if(msg == NULL) {
|
||||
if (msg == NULL) {
|
||||
perror("malloc");
|
||||
return 1;
|
||||
}
|
||||
msg->uc_msg.msgtype = 11;
|
||||
msg->counter = i;
|
||||
if(uc_thread_queue_add(&queue, &msg->uc_msg) != 0) {
|
||||
if (uc_thread_queue_add(&queue, &msg->uc_msg) != 0) {
|
||||
printf("uc_threadqueue_add failed\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ struct descriptors entries;
|
||||
|
||||
int descriptor_cmp(struct descriptor *a, struct descriptor *b)
|
||||
{
|
||||
if(a->fd < b->fd)
|
||||
if (a->fd < b->fd)
|
||||
return -1;
|
||||
if(a->fd > b->fd)
|
||||
if (a->fd > b->fd)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
@@ -41,7 +41,7 @@ void find(int fd)
|
||||
des.fd = fd;
|
||||
found = SPLAY_FIND(descriptors, &entries, &des);
|
||||
|
||||
if(found == NULL)
|
||||
if (found == NULL)
|
||||
printf("Not found fd %d\n", fd);
|
||||
else
|
||||
printf("Found fd %d (%d)\n", found->fd, fd);
|
||||
@@ -80,7 +80,7 @@ void fd_min_max(void)
|
||||
min_des = SPLAY_MIN(descriptors, &entries);
|
||||
max_des = SPLAY_MAX(descriptors, &entries);
|
||||
|
||||
if(min_des && max_des)
|
||||
if (min_des && max_des)
|
||||
printf("min fd = %d max fd = %d\n", min_des->fd, max_des->fd);
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int a,N;
|
||||
if(argc < 2) {
|
||||
if (argc < 2) {
|
||||
printf("Usage %s interger1\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user