fix: getprogname() is not implemented
Signed-off-by: sisungo <[email protected]>
This commit is contained in:
@@ -1,13 +1,30 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
#ifndef __DECONST
|
#ifndef __DECONST
|
||||||
#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
|
#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
|
||||||
#endif
|
#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() {
|
static inline const char *getprogname() {
|
||||||
return "grep";
|
if (!PROGNAME) abort();
|
||||||
|
return PROGNAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void warnc(int code, const char *fmt, ...) {
|
static inline void warnc(int code, const char *fmt, ...) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define MAINFILE
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "grep.h"
|
#include "grep.h"
|
||||||
|
|
||||||
@@ -319,6 +320,7 @@ main(int argc, char *argv[])
|
|||||||
int c, lastc, needpattern, newarg, prevoptind;
|
int c, lastc, needpattern, newarg, prevoptind;
|
||||||
bool matched;
|
bool matched;
|
||||||
|
|
||||||
|
initprogname(argv[0]);
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user