summaryrefslogtreecommitdiffstats
path: root/common.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-04-11 13:18:33 +0000
committerRoy Marples <roy@marples.name>2007-04-11 13:18:33 +0000
commit378dcbd5d580b197dbcd4f1c2fc84bf41c28e032 (patch)
treeb981cf297a7e709266d31ffad218984870641961 /common.c
parent96ccff7a0659090f6c4121fe6892a1f37668bafa (diff)
downloaddhcpcd-378dcbd5d580b197dbcd4f1c2fc84bf41c28e032.tar.xz
Cuddle up to LKML style C
Diffstat (limited to 'common.c')
-rw-r--r--common.c85
1 files changed, 40 insertions, 45 deletions
diff --git a/common.c b/common.c
index d232de04..bbddf3cd 100644
--- a/common.c
+++ b/common.c
@@ -32,26 +32,23 @@
# if ! defined(__UCLIBC__) && ! defined (__dietlibc__)
size_t strlcpy (char *dst, const char *src, size_t size)
{
- const char *s = src;
- size_t n = size;
-
- if (n && --n)
- do
- {
- if (! (*dst++ = *src++))
- break;
- }
- while (--n);
-
- if (! n)
- {
- if (size)
- *dst = '\0';
- while (*src++)
- ;
- }
-
- return (src - s - 1);
+ const char *s = src;
+ size_t n = size;
+
+ if (n && --n)
+ do {
+ if (! (*dst++ = *src++))
+ break;
+ } while (--n);
+
+ if (! n) {
+ if (size)
+ *dst = '\0';
+ while (*src++)
+ ;
+ }
+
+ return (src - s - 1);
}
#endif
#endif
@@ -61,54 +58,52 @@ size_t strlcpy (char *dst, const char *src, size_t size)
#include <sys/sysinfo.h>
long uptime (void)
{
- struct sysinfo info;
+ struct sysinfo info;
- sysinfo (&info);
- return info.uptime;
+ sysinfo (&info);
+ return info.uptime;
}
#elif __APPLE__
/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
#include <sys/time.h>
long uptime (void)
{
- struct timeval tv;
- static long start = 0;
+ struct timeval tv;
+ static long start = 0;
- if (gettimeofday (&tv, NULL) == -1)
- {
- logger (LOG_ERR, "gettimeofday: %s", strerror (errno));
- return -1;
- }
+ if (gettimeofday (&tv, NULL) == -1) {
+ logger (LOG_ERR, "gettimeofday: %s", strerror (errno));
+ return -1;
+ }
- if (start == 0)
- start = tv.tv_sec;
+ if (start == 0)
+ start = tv.tv_sec;
- return tv.tv_sec - start;
+ return tv.tv_sec - start;
}
#else
#include <time.h>
long uptime (void)
{
- struct timespec tp;
+ struct timespec tp;
- if (clock_gettime(CLOCK_MONOTONIC, &tp) == -1)
- {
- logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
- return -1;
- }
+ if (clock_gettime(CLOCK_MONOTONIC, &tp) == -1) {
+ logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
+ return -1;
+ }
- return tp.tv_sec;
+ return tp.tv_sec;
}
#endif
void *xmalloc (size_t size)
{
- void *value = malloc (size);
+ void *value = malloc (size);
- if (value)
- return value;
+ if (value)
+ return value;
- logger (LOG_ERR, "memory exhausted");
- exit (1);
+ logger (LOG_ERR, "memory exhausted");
+ exit (1);
}