Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/st/st.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ static void xsetenv(void);
static void xseturgency(int);
static int evcol(XEvent *);
static int evrow(XEvent *);
static void *xmalloc(size_t);
static void *xrealloc(void *, size_t);
static char *xstrdup(char *);

static void expose(XEvent *);
static void visibility(XEvent *);
Expand All @@ -200,6 +203,7 @@ static int match(uint, uint);

static void run(void);
static void usage(void);
static void die(const char *, ...);

static void (*handler[LASTEvent])(XEvent *) = {
[KeyPress] = kpress,
Expand Down Expand Up @@ -264,6 +268,46 @@ static char *opt_title = NULL;

static int oldbutton = 3; /* button event on startup: 3 = release */

void
die(const char *errstr, ...)
{
va_list ap;

va_start(ap, errstr);
vfprintf(stderr, errstr, ap);
va_end(ap);
exit(1);
}

void *
xmalloc(size_t len)
{
void *p;

if (!(p = malloc(len)))
die("malloc: %s\n", strerror(errno));

return p;
}

void *
xrealloc(void *p, size_t len)
{
if ((p = realloc(p, len)) == NULL)
die("realloc: %s\n", strerror(errno));

return p;
}

char *
xstrdup(char *s)
{
if ((s = strdup(s)) == NULL)
die("strdup: %s\n", strerror(errno));

return s;
}

void
clipcopy(const Arg *dummy)
{
Expand Down
4 changes: 4 additions & 0 deletions libst.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef unsigned char uchar;
typedef unsigned int uint;

static void execsh(char *, char **);
static void die(const char *, ...);
static void ttywriteraw(Term *term, const char *, size_t);

static void csidump(Term *);
Expand Down Expand Up @@ -135,6 +136,9 @@ static char *base64dec(const char *);
static char base64dec_getc(const char **);

static ssize_t xwrite(int, const char *, size_t);
static void *xmalloc(size_t);
static void *xrealloc(void *, size_t);
static char *xstrdup(char *);

static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
Expand Down
6 changes: 0 additions & 6 deletions libst.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ struct Term {
STREscape strescseq;
};

void die(const char *, ...);

void tprintscreen(Term *);
void tsendbreak(Term *);
void ttoggleprinter(Term *);
Expand All @@ -207,7 +205,3 @@ void ttywrite(Term *, const char *, size_t, int);
void resettitle(Term *);

size_t utf8encode(Rune, char *);

void *xmalloc(size_t);
void *xrealloc(void *, size_t);
char *xstrdup(char *);