1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <errno.h>
6 #include <zircon/status.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <threads.h>
11 
thrd_error_string(int error)12 static const char* thrd_error_string(int error) {
13     switch (error) {
14     case thrd_success: return "thrd_success";
15     case thrd_busy: return "thrd_busy";
16     case thrd_error: return "thrd_error";
17     case thrd_nomem: return "thrd_nomem";
18     case thrd_timedout: return "thrd_timedout";
19     default: return "<unknown thrd status>";
20     }
21 }
22 
main(int argc,char ** argv)23 int main(int argc, char** argv) {
24     for (int idx = 1; idx < argc; idx++) {
25         errno = 0;
26         long error_long = strtol(argv[idx], NULL, 10);
27         if (errno)
28             exit(ZX_ERR_INVALID_ARGS);
29         int error = (int)error_long;
30         const char* zx_error = zx_status_get_string((zx_status_t)error);
31         char* posix_error = strerror(error);
32         const char* thrd_error = thrd_error_string(error);
33         printf("Int value: %d\n", error);
34         printf("\tZircon error: %s\n", zx_error);
35         printf("\tPosix error: %s\n", posix_error);
36         printf("\tC11 thread error: %s\n", thrd_error);
37     }
38 }
39