summaryrefslogtreecommitdiff
path: root/libgcompat
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-14 18:28:35 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-14 18:28:35 -0600
commitd40369b0e09e4e2228ebff305067ec2d99220848 (patch)
tree0839bc088f3f0b577e0badddab745fa9f3c94dd4 /libgcompat
parent28748009c0dc553e2fe5e6253e7615cf89d2b7ef (diff)
downloadgcompat-d40369b0e09e4e2228ebff305067ec2d99220848.tar.gz
gcompat-d40369b0e09e4e2228ebff305067ec2d99220848.tar.bz2
gcompat-d40369b0e09e4e2228ebff305067ec2d99220848.tar.xz
gcompat-d40369b0e09e4e2228ebff305067ec2d99220848.zip
global: Format the code consistently
* Apply clang-format. * Change all comments to the same style. * Add braces as dictated by the coding style guidelines. Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'libgcompat')
-rw-r--r--libgcompat/backtrace.c25
-rw-r--r--libgcompat/dlmopen.c15
-rw-r--r--libgcompat/dlvsym.c11
-rw-r--r--libgcompat/gnulib.c2
-rw-r--r--libgcompat/malloc.c44
-rw-r--r--libgcompat/math.c2
-rw-r--r--libgcompat/pthread.c16
-rw-r--r--libgcompat/pwd.c30
-rw-r--r--libgcompat/resolv.c13
-rw-r--r--libgcompat/resource.c15
-rw-r--r--libgcompat/stdio.c31
-rw-r--r--libgcompat/stdlib.c4
-rw-r--r--libgcompat/string.c25
-rw-r--r--libgcompat/sysctl.c22
-rw-r--r--libgcompat/ucontext.c2
-rw-r--r--libgcompat/version.c6
16 files changed, 141 insertions, 122 deletions
diff --git a/libgcompat/backtrace.c b/libgcompat/backtrace.c
index 4ef0f88..c8ded8b 100644
--- a/libgcompat/backtrace.c
+++ b/libgcompat/backtrace.c
@@ -2,9 +2,16 @@
#include <stddef.h>
#include <stdlib.h>
-#define _frame_level(addr_buf, curr, frame, size) \
- if(__builtin_frame_address(frame) != NULL && (curr = __builtin_return_address(frame)) > 0x1000 && frame <= size) addr_buf[frame] = curr; \
- else return size;
+#define _frame_level(addr_buf, curr, frame, size) \
+ do { \
+ if (__builtin_frame_address(frame) != NULL \
+ && (curr = __builtin_return_address(frame)) > 0x1000 \
+ && frame <= size) { \
+ addr_buf[frame] = curr; \
+ } else { \
+ return size; \
+ } \
+ } while (0)
int backtrace(void **addr_buf, int size)
{
@@ -22,18 +29,18 @@ int backtrace(void **addr_buf, int size)
return 9;
}
-char **backtrace_symbols(void * const *addr_buf, int size)
+char **backtrace_symbols(void *const *addr_buf, int size)
{
char **result = calloc(sizeof(char *), size);
- if(result == NULL) return result;
+ if (result == NULL) {
+ return result;
+ }
- for(int next = 0; next < size; next++)
- {
+ for (int next = 0; next < size; next++) {
Dl_info info;
int err = dladdr(addr_buf[next], &info);
- if(err != 0)
- {
+ if (err != 0) {
result[next] = "??:0";
} else {
result[next] = info.dli_sname;
diff --git a/libgcompat/dlmopen.c b/libgcompat/dlmopen.c
index fecb29c..4584680 100644
--- a/libgcompat/dlmopen.c
+++ b/libgcompat/dlmopen.c
@@ -1,15 +1,14 @@
-#include <dlfcn.h> // dlopen
-#include <stdio.h> // fprintf
-#include <stdlib.h> // getenv
+#include <dlfcn.h> /* dlopen */
+#include <stdio.h> /* fprintf */
+#include <stdlib.h> /* getenv */
void *dlmopen(long lmid, const char *pathname, int mode)
{
- if(getenv("GLIBC_FAKE_DEBUG"))
- {
- fprintf(stderr, "library %s was requested to load in %ld namespace",
- pathname, lmid);
+ if (getenv("GLIBC_FAKE_DEBUG")) {
+ fprintf(stderr,
+ "library %s was requested to load in %ld namespace",
+ pathname, lmid);
}
return dlopen(pathname, mode);
}
-
diff --git a/libgcompat/dlvsym.c b/libgcompat/dlvsym.c
index 3d744ea..0aba245 100644
--- a/libgcompat/dlvsym.c
+++ b/libgcompat/dlvsym.c
@@ -1,13 +1,12 @@
-#include <dlfcn.h> // dlsym
-#include <stdio.h> // fprintf
-#include <stdlib.h> // getenv
+#include <dlfcn.h> /* dlsym */
+#include <stdio.h> /* fprintf */
+#include <stdlib.h> /* getenv */
void *dlvsym(void *handle, char *symbol, char *version)
{
- if(getenv("GLIBC_FAKE_DEBUG"))
- {
+ if (getenv("GLIBC_FAKE_DEBUG")) {
fprintf(stderr, "symbol %s with version %s is being redirected",
- symbol, version);
+ symbol, version);
}
return dlsym(handle, symbol);
diff --git a/libgcompat/gnulib.c b/libgcompat/gnulib.c
index 08544fc..e0ee953 100644
--- a/libgcompat/gnulib.c
+++ b/libgcompat/gnulib.c
@@ -4,5 +4,5 @@
unsigned long __fdelt_chk(unsigned long size)
{
assert(size < FD_SETSIZE);
- return size / (sizeof(unsigned long)<<3);
+ return size / (sizeof(unsigned long) << 3);
}
diff --git a/libgcompat/malloc.c b/libgcompat/malloc.c
index 7478834..db85d8d 100644
--- a/libgcompat/malloc.c
+++ b/libgcompat/malloc.c
@@ -1,16 +1,16 @@
/* struct mallinfo pulled from mallinfo.3:
*
* Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
- *
+ *
* Permission is granted to make and distribute verbatim copies of this
* manual provided the copyright notice and this permission notice are
* preserved on all copies.
- *
+ *
* Permission is granted to copy and distribute modified versions of this
* manual under the conditions for verbatim copying, provided that the
* entire resulting derived work is distributed under the terms of a
* permission notice identical to this one.
- *
+ *
* Since the Linux kernel and libraries are constantly changing, this
* manual page may be incorrect or out-of-date. The author(s) assume no
* responsibility for errors or omissions, or for damages resulting from
@@ -18,26 +18,26 @@
* have taken the same level of care in the production of this manual,
* which is licensed free of charge, as they might when working
* professionally.
- *
+ *
* Formatted or processed versions of this manual, if unaccompanied by
* the source, must acknowledge the copyright and authors of this work.
*/
-#include <string.h> /* memset */
-#include <stdlib.h> /* {m,c,re}alloc, free */
-#include <malloc.h> /* memalign */
+#include <malloc.h> /* memalign */
+#include <stdlib.h> /* {m,c,re}alloc, free */
+#include <string.h> /* memset */
struct mallinfo {
- int arena; /* Non-mmapped space allocated (bytes) */
- int ordblks; /* Number of free chunks */
- int smblks; /* Number of free fastbin blocks */
- int hblks; /* Number of mmapped regions */
- int hblkhd; /* Space allocated in mmapped regions (bytes) */
- int usmblks; /* Maximum total allocated space (bytes) */
- int fsmblks; /* Space in freed fastbin blocks (bytes) */
- int uordblks; /* Total allocated space (bytes) */
- int fordblks; /* Total free space (bytes) */
- int keepcost; /* Top-most, releasable space (bytes) */
+ int arena; /* Non-mmapped space allocated (bytes) */
+ int ordblks; /* Number of free chunks */
+ int smblks; /* Number of free fastbin blocks */
+ int hblks; /* Number of mmapped regions */
+ int hblkhd; /* Space allocated in mmapped regions (bytes) */
+ int usmblks; /* Maximum total allocated space (bytes) */
+ int fsmblks; /* Space in freed fastbin blocks (bytes) */
+ int uordblks; /* Total allocated space (bytes) */
+ int fordblks; /* Total free space (bytes) */
+ int keepcost; /* Top-most, releasable space (bytes) */
};
struct mallinfo mallinfo(void)
@@ -72,8 +72,10 @@ void *__libc_memalign(size_t align, size_t len)
return memalign(align, len);
}
-extern __typeof(__libc_malloc) __malloc __attribute__((weak, alias("__libc_malloc")));
-extern __typeof(__libc_calloc) __calloc __attribute__((weak, alias("__libc_calloc")));
-extern __typeof(__libc_realloc) __realloc __attribute__((weak, alias("__libc_realloc")));
+extern __typeof(__libc_malloc) __malloc
+ __attribute__((weak, alias("__libc_malloc")));
+extern __typeof(__libc_calloc) __calloc
+ __attribute__((weak, alias("__libc_calloc")));
+extern __typeof(__libc_realloc) __realloc
+ __attribute__((weak, alias("__libc_realloc")));
extern __typeof(__libc_free) __free __attribute__((weak, alias("__libc_free")));
-
diff --git a/libgcompat/math.c b/libgcompat/math.c
index 2c793e4..42ed032 100644
--- a/libgcompat/math.c
+++ b/libgcompat/math.c
@@ -1,4 +1,4 @@
-#include <math.h> // isinf, isnan
+#include <math.h> /* isinf, isnan */
int __isinff(float number)
{
diff --git a/libgcompat/pthread.c b/libgcompat/pthread.c
index ddfc570..52daceb 100644
--- a/libgcompat/pthread.c
+++ b/libgcompat/pthread.c
@@ -1,15 +1,19 @@
#include <pthread.h>
-int __register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) {
+int __register_atfork(void (*prepare)(void), void (*parent)(void),
+ void (*child)(void))
+{
return pthread_atfork(prepare, parent, child);
}
-int register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) __attribute__ ((weak, alias("__register_atfork")));
+int register_atfork(void (*prepare)(void), void (*parent)(void),
+ void (*child)(void))
+ __attribute__((weak, alias("__register_atfork")));
-
-void __pthread_register_cancel(void *buf) {
+void __pthread_register_cancel(void *buf)
+{
}
-
-void __pthread_unregister_cancel(void *buf) {
+void __pthread_unregister_cancel(void *buf)
+{
}
diff --git a/libgcompat/pwd.c b/libgcompat/pwd.c
index 2e09aea..50d8da0 100644
--- a/libgcompat/pwd.c
+++ b/libgcompat/pwd.c
@@ -1,23 +1,27 @@
/* some musl versions incorrectly mark fgetpwent() as a GNU extension */
#define _GNU_SOURCE
-#include <stdio.h>
#include <errno.h>
#include <pwd.h>
+#include <stdio.h>
#include <string.h>
-
-int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) {
+int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen,
+ struct passwd **pwbufp)
+{
struct passwd *pwd;
- if (pwbufp == NULL || pwbuf == NULL)
+ if (pwbufp == NULL || pwbuf == NULL) {
return ERANGE;
+ }
- if (buflen < 1)
+ if (buflen < 1) {
return ERANGE;
+ }
- if (buf != NULL)
+ if (buf != NULL) {
*buf = '\0';
+ }
if ((pwd = getpwent()) == NULL) {
*pwbufp = NULL;
@@ -30,18 +34,22 @@ int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **p
return 0;
}
-
-int fgetpwent_r(FILE *filp, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) {
+int fgetpwent_r(FILE *filp, struct passwd *pwbuf, char *buf, size_t buflen,
+ struct passwd **pwbufp)
+{
struct passwd *pwd;
- if (pwbufp == NULL || pwbuf == NULL)
+ if (pwbufp == NULL || pwbuf == NULL) {
return ERANGE;
+ }
- if (buflen < 1)
+ if (buflen < 1) {
return ERANGE;
+ }
- if (buf != NULL)
+ if (buf != NULL) {
*buf = '\0';
+ }
if ((pwd = fgetpwent(filp)) == NULL) {
*pwbufp = NULL;
diff --git a/libgcompat/resolv.c b/libgcompat/resolv.c
index 9ded8c9..3566dcd 100644
--- a/libgcompat/resolv.c
+++ b/libgcompat/resolv.c
@@ -6,8 +6,8 @@
* Note: res_init() is actually deprecated according to
* http://docs.oracle.com/cd/E36784_01/html/E36875/res-nclose-3resolv.html
**************************************************************************/
-#include <string.h> /* memcpy, memset */
-#include <resolv.h> /* res_state */
+#include <resolv.h> /* res_state */
+#include <string.h> /* memcpy, memset */
static inline int res_ninit(res_state statp)
{
@@ -20,13 +20,16 @@ static inline int res_ninit(res_state statp)
static inline int res_nclose(res_state statp)
{
- if (!statp)
+ if (!statp) {
return -1;
+ }
if (statp != &_res) {
memset(statp, 0, sizeof(*statp));
}
return 0;
}
-extern __typeof(res_ninit) __res_ninit __attribute__((weak, alias("res_ninit")));
-extern __typeof(res_nclose) __res_nclose __attribute__((weak, alias("res_nclose")));
+extern __typeof(res_ninit) __res_ninit
+ __attribute__((weak, alias("res_ninit")));
+extern __typeof(res_nclose) __res_nclose
+ __attribute__((weak, alias("res_nclose")));
diff --git a/libgcompat/resource.c b/libgcompat/resource.c
index 029b31e..4a7ab4e 100644
--- a/libgcompat/resource.c
+++ b/libgcompat/resource.c
@@ -1,8 +1,8 @@
-#include <sys/resource.h> /* setrlimit, struct rlimit */
-#include <assert.h> /* assert */
-#include <dlfcn.h> /* dlsym, RTLD_NEXT */
-#include <stdlib.h> /* NULL */
-#include <string.h> /* memcpy */
+#include <assert.h> /* assert */
+#include <dlfcn.h> /* dlsym, RTLD_NEXT */
+#include <stdlib.h> /* NULL */
+#include <string.h> /* memcpy */
+#include <sys/resource.h> /* setrlimit, struct rlimit */
/* Sigh.
* Valve compiled Steam against the glibc2.2 version of setrlimit.
@@ -11,7 +11,7 @@
* So, what you have to do is: if you want to run steam with this gcompat,
* ensure you compile *without* defining NO_BROKEN_SHADOW_SETRLIMIT.
* If you do *not* want to run steam with this gcompat, define it.
- *
+ *
* The only problem with enabling this all the time is that if a binary
* really does need a ulimit to be 0 for any reason (such as coredumps), it
* very obviously won't work here.
@@ -27,8 +27,7 @@ int setrlimit(int resource, const struct rlimit *rlim)
memcpy(&my_rlim, rlim, sizeof(struct rlimit));
- if(my_rlim.rlim_cur == 0)
- {
+ if (my_rlim.rlim_cur == 0) {
my_rlim.rlim_cur = my_rlim.rlim_max;
}
diff --git a/libgcompat/stdio.c b/libgcompat/stdio.c
index 89bd677..a44d94c 100644
--- a/libgcompat/stdio.c
+++ b/libgcompat/stdio.c
@@ -15,8 +15,7 @@ int __printf_chk(int flag, const char *format, ...)
va_list argp;
int result;
- if(flag > 0)
- {
+ if (flag > 0) {
assert(format != NULL);
}
@@ -32,8 +31,7 @@ int __fprintf_chk(FILE *stream, int flag, const char *format, ...)
va_list argp;
int result;
- if(flag > 0)
- {
+ if (flag > 0) {
assert(stream != NULL);
assert(format != NULL);
}
@@ -59,13 +57,13 @@ int __sprintf_chk(char *str, int flag, size_t strlen, const char *format, ...)
return result;
}
-int __snprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *format, ...)
+int __snprintf_chk(char *str, size_t size, int flag, size_t strlen,
+ const char *format, ...)
{
va_list argp;
int result;
- if(flag > 0)
- {
+ if (flag > 0) {
assert(format != NULL);
}
// must always be done per LFS
@@ -78,13 +76,13 @@ int __snprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *
return result;
}
-int __swprintf_chk(wchar_t *wcs, size_t maxlen, int flag, size_t wcslen, const wchar_t *format, ...)
+int __swprintf_chk(wchar_t *wcs, size_t maxlen, int flag, size_t wcslen,
+ const wchar_t *format, ...)
{
va_list argp;
int result;
- if(flag > 0)
- {
+ if (flag > 0) {
assert(format != NULL);
}
// must always be done per LFS
@@ -99,8 +97,7 @@ int __swprintf_chk(wchar_t *wcs, size_t maxlen, int flag, size_t wcslen, const w
int __vasprintf_chk(char **strp, int flag, const char *fmt, va_list ap)
{
- if(flag > 0)
- {
+ if (flag > 0) {
assert(strp != NULL);
assert(fmt != NULL);
}
@@ -109,22 +106,20 @@ int __vasprintf_chk(char **strp, int flag, const char *fmt, va_list ap)
int __vfprintf_chk(FILE *stream, int flag, const char *format, va_list ap)
{
- if(flag > 0)
- {
+ if (flag > 0) {
assert(stream != NULL);
assert(format != NULL);
}
return vfprintf(stream, format, ap);
}
-int __vsnprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *format, va_list ap)
+int __vsnprintf_chk(char *str, size_t size, int flag, size_t strlen,
+ const char *format, va_list ap)
{
- if(flag > 0)
- {
+ if (flag > 0) {
assert(format != NULL);
}
// must always be done per LFS
assert(size <= strlen);
return vsnprintf(str, size, format, ap);
}
-
diff --git a/libgcompat/stdlib.c b/libgcompat/stdlib.c
index 30c904e..6783615 100644
--- a/libgcompat/stdlib.c
+++ b/libgcompat/stdlib.c
@@ -1,5 +1,5 @@
-#include <assert.h> // assert
-#include <stdlib.h> // strtod
+#include <assert.h> /* assert */
+#include <stdlib.h> /* strtod */
char *__realpath_chk(const char *path, char *resolved_path)
{
diff --git a/libgcompat/string.c b/libgcompat/string.c
index 9045d5d..60f61fc 100644
--- a/libgcompat/string.c
+++ b/libgcompat/string.c
@@ -1,6 +1,6 @@
-#include <assert.h> /* assert */
-#include <string.h> /* memcpy, strcpy, strncat, strndup */
-#include <stdlib.h> /* strto[u?]ll */
+#include <assert.h> /* assert */
+#include <stdlib.h> /* strto[u?]ll */
+#include <string.h> /* memcpy, strcpy, strncat, strndup */
/* "Checked" memcpy */
void *__memcpy_chk(void *dest, const void *src, size_t len, size_t destlen)
@@ -8,8 +8,7 @@ void *__memcpy_chk(void *dest, const void *src, size_t len, size_t destlen)
assert(dest != NULL);
assert(src != NULL);
assert(len <= destlen);
- if(src < dest)
- {
+ if (src < dest) {
assert(!(src + len >= dest));
} else {
assert(!(dest + len >= src));
@@ -64,12 +63,14 @@ char *__strndup(const char *str, size_t count)
void *rawmemchr(const void *s, int c)
{
const unsigned char *haystack = s;
- unsigned char needle = (unsigned char)c;
- while(*haystack++ != needle);
- return (void *)haystack;
+ unsigned char needle = (unsigned char) c;
+ while (*haystack++ != needle)
+ ;
+ return (void *) haystack;
}
-extern __typeof(rawmemchr) __rawmemchr __attribute__((weak, alias("rawmemchr")));
+extern __typeof(rawmemchr) __rawmemchr
+ __attribute__((weak, alias("rawmemchr")));
/* Another useless __ alias */
char *__strtok_r(char *str, const char *delim, char **saveptr)
@@ -85,12 +86,14 @@ char *__strsep_g(char **stringp, const char *delim)
}
/* Some day, when musl supports LC_NUMERIC, we can probably remove these */
-long long int strtoll_l(const char *nptr, char **endptr, int base, locale_t locale)
+long long int strtoll_l(const char *nptr, char **endptr, int base,
+ locale_t locale)
{
return strtoll(nptr, endptr, base);
}
-unsigned long long int strtoull_l(const char *nptr, char **endptr, int base, locale_t locale)
+unsigned long long int strtoull_l(const char *nptr, char **endptr, int base,
+ locale_t locale)
{
return strtoull(nptr, endptr, base);
}
diff --git a/libgcompat/sysctl.c b/libgcompat/sysctl.c
index a14c2b8..e7218c1 100644
--- a/libgcompat/sysctl.c
+++ b/libgcompat/sysctl.c
@@ -1,6 +1,5 @@
-#include <unistd.h> /* size_t */
#include <sys/syscall.h>
-
+#include <unistd.h> /* size_t */
#ifdef SYS__sysctl
@@ -13,16 +12,15 @@ struct __sysctl_args {
size_t newlen;
};
-
-int sysctl (int *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen) {
- struct __sysctl_args args = {
- .name = name,
- .nlen = nlen,
- .oldval = oldval,
- .oldlenp = oldlenp,
- .newval = newval,
- .newlen = newlen
- };
+int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp, void *newval,
+ size_t newlen)
+{
+ struct __sysctl_args args = { .name = name,
+ .nlen = nlen,
+ .oldval = oldval,
+ .oldlenp = oldlenp,
+ .newval = newval,
+ .newlen = newlen };
return syscall(SYS__sysctl, &args);
}
diff --git a/libgcompat/ucontext.c b/libgcompat/ucontext.c
index 2d6006e..4827263 100644
--- a/libgcompat/ucontext.c
+++ b/libgcompat/ucontext.c
@@ -1,4 +1,4 @@
-#include <errno.h> /* errno, ENOSYS */
+#include <errno.h> /* errno, ENOSYS */
int getcontext(void *ucp)
{
diff --git a/libgcompat/version.c b/libgcompat/version.c
index 63146f8..99c2c8c 100644
--- a/libgcompat/version.c
+++ b/libgcompat/version.c
@@ -1,9 +1,11 @@
-#include <stdlib.h> // getenv
+#include <stdlib.h> /* getenv */
const char *gnu_get_libc_version(void)
{
char *ver = getenv("GLIBC_FAKE_VERSION");
- if(ver == NULL) ver = "2.8";
+ if (ver == NULL) {
+ ver = "2.8";
+ }
return ver;
}