Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/err.c
Show All 34 Lines | |||||
#include "namespace.h" | #include "namespace.h" | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "block_abi.h" | |||||
#include "un-namespace.h" | #include "un-namespace.h" | ||||
#include "libc_private.h" | #include "libc_private.h" | ||||
static FILE *err_file; /* file to use for error output */ | static FILE *err_file; /* file to use for error output */ | ||||
static void (*err_exit)(int); | static void (*err_exit)(int); | ||||
typedef DECLARE_BLOCK(void, err_exit_block_t, int); | |||||
/* | /* | ||||
* This is declared to take a `void *' so that the caller is not required | * This is declared to take a `void *' so that the caller is not required | ||||
* to include <stdio.h> first. However, it is really a `FILE *', and the | * to include <stdio.h> first. However, it is really a `FILE *', and the | ||||
* manual page documents it as such. | * manual page documents it as such. | ||||
*/ | */ | ||||
void | void | ||||
err_set_file(void *fp) | err_set_file(void *fp) | ||||
{ | { | ||||
if (fp) | if (fp) | ||||
err_file = fp; | err_file = fp; | ||||
else | else | ||||
err_file = stderr; | err_file = stderr; | ||||
} | } | ||||
void | void | ||||
err_set_exit(void (*ef)(int)) | err_set_exit(void (*ef)(int)) | ||||
{ | { | ||||
err_exit = ef; | err_exit = ef; | ||||
} | |||||
/* | |||||
* Register a block to be executed at error exit. | |||||
*/ | |||||
void | |||||
err_set_exit_b(err_exit_block_t block) | |||||
{ | |||||
if (_Block_copy != 0) | |||||
err_exit = (void(*)(int))GET_BLOCK_FUNCTION(_Block_copy(block)); | |||||
theraven: This doesn't look right. Will it pass the block as the argument when err_exit is called? If… | |||||
} | } | ||||
__weak_reference(_err, err); | __weak_reference(_err, err); | ||||
void | void | ||||
_err(int eval, const char *fmt, ...) | _err(int eval, const char *fmt, ...) | ||||
{ | { | ||||
va_list ap; | va_list ap; | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |
This doesn't look right. Will it pass the block as the argument when err_exit is called? If not, then bound variables in the block will be undefined values.