GCC Bugzilla – Attachment 49108 Details for
Bug 96739
attribute(constructor) vs format NULL check
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
less boiled down test
ioprob.c (text/x-csrc), 1.83 KB, created by
Dr. David Alan Gilbert
on 2020-08-24 09:34:39 UTC
(
hide
)
Description:
less boiled down test
Filename:
MIME Type:
Creator:
Dr. David Alan Gilbert
Created:
2020-08-24 09:34:39 UTC
Size:
1.83 KB
patch
obsolete
>#include <stdio.h> >#include <stdlib.h> >#include <string.h> > >typedef struct Error Error; >typedef struct QemuOpts QemuOpts; >typedef int (*cfunc_t)(int argc, char **argv); >typedef void (*helpfunc_t)(void); >typedef struct cmdinfo { > const char *name; > const char *altname; > cfunc_t cfunc; > int flags; > const char *args; > const char *oneline; > void (*help)(void); > unsigned long perm; >} cmdinfo_t; >; >static cmdinfo_t *cmdtab; >static int ncmds; >void qemuio_add_command(const cmdinfo_t *ci) { > ++ncmds; > cmdtab = reallocarray(cmdtab, ncmds, sizeof(cmdinfo_t)); > cmdtab[ncmds - 1] = *ci; >} > >static const cmdinfo_t *find_command(const char *cmd) >{ > cmdinfo_t *ct; > > for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) { > if (strcmp(ct->name, cmd) == 0 || > (ct->altname && strcmp(ct->altname, cmd) == 0)) > { > return (const cmdinfo_t *)ct; > } > } > return NULL; >} > >static void help_oneline(const char *cmd, const cmdinfo_t *ct) { > if (cmd) { > printf("%s ", cmd); > } else { > printf("%s ", ct->name); > } >} > >static void help_onecmd(const char *cmd, const cmdinfo_t *ct) >{ > help_oneline(cmd, ct); > if (ct->help) { > ct->help(); > } >} > >static void help_all(void) { > const cmdinfo_t *ct; > for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) { > help_oneline(ct->name, ct); > } >} >static int help_f(int argc, char **argv) { > const cmdinfo_t *ct; > > if (argc == 1) { > help_all(); > return 0; > } > > ct = find_command(argv[1]); > if (ct == NULL) { > printf("command %s not found\n", argv[1]); > return -1; > } > > help_onecmd(argv[1], ct); > > return 0; >} >static const cmdinfo_t help_cmd = { > .name = "", > .altname = "", > .cfunc = help_f, > .args = "", > .oneline = "", >}; >static void __attribute((constructor)) init_qemuio_commands(void) { > qemuio_add_command(&help_cmd); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 96739
:
49096
| 49108