diff options
| author | dzzxzz <[email protected]> | 2012-03-17 06:43:49 +0000 |
|---|---|---|
| committer | dzzxzz <[email protected]> | 2012-03-17 06:43:49 +0000 |
| commit | 12b5e56f46e4b2b489a088c2ccfb6410c10686ea (patch) | |
| tree | 7cafe9a126189efd19cf014e46c95f87bbb33774 /src/kservice.c | |
| parent | 3b06be1cde860cdc4cdc97f901e1794329591041 (diff) | |
unify the coding style of kernel
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1998 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'src/kservice.c')
| -rw-r--r-- | src/kservice.c | 83 |
1 files changed, 54 insertions, 29 deletions
diff --git a/src/kservice.c b/src/kservice.c index 0a96de77c8..2a6733b141 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1,7 +1,7 @@ /* * File : kservice.c * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team + * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -23,6 +23,7 @@ /** * @addtogroup KernelService */ + /*@{*/ /* global errno in RT-Thread */ @@ -48,7 +49,8 @@ rt_err_t rt_get_errno(void) } tid = rt_thread_self(); - if (tid == RT_NULL) return _errno; + if (tid == RT_NULL) + return _errno; return tid->error; } @@ -66,11 +68,17 @@ void rt_set_errno(rt_err_t error) { /* it's in interrupt context */ _errno = error; + return; } tid = rt_thread_self(); - if (tid == RT_NULL) { _errno = error; return; } + if (tid == RT_NULL) + { + _errno = error; + + return; + } tid->error = error; } @@ -84,10 +92,12 @@ int *_rt_errno(void) { rt_thread_t tid; - if (rt_interrupt_get_nest() != 0) return (int *)&_errno; + if (rt_interrupt_get_nest() != 0) + return (int *)&_errno; tid = rt_thread_self(); - if (tid != RT_NULL) return (int *)&(tid->error); + if (tid != RT_NULL) + return (int *)&(tid->error); return (int *)&_errno; } @@ -100,7 +110,6 @@ int *_rt_errno(void) * @param count the copied length * * @return the address of source memory - * */ void *rt_memset(void *s, int c, rt_ubase_t count) { @@ -148,7 +157,7 @@ void *rt_memset(void *s, int c, rt_ubase_t count) *aligned_addr++ = buffer; *aligned_addr++ = buffer; *aligned_addr++ = buffer; - count -= 4*LBLOCKSIZE; + count -= 4 * LBLOCKSIZE; } while (count >= LBLOCKSIZE) @@ -183,7 +192,6 @@ void *rt_memset(void *s, int c, rt_ubase_t count) * @param count the copied length * * @return the address of destination memory - * */ void *rt_memcpy(void *dst, const void *src, rt_ubase_t count) { @@ -257,7 +265,6 @@ void *rt_memcpy(void *dst, const void *src, rt_ubase_t count) * @param n the copied length * * @return the address of destination memory - * */ void *rt_memmove(void *dest, const void *src, rt_ubase_t n) { @@ -297,6 +304,7 @@ rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count) for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) if ((res = *su1 - *su2) != 0) break; + return res; } @@ -323,6 +331,7 @@ char *rt_strstr(const char *s1, const char *s2) return (char *)s1; s1 ++; } + return RT_NULL; } @@ -379,6 +388,7 @@ char *rt_strncpy(char *dst, const char *src, rt_ubase_t n) } } while (--n != 0); } + return (dst); } @@ -417,6 +427,7 @@ rt_ubase_t rt_strcmp(const char *cs, const char *ct) { while (*cs && *cs == *ct) cs++, ct++; + return (*cs - *ct); } @@ -451,9 +462,11 @@ char *rt_strdup(const char *s) rt_size_t len = rt_strlen(s) + 1; char *tmp = (char *)rt_malloc(len); - if (!tmp) return RT_NULL; + if (!tmp) + return RT_NULL; rt_memcpy(tmp, s, len); + return tmp; } #endif @@ -466,7 +479,7 @@ void rt_show_version(void) rt_kprintf("\n \\ | /\n"); rt_kprintf("- RT - Thread Operating System\n"); rt_kprintf(" / | \\ %d.%d.%d build %s\n", RT_VERSION, RT_SUBVERSION, RT_REVISION, __DATE__); - rt_kprintf(" 2006 - 2011 Copyright by rt-thread team\n"); + rt_kprintf(" 2006 - 2012 Copyright by rt-thread team\n"); } /* private function */ @@ -494,7 +507,8 @@ rt_inline rt_int32_t divide(rt_int32_t *n, rt_int32_t base) rt_inline int skip_atoi(const char **s) { register int i=0; - while (isdigit(**s)) i = i*10 + *((*s)++) - '0'; + while (isdigit(**s)) + i = i * 10 + *((*s)++) - '0'; return i; } @@ -528,7 +542,8 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t size = s; digits = (type & LARGE) ? large_digits : small_digits; - if (type & LEFT) type &= ~ZEROPAD; + if (type & LEFT) + type &= ~ZEROPAD; c = (type & ZEROPAD) ? '0' : ' '; @@ -554,14 +569,17 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t #endif i = 0; - if (num == 0) tmp[i++]='0'; + if (num == 0) + tmp[i++]='0'; else { - while (num != 0) tmp[i++] = digits[divide(&num, base)]; + while (num != 0) + tmp[i++] = digits[divide(&num, base)]; } #ifdef RT_PRINTF_PRECISION - if (i > precision) precision = i; + if (i > precision) + precision = i; size -= precision; #else size -= i; @@ -571,7 +589,8 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t { while (size-->0) { - if (buf <= end) *buf = ' '; + if (buf <= end) + *buf = ' '; ++ buf; } } @@ -591,12 +610,14 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t { if (base==8) { - if (buf <= end) *buf = '0'; + if (buf <= end) + *buf = '0'; ++ buf; } else if (base == 16) { - if (buf <= end) *buf = '0'; + if (buf <= end) + *buf = '0'; ++ buf; if (buf <= end) { @@ -612,7 +633,8 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t { while (size-- > 0) { - if (buf <= end) *buf = c; + if (buf <= end) + *buf = c; ++ buf; } } @@ -620,7 +642,8 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t #ifdef RT_PRINTF_PRECISION while (i < precision--) { - if (buf <= end) *buf = '0'; + if (buf <= end) + *buf = '0'; ++ buf; } #endif @@ -628,13 +651,15 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t /* put number in the temporary buffer */ while (i-- > 0) { - if (buf <= end) *buf = tmp[i]; + if (buf <= end) + *buf = tmp[i]; ++ buf; } while (size-- > 0) { - if (buf <= end) *buf = ' '; + if (buf <= end) + *buf = ' '; ++ buf; } @@ -655,7 +680,7 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list rt_uint8_t base; /* the base of number */ rt_uint8_t flags; /* flags to print number */ rt_uint8_t qualifier; /* 'h', 'l', or 'L' for integer fields */ - rt_int32_t field_width; /* width of output field */ + rt_int32_t field_width; /* width of output field */ #ifdef RT_PRINTF_PRECISION int precision; /* min. # of digits for integers and max for a string */ @@ -675,7 +700,8 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list { if (*fmt != '%') { - if (str <= end) *str = *fmt; + if (str <= end) + *str = *fmt; ++ str; continue; } @@ -893,7 +919,7 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list /* the trailing null byte doesn't count towards the total * ++str; */ - return str-buf; + return str - buf; } /** @@ -1015,7 +1041,6 @@ void rt_hw_console_output(const char *str) */ void rt_kprintf(const char *fmt, ...) { - va_list args; rt_size_t length; static char rt_log_buf[RT_CONSOLEBUF_SIZE]; @@ -1091,9 +1116,9 @@ void* rt_malloc_align(rt_size_t size, rt_size_t align) * * @param ptr the memory block pointer */ -void rt_free_align(void* ptr) +void rt_free_align(void *ptr) { - void* real_ptr; + void *real_ptr; real_ptr = (void*)*(rt_uint32_t*)((rt_uint32_t)ptr - sizeof(void*)); rt_free(real_ptr); |
