Rizin
unix-like reverse engineering framework and cli tools
tuklib_exit.h File Reference

Close stdout and stderr, and exit. More...

#include "tuklib_common.h"

Go to the source code of this file.

Macros

#define tuklib_exit   TUKLIB_SYMBOL(tuklib_exit)
 

Functions

void tuklib_exit (int status, int err_status, int show_error) tuklib_attr_noreturn
 

Detailed Description

Close stdout and stderr, and exit.

Note
Requires tuklib_progname and tuklib_gettext modules

Definition in file tuklib_exit.h.

Macro Definition Documentation

◆ tuklib_exit

#define tuklib_exit   TUKLIB_SYMBOL(tuklib_exit)

Definition at line 20 of file tuklib_exit.h.

Function Documentation

◆ tuklib_exit()

void tuklib_exit ( int  status,
int  err_status,
int  show_error 
)

Definition at line 25 of file tuklib_exit.c.

26 {
27  if (status != err_status) {
28  // Close stdout. If something goes wrong,
29  // print an error message to stderr.
30  const int ferror_err = ferror(stdout);
31  const int fclose_err = fclose(stdout);
32  if (ferror_err || fclose_err) {
33  status = err_status;
34 
35  // If it was fclose() that failed, we have the reason
36  // in errno. If only ferror() indicated an error,
37  // we have no idea what the reason was.
38  if (show_error)
39  fprintf(stderr, "%s: %s: %s\n", progname,
40  _("Writing to standard "
41  "output failed"),
42  fclose_err ? strerror(errno)
43  : _("Unknown error"));
44  }
45  }
46 
47  if (status != err_status) {
48  // Close stderr. If something goes wrong, there's
49  // nothing where we could print an error message.
50  // Just set the exit status.
51  const int ferror_err = ferror(stderr);
52  const int fclose_err = fclose(stderr);
53  if (fclose_err || ferror_err)
54  status = err_status;
55  }
56 
57  exit(status);
58 }
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
#define _(String)
Definition: opintl.h:53
#define progname

References _, test-lz4-list::exit, progname, and status.