fix: getprogname() is not implemented
Signed-off-by: sisungo <[email protected]>
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#ifndef __DECONST
|
||||
#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
|
||||
#endif
|
||||
|
||||
#ifdef MAINFILE
|
||||
const char *PROGNAME = NULL;
|
||||
|
||||
static inline void initprogname(const char *argv0) {
|
||||
PROGNAME = "grep";
|
||||
if (argv0 && argv0[0]) {
|
||||
char *copied_argv0 = strdup(argv0);
|
||||
if (!copied_argv0) return;
|
||||
PROGNAME = basename(copied_argv0);
|
||||
}
|
||||
}
|
||||
#else
|
||||
extern const char *PROGNAME;
|
||||
#endif
|
||||
|
||||
static inline const char *getprogname() {
|
||||
return "grep";
|
||||
if (!PROGNAME) abort();
|
||||
return PROGNAME;
|
||||
}
|
||||
|
||||
static inline void warnc(int code, const char *fmt, ...) {
|
||||
|
||||
Reference in New Issue
Block a user