diff --git a/libc/aio/lio_listio.c b/libc/aio/lio_listio.c index e4e4a71a7e..0889fd9b14 100644 --- a/libc/aio/lio_listio.c +++ b/libc/aio/lio_listio.c @@ -305,7 +305,7 @@ static int lio_sigsetup(FAR struct aiocb * const *list, int nent, /* Attach our signal handler */ - printf("waiter_main: Registering signal handler\n" ); + printf("waiter_main: Registering signal handler\n"); act.sa_sigaction = lio_sighandler; act.sa_flags = SA_SIGINFO; @@ -352,7 +352,7 @@ static int lio_waitall(FAR struct aiocb * const *list, int nent) /* Loop until all I/O completes */ - for (;;) + for (; ; ) { /* Check if all I/O has completed */ diff --git a/libc/math/lib_rint.c b/libc/math/lib_rint.c index c424d05365..d180c2a251 100644 --- a/libc/math/lib_rint.c +++ b/libc/math/lib_rint.c @@ -111,7 +111,7 @@ double rint(double x) if (fremainder == -0.5) { - linteger = ((linteger+1)&~1); + linteger = ((linteger + 1) & ~1); } else if (fremainder < -0.5) { @@ -124,7 +124,7 @@ double rint(double x) if (fremainder == 0.5) { - linteger = ((linteger+1)&~1); + linteger = ((linteger + 1) & ~1); } else if (fremainder > 0.5) { diff --git a/libc/math/lib_rintf.c b/libc/math/lib_rintf.c index f0a329733f..d72cbad7fd 100644 --- a/libc/math/lib_rintf.c +++ b/libc/math/lib_rintf.c @@ -111,7 +111,7 @@ float rintf(float x) if (fremainder == -0.5) { - linteger = ((linteger+1)&~1); + linteger = ((linteger + 1) & ~1); } else if (fremainder < -0.5) { @@ -124,7 +124,7 @@ float rintf(float x) if (fremainder == 0.5) { - linteger = ((linteger+1)&~1); + linteger = ((linteger + 1) & ~1); } else if (fremainder > 0.5) { diff --git a/libc/math/lib_rintl.c b/libc/math/lib_rintl.c index 439c75566f..c6dc09a3b8 100644 --- a/libc/math/lib_rintl.c +++ b/libc/math/lib_rintl.c @@ -111,7 +111,7 @@ long double rintl(long double x) if (fremainder == -0.5) { - llinteger = ((llinteger+1)&~1); + llinteger = ((llinteger + 1) & ~1); } else if (fremainder < -0.5) { @@ -124,7 +124,7 @@ long double rintl(long double x) if (fremainder == 0.5) { - llinteger = ((llinteger+1)&~1); + llinteger = ((llinteger + 1) & ~1); } else if (fremainder > 0.5) { diff --git a/libc/math/lib_trunc.c b/libc/math/lib_trunc.c index b0a93f4575..3f32577402 100644 --- a/libc/math/lib_trunc.c +++ b/libc/math/lib_trunc.c @@ -43,7 +43,15 @@ #ifdef CONFIG_HAVE_DOUBLE double trunc(double x) { - union {double f; uint64_t i;} u = {x}; + union + { + double f; + uint64_t i; + } u = + { + x + }; + int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12; uint64_t m; volatile float __x; diff --git a/libc/math/lib_truncf.c b/libc/math/lib_truncf.c index 73ce7b0ad8..97b1f707bd 100644 --- a/libc/math/lib_truncf.c +++ b/libc/math/lib_truncf.c @@ -42,7 +42,15 @@ float truncf(float x) { - union {float f; uint32_t i;} u = {x}; + union + { + float f; + uint32_t i; + } u = + { + x + }; + int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9; uint32_t m; volatile float __x; diff --git a/libc/math/lib_truncl.c b/libc/math/lib_truncl.c index fce958557c..8fc87f8a55 100644 --- a/libc/math/lib_truncl.c +++ b/libc/math/lib_truncl.c @@ -58,7 +58,10 @@ union ldshape long double truncl(long double x) { - union ldshape u = {x}; + union ldshape u = + { + x + }; int e = u.i.se & 0x7fff; int s = u.i.se >> 15; long double y; diff --git a/libc/misc/lib_crc32.c b/libc/misc/lib_crc32.c index 0c111a8824..40e7c014a0 100644 --- a/libc/misc/lib_crc32.c +++ b/libc/misc/lib_crc32.c @@ -37,7 +37,7 @@ * - The values must be right-shifted by eight bits by the updcrc logic; the shift must * be u_(bring in zeroes). On some hardware you could probably optimize the shift in * assembler by using byte-swap instructions polynomial $edb88320 - ************************************************************************************************/ + ************************************************************************************************/ /************************************************************************************************ * Included Files diff --git a/libc/misc/lib_match.c b/libc/misc/lib_match.c index 3bebb1a946..690d111a5c 100644 --- a/libc/misc/lib_match.c +++ b/libc/misc/lib_match.c @@ -191,7 +191,7 @@ int match(const char *pattern, const char *string) { const char *or; - for (;;) + for (; ; ) { or = strchr(pattern, '|'); if (or == (char *)0) diff --git a/libc/net/lib_inetaddr.c b/libc/net/lib_inetaddr.c index c05b596974..5a2d9a97b2 100644 --- a/libc/net/lib_inetaddr.c +++ b/libc/net/lib_inetaddr.c @@ -55,7 +55,7 @@ * The inet_addr() function converts the string pointed to by cp, in the * standard IPv4 dotted decimal notation, to an integer value suitable for * use as an Internet address. - + * ****************************************************************************/ in_addr_t inet_addr(FAR const char *cp) diff --git a/libc/net/lib_inetntoa.c b/libc/net/lib_inetntoa.c index 60c5742871..4bd49db921 100644 --- a/libc/net/lib_inetntoa.c +++ b/libc/net/lib_inetntoa.c @@ -65,7 +65,7 @@ FAR char *inet_ntoa(struct in_addr in) { static char buffer[INET_ADDRSTRLEN+2]; - FAR unsigned char *ptr = (FAR unsigned char*)&in.s_addr; + FAR unsigned char *ptr = (FAR unsigned char *)&in.s_addr; sprintf(buffer, "%u.%u.%u.%u", ptr[0], ptr[1], ptr[2], ptr[3]); return buffer; } @@ -73,7 +73,7 @@ FAR char *inet_ntoa(struct in_addr in) FAR char *_inet_ntoa(in_addr_t in) { static char buffer[INET_ADDRSTRLEN+2]; - FAR unsigned char *ptr = (FAR unsigned char*)∈ + FAR unsigned char *ptr = (FAR unsigned char *)∈ sprintf(buffer, "%u.%u.%u.%u", ptr[0], ptr[1], ptr[2], ptr[3]); return buffer; } diff --git a/libc/net/lib_inetntop.c b/libc/net/lib_inetntop.c index 460ec31b10..2a6037f97c 100644 --- a/libc/net/lib_inetntop.c +++ b/libc/net/lib_inetntop.c @@ -107,7 +107,7 @@ static int inet_ipv4_ntop(FAR const void *src, FAR char *dest, socklen_t size) return -ENOSPC; } - ptr = (FAR char*)src; + ptr = (FAR char *)src; sprintf(dest, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); return OK; } diff --git a/libc/net/lib_inetpton.c b/libc/net/lib_inetpton.c index c69af48bc1..96338bde11 100644 --- a/libc/net/lib_inetpton.c +++ b/libc/net/lib_inetpton.c @@ -111,7 +111,7 @@ static int inet_ipv4_pton(FAR const char *src, FAR void *dest) numoffset = 0; ndots = 0; - for (;;) + for (; ; ) { ch = (uint8_t)src[srcoffset++]; @@ -225,7 +225,7 @@ static int inet_ipv6_pton(FAR const char *src, FAR void *dest) nrsep = 0; rtime = false; - for (;;) + for (; ; ) { ch = (uint8_t)src[srcoffset++]; diff --git a/libc/net/lib_shutdown.c b/libc/net/lib_shutdown.c index 6b71f847c3..028fb96eeb 100644 --- a/libc/net/lib_shutdown.c +++ b/libc/net/lib_shutdown.c @@ -59,7 +59,7 @@ * * The shutdown() function disables subsequent send and/or receive * operations on a socket, depending on the value of the how argument. - + * * Input Paramteers: * sockfd - Specifies the file descriptor of the socket. * how - Specifies the type of shutdown. The values are as follows: @@ -71,7 +71,7 @@ * Returned Value: * Upon successful completion, shutdown() will return 0; otherwise, -1 will * be returned and errno set to indicate the error. - + * * EBADF - The socket argument is not a valid file descriptor. * EINVAL - The how argument is invalid. * ENOTCONN - The socket is not connected. diff --git a/libc/netdb/lib_dnsclient.c b/libc/netdb/lib_dnsclient.c index a959005f53..c510f2f431 100644 --- a/libc/netdb/lib_dnsclient.c +++ b/libc/netdb/lib_dnsclient.c @@ -534,11 +534,11 @@ static int dns_recv_response(int sd, FAR struct sockaddr *addr, int d = 64; nameptr = dns_parse_name((uint8_t *)buffer + 12) + 4; - for (;;) + for (; ; ) { ndbg("%02X %02X %02X %02X %02X %02X %02X %02X \n", - nameptr[0],nameptr[1],nameptr[2],nameptr[3], - nameptr[4],nameptr[5],nameptr[6],nameptr[7]); + nameptr[0], nameptr[1], nameptr[2], nameptr[3], + nameptr[4], nameptr[5], nameptr[6], nameptr[7]); nameptr += 8; d -= 8; @@ -589,10 +589,10 @@ static int dns_recv_response(int sd, FAR struct sockaddr *addr, ans->u.ipv4.s_addr = *(FAR uint32_t *)(nameptr + 10); nvdbg("IPv4 address: %d.%d.%d.%d\n", - (ans->u.ipv4.s_addr ) & 0xff, - (ans->u.ipv4.s_addr >> 8 ) & 0xff, - (ans->u.ipv4.s_addr >> 16 ) & 0xff, - (ans->u.ipv4.s_addr >> 24 ) & 0xff); + (ans->u.ipv4.s_addr ) & 0xff, + (ans->u.ipv4.s_addr >> 8 ) & 0xff, + (ans->u.ipv4.s_addr >> 16) & 0xff, + (ans->u.ipv4.s_addr >> 24) & 0xff); if (*addrlen >= sizeof(struct sockaddr_in)) { diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index f32fdc1d29..812b1fedb9 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -191,36 +191,32 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type, return -ERANGE; } + info = (FAR struct hostent_info_s *)buf; + dest = info->hi_data; + buflen -= (sizeof(struct hostent_info_s) - 1); - info = (FAR struct hostent_info_s *)buf; - dest = info->hi_data; - buflen -= (sizeof(struct hostent_info_s) - 1); + memset(host, 0, sizeof(struct hostent)); + memset(info, 0, sizeof(struct hostent_info_s)); + memcpy(dest, src, addrlen); - memset(host, 0, sizeof(struct hostent)); - memset(info, 0, sizeof(struct hostent_info_s)); - memcpy(dest, src, addrlen); + info->hi_addrlist[0] = dest; + host->h_addr_list = info->hi_addrlist; + host->h_length = addrlen; - info->hi_addrlist[0] = dest; - host->h_addr_list = info->hi_addrlist; - host->h_length = addrlen; + dest += addrlen; + buflen -= addrlen; - dest += addrlen; - buflen -= addrlen; + /* And copy localhost host name */ - /* And copy localhost host name */ - - namelen = strlen(g_lo_hostname); - if (addrlen + namelen + 1 > buflen) - { - herrnocode = ERANGE; - goto errorout_with_herrnocode; - } - - strncpy(dest, g_lo_hostname, buflen); - return 0; + namelen = strlen(g_lo_hostname); + if (addrlen + namelen + 1 > buflen) + { + herrnocode = ERANGE; + goto errorout_with_herrnocode; } - return 1; + strncpy(dest, g_lo_hostname, buflen); + return 0; errorout_with_herrnocode: if (h_errnop) diff --git a/libc/netdb/lib_parsehostfile.c b/libc/netdb/lib_parsehostfile.c index 8913a8a2b2..177c00a3f3 100644 --- a/libc/netdb/lib_parsehostfile.c +++ b/libc/netdb/lib_parsehostfile.c @@ -61,7 +61,7 @@ /* Check if character is any kind of white space (except for newline) */ #define lib_isspace(c) \ - ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\f' || c== '\v') + ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\f' || c == '\v') /**************************************************************************** * Private Type Definitions diff --git a/libc/queue/sq_rem.c b/libc/queue/sq_rem.c index 2abf6d34e3..dd51390859 100644 --- a/libc/queue/sq_rem.c +++ b/libc/queue/sq_rem.c @@ -66,7 +66,7 @@ void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue) else { FAR sq_entry_t *prev; - for (prev = (FAR sq_entry_t*)queue->head; + for (prev = (FAR sq_entry_t *)queue->head; prev && prev->flink != node; prev = prev->flink); diff --git a/libc/stdio/lib_dtoa.c b/libc/stdio/lib_dtoa.c index 6241a486b4..68ae7b2098 100644 --- a/libc/stdio/lib_dtoa.c +++ b/libc/stdio/lib_dtoa.c @@ -427,7 +427,10 @@ static Bigint *pow5mult(Bigint * b, int k) { Bigint *b1, *p5, *p51; int i; - static int p05[3] = { 5, 25, 125 }; + static int p05[3] = + { + 5, 25, 125 + }; if ((i = k & 3)) b = multadd(b, p05[i - 1], 0); @@ -444,7 +447,7 @@ static Bigint *pow5mult(Bigint * b, int k) p5->next = 0; } - for (;;) + for (; ; ) { if (k & 1) { @@ -574,7 +577,8 @@ static int cmp(Bigint * a, Bigint * b) xa = xa0 + j; xb0 = b->x; xb = xb0 + j; - for (;;) + + for (; ; ) { if (*--xa != *--xb) { @@ -807,13 +811,27 @@ static const double tens[] = }; #ifdef IEEE_Arith -static const double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; -static const double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 }; +static const double bigtens[] = +{ + 1e16, 1e32, 1e64, 1e128, 1e256 +}; + +static const double tinytens[] = +{ + 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 +}; # define n_bigtens 5 #else -static const double bigtens[] = { 1e16, 1e32 }; -static const double tinytens[] = { 1e-16, 1e-32 }; +static const double bigtens[] = +{ + 1e16, 1e32 +}; + +static const double tinytens[] = +{ + 1e-16, 1e-32 +}; # define n_bigtens 2 #endif @@ -1284,7 +1302,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) /* Use Steele & White method of only generating digits needed. */ eps = 0.5 / tens[ilim - 1] - eps; - for (i = 0;;) + for (i = 0; ; ) { L = (int)d; d -= L; @@ -1314,7 +1332,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) /* Generate ilim digits, then fix them up. */ eps *= tens[ilim - 1]; - for (i = 1;; i++, d *= 10.) + for (i = 1; ; i++, d *= 10.) { L = (int)d; d -= L; @@ -1363,7 +1381,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) goto one_digit; } - for (i = 1;; i++) + for (i = 1; ; i++) { L = (int)(d / ds); d -= L * ds; @@ -1586,7 +1604,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) mhi = lshift(mhi, Log2P); } - for (i = 1;; i++) + for (i = 1; ; i++) { dig = quorem(b, S) + '0'; /* Do we yet have the shortest decimal string that will round to d? */ @@ -1634,8 +1652,10 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) if (j_1 > 0) { if (dig == '9') - { /* possible if i == 1 */ - round_9_up: + { + /* possible if i == 1 */ + + round_9_up: *s++ = '9'; goto roundoff; } @@ -1664,7 +1684,7 @@ char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) } else { - for (i = 1;; i++) + for (i = 1; ; i++) { *s++ = dig = quorem(b, S) + '0'; if (i >= ilim) @@ -1713,7 +1733,9 @@ ret: ret1: Bfree(b); if (s == s0) - { /* Don't return empty string */ + { + /* Don't return empty string */ + *s++ = '0'; k = 0; } diff --git a/libc/stdio/lib_fopen.c b/libc/stdio/lib_fopen.c index a29140ebae..fc0856ce5b 100644 --- a/libc/stdio/lib_fopen.c +++ b/libc/stdio/lib_fopen.c @@ -137,7 +137,7 @@ static int lib_mode2oflags(FAR const char *mode) { /* Write to the end of the file */ - oflags = O_WROK|O_CREAT|O_APPEND; + oflags = O_WROK | O_CREAT | O_APPEND; state = MODE_A; } else diff --git a/libc/stdio/lib_libfflush.c b/libc/stdio/lib_libfflush.c index 6c0dfabe83..ff9aaece4b 100644 --- a/libc/stdio/lib_libfflush.c +++ b/libc/stdio/lib_libfflush.c @@ -121,11 +121,11 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) if (stream->fs_bufpos != stream->fs_bufstart) { - /* Make sure that the buffer holds buffered write data. We do not - * support concurrent read/write buffer usage. - */ + /* Make sure that the buffer holds buffered write data. We do not + * support concurrent read/write buffer usage. + */ - if (stream->fs_bufread != stream->fs_bufstart) + if (stream->fs_bufread != stream->fs_bufstart) { /* The buffer holds read data... just return zero meaning "no bytes * remaining in the buffer." diff --git a/libc/stdio/lib_libfgets.c b/libc/stdio/lib_libfgets.c index 210d273bf3..884cc1f535 100644 --- a/libc/stdio/lib_libfgets.c +++ b/libc/stdio/lib_libfgets.c @@ -177,7 +177,7 @@ FAR char *lib_fgets(FAR char *buf, size_t buflen, FILE *stream, * the next character and one for the null terminator. */ - for (;;) + for (; ; ) { /* Get the next character */ diff --git a/libc/stdio/lib_libflushall.c b/libc/stdio/lib_libflushall.c index 7c7b8d9b66..85e807a9ea 100644 --- a/libc/stdio/lib_libflushall.c +++ b/libc/stdio/lib_libflushall.c @@ -97,38 +97,38 @@ int lib_flushall(FAR struct streamlist *list) if (list) { - int i; + int i; - /* Process each stream in the thread's stream list */ + /* Process each stream in the thread's stream list */ - stream_semtake(list); - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) - { - FILE *stream = &list->sl_streams[i]; + stream_semtake(list); + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + { + FILE *stream = &list->sl_streams[i]; - /* If the stream is open (i.e., assigned a non-negative file - * descriptor) and opened for writing, then flush all of the pending - * write data in the stream. - */ + /* If the stream is open (i.e., assigned a non-negative file + * descriptor) and opened for writing, then flush all of the pending + * write data in the stream. + */ - if (stream->fs_fd >= 0 && (stream->fs_oflags & O_WROK) != 0) - { - /* Flush the writable FILE */ + if (stream->fs_fd >= 0 && (stream->fs_oflags & O_WROK) != 0) + { + /* Flush the writable FILE */ - ret = lib_fflush(stream, true); - if (ret < 0) - { - /* An error occurred during the flush AND/OR we were unable - * to flush all of the buffered write data. Remember the - * last errcode. - */ + ret = lib_fflush(stream, true); + if (ret < 0) + { + /* An error occurred during the flush AND/OR we were unable + * to flush all of the buffered write data. Remember the + * last errcode. + */ - lasterrno = ret; - } - } - } + lasterrno = ret; + } + } + } - stream_semgive(list); + stream_semgive(list); } /* If any flush failed, return the errorcode of the last failed flush */ diff --git a/libc/stdio/lib_libfread.c b/libc/stdio/lib_libfread.c index 27011738c9..48ab4ad4cf 100644 --- a/libc/stdio/lib_libfread.c +++ b/libc/stdio/lib_libfread.c @@ -86,10 +86,10 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) { - unsigned char *dest = (unsigned char*)ptr; - ssize_t bytes_read; + FAR unsigned char *dest = (FAR unsigned char*)ptr; + ssize_t bytes_read; #if CONFIG_STDIO_BUFFER_SIZE > 0 - int ret; + int ret; #endif /* Make sure that reading from this stream is allowed */ @@ -288,7 +288,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) #if CONFIG_STDIO_BUFFER_SIZE > 0 shortread: #endif - bytes_read = dest - (unsigned char*)ptr; + bytes_read = dest - (FAR unsigned char *)ptr; /* Set or clear the EOF indicator. If we get here because of a * short read and the total number of* bytes read is zero, then diff --git a/libc/stdio/lib_libvsprintf.c b/libc/stdio/lib_libvsprintf.c index 61cac29283..634b172ad0 100644 --- a/libc/stdio/lib_libvsprintf.c +++ b/libc/stdio/lib_libvsprintf.c @@ -1291,7 +1291,7 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list a /* Accumulate the field width integer. */ int n = ((int)(FMT_CHAR)) - (int)'0'; - for (;;) + for (; ; ) { FMT_NEXT; if (FMT_CHAR >= '0' && FMT_CHAR <= '9') @@ -1363,10 +1363,10 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list a #endif /* Get the string to output */ - ptmp = va_arg(ap, char *); + ptmp = va_arg(ap, FAR char *); if (!ptmp) { - ptmp = (char*)g_nullstring; + ptmp = (FAR char *)g_nullstring; } /* Get the width of the string and perform right-justification diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c index c094cb1fb3..d4996dceef 100644 --- a/libc/stdio/lib_sscanf.c +++ b/libc/stdio/lib_sscanf.c @@ -168,7 +168,7 @@ int sscanf(FAR const char *buf, FAR const char *fmt, ...) int count; va_start(ap, fmt); - count = vsscanf((FAR const char*)buf, fmt, ap); + count = vsscanf((FAR const char *)buf, fmt, ap); va_end(ap); return count; } @@ -274,7 +274,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) tv = NULL; /* To avoid warnings about begin uninitialized */ if (!noassign) { - tv = va_arg(ap, char*); + tv = va_arg(ap, FAR char *); tv[0] = '\0'; } @@ -330,7 +330,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) tv = NULL; /* To avoid warnings about beign uninitialized */ if (!noassign) { - tv = va_arg(ap, char*); + tv = va_arg(ap, FAR char *); tv[0] = '\0'; } @@ -389,12 +389,12 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) if (lflag) { - plong = va_arg(ap, long*); + plong = va_arg(ap, FAR long *); *plong = 0; } else { - pint = va_arg(ap, int*); + pint = va_arg(ap, FAR int *); *pint = 0; } } @@ -540,13 +540,13 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) #ifdef CONFIG_HAVE_DOUBLE if (lflag) { - pd = va_arg(ap, double_t*); + pd = va_arg(ap, FAR double_t *); *pd = 0.0; } else #endif { - pf = va_arg(ap, float*); + pf = va_arg(ap, FAR float *); *pf = 0.0; } } @@ -644,12 +644,12 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) if (lflag) { - FAR long *plong = va_arg(ap, long*); + FAR long *plong = va_arg(ap, FAR long *); *plong = (long)nchars; } else { - FAR int *pint = va_arg(ap, int*); + FAR int *pint = va_arg(ap, FAR int *); *pint = (int)nchars; } } diff --git a/libc/stdlib/lib_qsort.c b/libc/stdlib/lib_qsort.c index 32f10c0469..8c0e2825b1 100644 --- a/libc/stdlib/lib_qsort.c +++ b/libc/stdlib/lib_qsort.c @@ -115,8 +115,8 @@ static inline FAR char *med3(FAR char *a, FAR char *b, FAR char *c, FAR const void *)) { return compar(a, b) < 0 ? - (compar(b, c) < 0 ? b : (compar(a, c) < 0 ? c : a )) - :(compar(b, c) > 0 ? b : (compar(a, c) < 0 ? a : c )); + (compar(b, c) < 0 ? b : (compar(a, c) < 0 ? c : a)) : + (compar(b, c) > 0 ? b : (compar(a, c) < 0 ? a : c)); } /**************************************************************************** @@ -218,7 +218,7 @@ loop: pa = pb = (FAR char *)base + width; pc = pd = (FAR char *)base + (nel - 1) * width; - for (;;) + for (; ; ) { while (pb <= pc && (r = compar(pb, base)) <= 0) { diff --git a/libc/stdlib/lib_strtod.c b/libc/stdlib/lib_strtod.c index 5b462b3527..2f7ed81f55 100644 --- a/libc/stdlib/lib_strtod.c +++ b/libc/stdlib/lib_strtod.c @@ -168,7 +168,7 @@ double_t strtod(const char *str, char **endptr) /* Handle optional sign */ negative = 0; - switch(*++p) + switch (*++p) { case '-': negative = 1; /* Fall through to increment pos */ diff --git a/libc/string/lib_memccpy.c b/libc/string/lib_memccpy.c index 525eb872c5..bbb307afc6 100644 --- a/libc/string/lib_memccpy.c +++ b/libc/string/lib_memccpy.c @@ -68,8 +68,8 @@ FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n) { - FAR unsigned char *pout = (FAR unsigned char*)s1; - FAR unsigned char *pin = (FAR unsigned char*)s2; + FAR unsigned char *pout = (FAR unsigned char *)s1; + FAR unsigned char *pin = (FAR unsigned char *)s2; /* Copy at most n bytes */ diff --git a/libc/string/lib_memcpy.c b/libc/string/lib_memcpy.c index aff9c34347..6a4b2bbe34 100644 --- a/libc/string/lib_memcpy.c +++ b/libc/string/lib_memcpy.c @@ -56,8 +56,8 @@ #ifndef CONFIG_ARCH_MEMCPY FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n) { - FAR unsigned char *pout = (FAR unsigned char*)dest; - FAR unsigned char *pin = (FAR unsigned char*)src; + FAR unsigned char *pout = (FAR unsigned char *)dest; + FAR unsigned char *pin = (FAR unsigned char *)src; while (n-- > 0) *pout++ = *pin++; return dest; } diff --git a/libc/string/lib_memmove.c b/libc/string/lib_memmove.c index d4b28b4f05..fb672f54eb 100644 --- a/libc/string/lib_memmove.c +++ b/libc/string/lib_memmove.c @@ -52,11 +52,14 @@ #ifndef CONFIG_ARCH_MEMMOVE FAR void *memmove(FAR void *dest, FAR const void *src, size_t count) { - char *tmp, *s; + FAR char *tmp; + FAR char *s; + if (dest <= src) { - tmp = (char*) dest; - s = (char*) src; + tmp = (FAR char *) dest; + s = (FAR char *) src; + while (count--) { *tmp++ = *s++; @@ -64,8 +67,9 @@ FAR void *memmove(FAR void *dest, FAR const void *src, size_t count) } else { - tmp = (char*) dest + count; - s = (char*) src + count; + tmp = (FAR char *) dest + count; + s = (FAR char *) src + count; + while (count--) { *--tmp = *--s; diff --git a/libc/string/lib_memset.c b/libc/string/lib_memset.c index 67f45ab6a9..fc2f83b30b 100644 --- a/libc/string/lib_memset.c +++ b/libc/string/lib_memset.c @@ -64,7 +64,7 @@ ****************************************************************************/ #ifndef CONFIG_ARCH_MEMSET -void *memset(void *s, int c, size_t n) +FAR void *memset(FAR void *s, int c, size_t n) { #ifdef CONFIG_MEMSET_OPTSPEED /* This version is optimized for speed (you could do better @@ -87,7 +87,7 @@ void *memset(void *s, int c, size_t n) if ((addr & 1) != 0) { - *(uint8_t*)addr = (uint8_t)c; + *(FAR uint8_t *)addr = (uint8_t)c; addr += 1; n -= 1; } @@ -102,7 +102,7 @@ void *memset(void *s, int c, size_t n) if ((addr & 3) != 0) { - *(uint16_t*)addr = val16; + *(FAR uint16_t *)addr = val16; addr += 2; n -= 2; } @@ -112,7 +112,7 @@ void *memset(void *s, int c, size_t n) while (n >= 4) { - *(uint32_t*)addr = val32; + *(FAR uint32_t *)addr = val32; addr += 4; n -= 4; } @@ -127,7 +127,7 @@ void *memset(void *s, int c, size_t n) if ((addr & 7) != 0) { - *(uint32_t*)addr = val32; + *(FAR uint32_t *)addr = val32; addr += 4; n -= 4; } @@ -136,7 +136,7 @@ void *memset(void *s, int c, size_t n) while (n >= 8) { - *(uint64_t*)addr = val64; + *(FAR uint64_t *)addr = val64; addr += 8; n -= 8; } @@ -151,7 +151,7 @@ void *memset(void *s, int c, size_t n) if (n >= 4) { - *(uint32_t*)addr = val32; + *(FAR uint32_t *)addr = val32; addr += 4; n -= 4; } @@ -167,20 +167,20 @@ void *memset(void *s, int c, size_t n) if (n >= 2) { - *(uint16_t*)addr = val16; + *(FAR uint16_t *)addr = val16; addr += 2; n -= 2; } if (n >= 1) { - *(uint8_t*)addr = (uint8_t)c; + *(FAR uint8_t *)addr = (uint8_t)c; } } #else /* This version is optimized for size */ - unsigned char *p = (unsigned char*)s; + FAR unsigned char *p = (FAR unsigned char*)s; while (n-- > 0) *p++ = c; #endif return s; diff --git a/libc/string/lib_strcasecmp.c b/libc/string/lib_strcasecmp.c index 4aec2826a5..9017625b2a 100644 --- a/libc/string/lib_strcasecmp.c +++ b/libc/string/lib_strcasecmp.c @@ -47,10 +47,10 @@ ****************************************************************************/ #ifndef CONFIG_ARCH_STRCMP -int strcasecmp(const char *cs, const char *ct) +int strcasecmp(FAR const char *cs, FAR const char *ct) { int result; - for (;;) + for (; ; ) { if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) { diff --git a/libc/string/lib_strcasestr.c b/libc/string/lib_strcasestr.c index 85cb9a043a..0a56c73180 100644 --- a/libc/string/lib_strcasestr.c +++ b/libc/string/lib_strcasestr.c @@ -57,7 +57,7 @@ static FAR char *strcasechr(FAR const char *s, int uc) ch = *s; if (toupper(ch) == uc) { - return (FAR char*)s; + return (FAR char *)s; } } } @@ -71,9 +71,9 @@ static FAR char *strcasechr(FAR const char *s, int uc) FAR char *strcasestr(FAR const char *str, FAR const char *substr) { - const char *candidate; /* Candidate in str with matching start character */ - char ch; /* First character of the substring */ - int len; /* The length of the substring */ + FAR const char *candidate; /* Candidate in str with matching start character */ + char ch; /* First character of the substring */ + int len; /* The length of the substring */ /* Special case the empty substring */ @@ -86,7 +86,7 @@ FAR char *strcasestr(FAR const char *str, FAR const char *substr) * the string */ - return (char*)str; + return (FAR char *)str; } /* Search for the substring */ @@ -94,7 +94,7 @@ FAR char *strcasestr(FAR const char *str, FAR const char *substr) candidate = str; ch = toupper(ch); - for (;;) + for (; ; ) { /* strcasechr() will return a pointer to the next occurrence of the * character ch in the string (ignoring case) @@ -103,23 +103,23 @@ FAR char *strcasestr(FAR const char *str, FAR const char *substr) candidate = strcasechr(candidate, ch); if (!candidate || strlen(candidate) < len) { - /* First character of the substring does not appear in the string - * or the remainder of the string is not long enough to contain the - * substring. - */ + /* First character of the substring does not appear in the string + * or the remainder of the string is not long enough to contain the + * substring. + */ - return NULL; + return NULL; } /* Check if this is the beginning of a matching substring (ignoring case) */ if (strncasecmp(candidate, substr, len) == 0) { - /* Yes.. return the pointer to the first occurrence of the matching - * substring. - */ + /* Yes.. return the pointer to the first occurrence of the matching + * substring. + */ - return (char*)candidate; + return (FAR char *)candidate; } /* No, find the next candidate after this one */ diff --git a/libc/string/lib_strcmp.c b/libc/string/lib_strcmp.c index 364caa7f5f..9839c4ee99 100644 --- a/libc/string/lib_strcmp.c +++ b/libc/string/lib_strcmp.c @@ -46,10 +46,10 @@ ****************************************************************************/ #ifndef CONFIG_ARCH_STRCMP -int strcmp(const char *cs, const char *ct) +int strcmp(FAR const char *cs, FAR const char *ct) { register signed char result; - for (;;) + for (; ; ) { if ((result = *cs - *ct++) != 0 || !*cs++) break; diff --git a/libc/string/lib_strdup.c b/libc/string/lib_strdup.c index 5ba87ae27b..ab5c620a12 100644 --- a/libc/string/lib_strdup.c +++ b/libc/string/lib_strdup.c @@ -47,12 +47,12 @@ * Public Functions ****************************************************************************/ -FAR char *strdup(const char *s) +FAR char *strdup(FAR const char *s) { FAR char *news = NULL; if (s) { - news = (FAR char*)lib_malloc(strlen(s) + 1); + news = (FAR char *)lib_malloc(strlen(s) + 1); if (news) { strcpy(news, s); diff --git a/libc/string/lib_strndup.c b/libc/string/lib_strndup.c index 1b9d868067..984b363944 100644 --- a/libc/string/lib_strndup.c +++ b/libc/string/lib_strndup.c @@ -74,7 +74,7 @@ FAR char *strndup(FAR const char *s, size_t size) /* Allocate the new string, adding 1 for the NUL terminator */ - news = (FAR char*)lib_malloc(allocsize + 1); + news = (FAR char *)lib_malloc(allocsize + 1); if (news) { /* Copy the string into the allocated memory and add a NUL diff --git a/libc/string/lib_strpbrk.c b/libc/string/lib_strpbrk.c index 78d54ba407..4170926bb6 100644 --- a/libc/string/lib_strpbrk.c +++ b/libc/string/lib_strpbrk.c @@ -45,7 +45,7 @@ * Public Functions ****************************************************************************/ -char *strpbrk(const char *str, const char *charset) +FAR char *strpbrk(FAR const char *str, FAR const char *charset) { /* Sanity checking */ @@ -66,7 +66,7 @@ char *strpbrk(const char *str, const char *charset) { /* Yes, then this position must be the first occurrence in string */ - return (char*)str; + return (FAR char *)str; } /* This character from the strings matches none of those in the charset. diff --git a/libc/string/lib_strrchr.c b/libc/string/lib_strrchr.c index 601f655b43..3b08598bb2 100644 --- a/libc/string/lib_strrchr.c +++ b/libc/string/lib_strrchr.c @@ -49,7 +49,7 @@ * occurrence of the character c in the string s. */ -char *strrchr(const char *s, int c) +FAR char *strrchr(FAR const char *s, int c) { if (s) { @@ -58,7 +58,7 @@ char *strrchr(const char *s, int c) { if (*p == c) { - return (char*)p; + return (FAR char *)p; } } } diff --git a/libc/string/lib_strstr.c b/libc/string/lib_strstr.c index eb629b709a..06404402a9 100644 --- a/libc/string/lib_strstr.c +++ b/libc/string/lib_strstr.c @@ -62,13 +62,13 @@ FAR char *strstr(FAR const char *str, FAR const char *substr) * the string */ - return (char*)str; + return (FAR char *)str; } /* Search for the substring */ candidate = str; - for (;;) + for (; ; ) { /* strchr() will return a pointer to the next occurrence of the * character ch in the string @@ -77,19 +77,19 @@ FAR char *strstr(FAR const char *str, FAR const char *substr) candidate = strchr(candidate, ch); if (!candidate || strlen(candidate) < len) { - /* First character of the substring does not appear in the string - * or the remainder of the string is not long enough to contain the - * substring. - */ + /* First character of the substring does not appear in the string + * or the remainder of the string is not long enough to contain the + * substring. + */ - return NULL; + return NULL; } /* Check if this is the beginning of a matching substring */ if (strncmp(candidate, substr, len) == 0) { - return (char*)candidate; + return (FAR char *)candidate; } /* No, find the next candidate after this one */ diff --git a/libc/string/lib_vikmemcpy.c b/libc/string/lib_vikmemcpy.c index 7dbcd331b2..41ab3ecf37 100644 --- a/libc/string/lib_vikmemcpy.c +++ b/libc/string/lib_vikmemcpy.c @@ -310,10 +310,10 @@ typedef uint32_t UIntN; * ****************************************************************************/ -void *memcpy(void *dest, const void *src, size_t count) +FAR void *memcpy(FAR void *dest, FAR const void *src, size_t count) { - uint8_t *dst8 = (uint8_t*)dest; - uint8_t *src8 = (uint8_t*)src; + FAR uint8_t *dst8 = (FAR uint8_t *)dest; + FAR uint8_t *src8 = (FAR uint8_t *)src; if (count < 8) { diff --git a/libc/time/lib_dayofweek.c b/libc/time/lib_dayofweek.c index b630c838cb..55fb3c4370 100644 --- a/libc/time/lib_dayofweek.c +++ b/libc/time/lib_dayofweek.c @@ -104,6 +104,7 @@ int clock_dayoftheweek(int mday, int month, int year) } month -= 2; - return (mday + year + year/4 - year/100 + year/400 + ( 31 * month) / 12) % 7; + return (mday + year + year / 4 - year / 100 + year / 400 + + (31 * month) / 12) % 7; } #endif /* CONFIG_TIME_EXTENDED */ diff --git a/libc/time/lib_gmtimer.c b/libc/time/lib_gmtimer.c index b42d7a7c90..d3f1740189 100644 --- a/libc/time/lib_gmtimer.c +++ b/libc/time/lib_gmtimer.c @@ -169,7 +169,8 @@ static void clock_utc2julian(time_t jd, int *year, int *month, int *day) /* Only handles dates since Jan 1, 1970 */ -static void clock_utc2calendar(time_t days, int *year, int *month, int *day) +static void clock_utc2calendar(time_t days, FAR int *year, FAR int *month, + FAR int *day) { int value; int min; @@ -181,13 +182,13 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day) * following: */ - value = days / (4*365 + 1); /* Number of 4-years periods since the epoch*/ - days -= value * (4*365 + 1); /* Remaining days */ - value <<= 2; /* Years since the epoch */ + value = days / (4 * 365 + 1); /* Number of 4-years periods since the epoch */ + days -= value * (4 * 365 + 1); /* Remaining days */ + value <<= 2; /* Years since the epoch */ /* Then we will brute force the next 0-3 years */ - for (;;) + for (; ; ) { /* Is this year a leap year (we'll need this later too) */ @@ -231,7 +232,7 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day) /* Get the number of days that occurred before the beginning of the month * following the midpoint. - */ + */ tmp = clock_daysbeforemonth(value + 1, leapyear); diff --git a/libc/time/lib_localtime.c b/libc/time/lib_localtime.c index 6e587f9486..c091d3d50d 100644 --- a/libc/time/lib_localtime.c +++ b/libc/time/lib_localtime.c @@ -437,10 +437,10 @@ static void settzname(void) FAR struct state_s *const sp = lclptr; int i; - tzname[0] = tzname[1] = (FAR char*)g_wildabbr; + tzname[0] = tzname[1] = (FAR char *)g_wildabbr; if (sp == NULL) { - tzname[0] = tzname[1] = (FAR char*)GMT; + tzname[0] = tzname[1] = (FAR char *)GMT; return; } @@ -528,6 +528,7 @@ static int tzload(FAR const char *name, struct state_s st; } u; }; + char *fullname; u_t *up; int doaccess; @@ -1158,7 +1159,7 @@ static FAR const char *getrule(FAR const char *strp, return strp; } -/*Given a year, a rule, and the offset from UT at the time that rule takes +/* Given a year, a rule, and the offset from UT at the time that rule takes * effect, calculate the year-relative time that rule takes effect. */ @@ -2122,7 +2123,7 @@ static time_t time2sub(struct tm *const tmp, } } - for (;;) + for (; ; ) { i = g_mon_lengths[isleap(y)][yourtm.tm_mon]; if (yourtm.tm_mday <= i) @@ -2198,7 +2199,7 @@ static time_t time2sub(struct tm *const tmp, hi = -(lo + 1); } - for (;;) + for (; ; ) { t = lo / 2 + hi / 2; if (t < lo) diff --git a/libc/unistd/lib_getopt.c b/libc/unistd/lib_getopt.c index 0c939fc420..1c0450100c 100644 --- a/libc/unistd/lib_getopt.c +++ b/libc/unistd/lib_getopt.c @@ -187,82 +187,82 @@ int getopt(int argc, FAR char *const argv[], FAR const char *optstring) g_optptr++; } - /* Special case handling of "-" and "-:" */ + /* Special case handling of "-" and "-:" */ - if (!*g_optptr) - { - optopt = '\0'; /* We'll fix up g_optptr the next time we are called */ - return '?'; - } + if (!*g_optptr) + { + optopt = '\0'; /* We'll fix up g_optptr the next time we are called */ + return '?'; + } - /* Handle the case of "-:" */ + /* Handle the case of "-:" */ - if (*g_optptr == ':') - { - optopt = ':'; - g_optptr++; - return '?'; - } + if (*g_optptr == ':') + { + optopt = ':'; + g_optptr++; + return '?'; + } - /* g_optptr now points at the next option and it is not something crazy. - * check if the option is in the list of valid options. - */ + /* g_optptr now points at the next option and it is not something crazy. + * check if the option is in the list of valid options. + */ - optchar = strchr(optstring, *g_optptr); - if (!optchar) - { - /* No this character is not in the list of valid options */ + optchar = strchr(optstring, *g_optptr); + if (!optchar) + { + /* No this character is not in the list of valid options */ - optopt = *g_optptr; - g_optptr++; - return '?'; - } + optopt = *g_optptr; + g_optptr++; + return '?'; + } - /* Yes, the character is in the list of valid options. Does it have an - * required argument? - */ + /* Yes, the character is in the list of valid options. Does it have an + * required argument? + */ - if (optchar[1] != ':') - { - /* No, no arguments. Just return the character that we found */ + if (optchar[1] != ':') + { + /* No, no arguments. Just return the character that we found */ - g_optptr++; - return *optchar; - } + g_optptr++; + return *optchar; + } - /* Yes, it has a required argument. Is the required argument - * immediately after the command in this same argument? - */ + /* Yes, it has a required argument. Is the required argument + * immediately after the command in this same argument? + */ - if (g_optptr[1] != '\0') - { - /* Yes, return a pointer into the current argument */ + if (g_optptr[1] != '\0') + { + /* Yes, return a pointer into the current argument */ - optarg = &g_optptr[1]; - optind++; - g_optptr = NULL; - return *optchar; - } + optarg = &g_optptr[1]; + optind++; + g_optptr = NULL; + return *optchar; + } - /* No.. is the optional argument the next argument in argv[] ? */ + /* No.. is the optional argument the next argument in argv[] ? */ - if (argv[optind+1] && *argv[optind+1] != '-') - { - /* Yes.. return that */ + if (argv[optind+1] && *argv[optind+1] != '-') + { + /* Yes.. return that */ - optarg = argv[optind+1]; - optind += 2; - g_optptr = NULL; - return *optchar; - } + optarg = argv[optind+1]; + optind += 2; + g_optptr = NULL; + return *optchar; + } - /* No argument was supplied */ + /* No argument was supplied */ - g_optptr = NULL; - optarg = NULL; - optopt = *optchar; - optind++; - return noarg_ret; + g_optptr = NULL; + optarg = NULL; + optopt = *optchar; + optind++; + return noarg_ret; } /* Restore the initial, uninitialized state */ diff --git a/libc/unistd/lib_usleep.c b/libc/unistd/lib_usleep.c index 09a06feeeb..7f554b3ebc 100644 --- a/libc/unistd/lib_usleep.c +++ b/libc/unistd/lib_usleep.c @@ -114,7 +114,7 @@ * * nanosleep(), setitimer(), timer_create(), timer_delete(), timer_getoverrun(), * timer_gettime(), timer_settime(), ualarm(), sleep() - + * * Parameters: * usec - the number of microseconds to wait. * diff --git a/libc/wqueue/work_cancel.c b/libc/wqueue/work_cancel.c index 393c84359c..50d5e5239d 100644 --- a/libc/wqueue/work_cancel.c +++ b/libc/wqueue/work_cancel.c @@ -112,7 +112,7 @@ static int work_qcancel(FAR struct usr_wqueue_s *wqueue, FAR struct work_s *work DEBUGASSERT(work->dq.flink != NULL || (FAR dq_entry_t *)work == wqueue->q.tail); - DEBUGASSERT(work->dq.blink != NULL ||i + DEBUGASSERT(work->dq.blink != NULL || (FAR dq_entry_t *)work == wqueue->q.head); /* Remove the entry from the work queue and make sure that it is diff --git a/libc/wqueue/work_usrthread.c b/libc/wqueue/work_usrthread.c index d359712d83..21bd65916e 100644 --- a/libc/wqueue/work_usrthread.c +++ b/libc/wqueue/work_usrthread.c @@ -304,7 +304,7 @@ static pthread_addr_t work_usrthread(pthread_addr_t arg) { /* Loop forever */ - for (;;) + for (; ; ) { /* Then process queued work. We need to keep the work queue locked * while we process items in the work list.