Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: fusl/src/ldso/dlerror.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <dlfcn.h> 1 #include <dlfcn.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <stdarg.h> 3 #include <stdarg.h>
4 #include "pthread_impl.h" 4 #include "pthread_impl.h"
5 #include "libc.h" 5 #include "libc.h"
6 6
7 char *dlerror() 7 char* dlerror() {
8 { 8 pthread_t self = __pthread_self();
9 » pthread_t self = __pthread_self(); 9 if (!self->dlerror_flag)
10 » if (!self->dlerror_flag) return 0; 10 return 0;
11 » self->dlerror_flag = 0; 11 self->dlerror_flag = 0;
12 » char *s = self->dlerror_buf; 12 char* s = self->dlerror_buf;
13 » if (s == (void *)-1) 13 if (s == (void*)-1)
14 » » return "Dynamic linker failed to allocate memory for error messa ge"; 14 return "Dynamic linker failed to allocate memory for error message";
15 » else 15 else
16 » » return s; 16 return s;
17 } 17 }
18 18
19 void __dl_thread_cleanup(void) 19 void __dl_thread_cleanup(void) {
20 { 20 pthread_t self = __pthread_self();
21 » pthread_t self = __pthread_self(); 21 if (self->dlerror_buf != (void*)-1)
22 » if (self->dlerror_buf != (void *)-1) 22 free(self->dlerror_buf);
23 » » free(self->dlerror_buf);
24 } 23 }
25 24
26 __attribute__((__visibility__("hidden"))) 25 __attribute__((__visibility__("hidden"))) void __dl_vseterr(const char* fmt,
27 void __dl_vseterr(const char *fmt, va_list ap) 26 va_list ap) {
28 { 27 va_list ap2;
29 » va_list ap2; 28 va_copy(ap2, ap);
30 » va_copy(ap2, ap); 29 pthread_t self = __pthread_self();
31 » pthread_t self = __pthread_self(); 30 if (self->dlerror_buf != (void*)-1)
32 » if (self->dlerror_buf != (void *)-1) 31 free(self->dlerror_buf);
33 » » free(self->dlerror_buf); 32 size_t len = vsnprintf(0, 0, fmt, ap2);
34 » size_t len = vsnprintf(0, 0, fmt, ap2); 33 va_end(ap2);
35 » va_end(ap2); 34 char* buf = malloc(len + 1);
36 » char *buf = malloc(len+1); 35 if (buf) {
37 » if (buf) { 36 vsnprintf(buf, len + 1, fmt, ap);
38 » » vsnprintf(buf, len+1, fmt, ap); 37 } else {
39 » } else { 38 buf = (void*)-1;
40 » » buf = (void *)-1;» 39 }
41 » } 40 self->dlerror_buf = buf;
42 » self->dlerror_buf = buf; 41 self->dlerror_flag = 1;
43 » self->dlerror_flag = 1;
44 } 42 }
45 43
46 __attribute__((__visibility__("hidden"))) 44 __attribute__((__visibility__("hidden"))) void __dl_seterr(const char* fmt,
47 void __dl_seterr(const char *fmt, ...) 45 ...) {
48 { 46 va_list ap;
49 » va_list ap; 47 va_start(ap, fmt);
50 » va_start(ap, fmt); 48 __dl_vseterr(fmt, ap);
51 » __dl_vseterr(fmt, ap); 49 va_end(ap);
52 » va_end(ap);
53 } 50 }
54 51
55 __attribute__((__visibility__("hidden"))) 52 __attribute__((__visibility__("hidden"))) int __dl_invalid_handle(void*);
56 int __dl_invalid_handle(void *);
57 53
58 static int stub_invalid_handle(void *h) 54 static int stub_invalid_handle(void* h) {
59 { 55 __dl_seterr("Invalid library handle %p", (void*)h);
60 » __dl_seterr("Invalid library handle %p", (void *)h); 56 return 1;
61 » return 1;
62 } 57 }
63 58
64 weak_alias(stub_invalid_handle, __dl_invalid_handle); 59 weak_alias(stub_invalid_handle, __dl_invalid_handle);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698