Skip to content

Commit

Permalink
(optional) Remove the horrid hack named case_errno_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
le-jzr committed Dec 29, 2017
1 parent e3415f8 commit 0d9b6ac
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 54 deletions.
8 changes: 0 additions & 8 deletions abi/include/_bits/errno.h
Expand Up @@ -72,12 +72,4 @@ typedef sysarg_t sys_errno_t;

#endif

/**
* Type used for casting "opaque" errno values in switches.
* When __OPAQUE_ERRNO__ is defined, `errno_t` is defined as a pointer type,
* which cannot be used in a switch directly. Instead of casting to long,
* we use an alias that can be easily mechanically replaced using tools/srepl.
*/
typedef long case_errno_t;

#endif
18 changes: 9 additions & 9 deletions kernel/generic/src/console/kconsole.c
Expand Up @@ -563,18 +563,18 @@ NO_TRACE static bool parse_int_arg(const char *text, size_t len,

uintptr_t symaddr;
errno_t rc = symtab_addr_lookup(symname, &symaddr);
switch ((case_errno_t) rc) {
case (case_errno_t) ENOENT:
switch (rc) {
case ENOENT:
printf("Symbol %s not found.\n", symname);
return false;
case (case_errno_t) EOVERFLOW:
case EOVERFLOW:
printf("Duplicate symbol %s.\n", symname);
symtab_print_search(symname);
return false;
case (case_errno_t) ENOTSUP:
case ENOTSUP:
printf("No symbol information available.\n");
return false;
case (case_errno_t) EOK:
case EOK:
if (isaddr)
*result = (sysarg_t) symaddr;
else if (isptr)
Expand All @@ -593,14 +593,14 @@ NO_TRACE static bool parse_int_arg(const char *text, size_t len,
errno_t rc = str_uint64_t(text, &end, 0, false, &value);
if (end != text + len)
rc = EINVAL;
switch ((case_errno_t) rc) {
case (case_errno_t) EINVAL:
switch (rc) {
case EINVAL:
printf("Invalid number '%s'.\n", text);
return false;
case (case_errno_t) EOVERFLOW:
case EOVERFLOW:
printf("Integer overflow in '%s'.\n", text);
return false;
case (case_errno_t) EOK:
case EOK:
*result = (sysarg_t) value;
if (isptr)
*result = *((sysarg_t *) *result);
Expand Down
6 changes: 3 additions & 3 deletions kernel/generic/src/debug/symtab.c
Expand Up @@ -97,10 +97,10 @@ const char *symtab_fmt_name_lookup(uintptr_t addr)
const char *name;
errno_t rc = symtab_name_lookup(addr, &name, NULL);

switch ((case_errno_t) rc) {
case (case_errno_t) EOK:
switch (rc) {
case EOK:
return name;
case (case_errno_t) ENOENT:
case ENOENT:
return "unknown";
default:
return "N/A";
Expand Down
6 changes: 3 additions & 3 deletions uspace/app/bdsh/cmds/builtins/cd/cd.c
Expand Up @@ -144,11 +144,11 @@ int cmd_cd(char **argv, cliuser_t *usr)
cli_set_prompt(usr);
return CMD_SUCCESS;
} else {
switch ((case_errno_t) rc) {
case (case_errno_t) ENOMEM:
switch (rc) {
case ENOMEM:
cli_error(CL_EFAIL, "Destination path too long");
break;
case (case_errno_t) ENOENT:
case ENOENT:
cli_error(CL_ENOENT, "Invalid directory `%s'", target_directory);
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions uspace/app/edit/edit.c
Expand Up @@ -588,11 +588,11 @@ static errno_t file_save(char const *fname)

rc = file_save_range(fname, &sp, &ep);

switch ((case_errno_t) rc) {
case (case_errno_t) EINVAL:
switch (rc) {
case EINVAL:
status_display("Error opening file!");
break;
case (case_errno_t) EIO:
case EIO:
status_display("Error writing data!");
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions uspace/app/init/init.c
Expand Up @@ -80,21 +80,21 @@ static void info_print(void)
static bool mount_report(const char *desc, const char *mntpt,
const char *fstype, const char *dev, errno_t rc)
{
switch ((case_errno_t) rc) {
case (case_errno_t) EOK:
switch (rc) {
case EOK:
if (dev != NULL)
printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
fstype, dev);
else
printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
break;
case (case_errno_t) EBUSY:
case EBUSY:
printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
return false;
case (case_errno_t) ELIMIT:
case ELIMIT:
printf("%s: %s limit exceeded\n", NAME, desc);
return false;
case (case_errno_t) ENOENT:
case ENOENT:
printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
return false;
default:
Expand Down
8 changes: 4 additions & 4 deletions uspace/app/tester/hw/serial/serial1.c
Expand Up @@ -62,12 +62,12 @@ const char *test_serial1(void)
if (test_argc < 1)
cnt = DEFAULT_COUNT;
else
switch ((case_errno_t) str_size_t(test_argv[0], NULL, 0, true, &cnt)) {
case (case_errno_t) EOK:
switch (str_size_t(test_argv[0], NULL, 0, true, &cnt)) {
case EOK:
break;
case (case_errno_t) EINVAL:
case EINVAL:
return "Invalid argument, unsigned integer expected";
case (case_errno_t) EOVERFLOW:
case EOVERFLOW:
return "Argument size overflow";
default:
return "Unexpected argument error";
Expand Down
6 changes: 3 additions & 3 deletions uspace/dist/src/c/demos/edit/edit.c
Expand Up @@ -587,11 +587,11 @@ static int file_save(char const *fname)

rc = file_save_range(fname, &sp, &ep);

switch ((case_errno_t) rc) {
case (case_errno_t) EINVAL:
switch (rc) {
case EINVAL:
status_display("Error opening file!");
break;
case (case_errno_t) EIO:
case EIO:
status_display("Error writing data!");
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions uspace/lib/c/generic/elf/elf_load.c
Expand Up @@ -79,11 +79,11 @@ int elf_load(int file, elf_info_t *info)
DPRINTF( "- prog dynamic: %p\n", info->finfo.dynamic);

errno_t rc2 = rtld_prog_process(&info->finfo, &env);
switch ((case_errno_t) rc2) {
case (case_errno_t) EOK:
switch (rc2) {
case EOK:
rc = EE_OK;
break;
case (case_errno_t) ENOMEM:
case ENOMEM:
rc = EE_MEMORY;
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions uspace/lib/c/generic/inet/host.c
Expand Up @@ -209,12 +209,12 @@ errno_t inet_host_plookup_one(const char *str, ip_ver_t version, inet_addr_t *ad

rc = inet_host_parse(str, &host, endptr != NULL ? &eptr : NULL);
if (rc != EOK) {
switch ((case_errno_t) rc) {
case (case_errno_t) EINVAL:
switch (rc) {
case EINVAL:
if (errmsg != NULL)
*errmsg = "Invalid format";
goto error;
case (case_errno_t) ENOMEM:
case ENOMEM:
if (errmsg != NULL)
*errmsg = "Out of memory";
goto error;
Expand Down
8 changes: 4 additions & 4 deletions uspace/lib/c/generic/inet/hostport.c
Expand Up @@ -263,16 +263,16 @@ errno_t inet_hostport_plookup_one(const char *str, ip_ver_t version, inet_ep_t *

rc = inet_hostport_parse(str, &hp, endptr != NULL ? &eptr : NULL);
if (rc != EOK) {
switch ((case_errno_t) rc) {
case (case_errno_t) EINVAL:
switch (rc) {
case EINVAL:
if (errmsg != NULL)
*errmsg = "Invalid format";
goto error;
case (case_errno_t) ENOMEM:
case ENOMEM:
if (errmsg != NULL)
*errmsg = "Out of memory";
goto error;
case (case_errno_t) EOK:
case EOK:
break;
default:
assert(false);
Expand Down
4 changes: 2 additions & 2 deletions uspace/lib/c/generic/str_error.c
Expand Up @@ -95,7 +95,7 @@ const char *str_error_name(errno_t e)
return err_name[i];
}

snprintf(noerr, NOERR_LEN, "(%d)", (int)(case_errno_t) e);
snprintf(noerr, NOERR_LEN, "(%d)", (int)e);
return noerr;
}

Expand All @@ -107,7 +107,7 @@ const char *str_error(errno_t e)
return err_desc[i];
}

snprintf(noerr, NOERR_LEN, "Unknown error code (%d)", (int)(case_errno_t) e);
snprintf(noerr, NOERR_LEN, "Unknown error code (%d)", (int)e);
return noerr;
}

Expand Down
2 changes: 1 addition & 1 deletion uspace/lib/c/include/stdlib.h
Expand Up @@ -55,7 +55,7 @@ extern void exit(int) __attribute__((noreturn));

#include <errno.h>
static inline int EXIT_RC(errno_t rc) {
return (int) (case_errno_t) rc;
return (int) rc;
}

#endif
Expand Down
6 changes: 3 additions & 3 deletions uspace/srv/devman/driver.c
Expand Up @@ -602,11 +602,11 @@ void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
async_wait_for(req, &rc);
}

switch ((case_errno_t) rc) {
case (case_errno_t) EOK:
switch (rc) {
case EOK:
dev->state = DEVICE_USABLE;
break;
case (case_errno_t) ENOENT:
case ENOENT:
dev->state = DEVICE_NOT_PRESENT;
break;
default:
Expand Down

0 comments on commit 0d9b6ac

Please sign in to comment.