1 Commits
Author SHA1 Message Date
sisungo e8928c577c fix: getprogname() is not implemented
Signed-off-by: sisungo <[email protected]>
2026-07-06 20:29:37 +08:00
2 changed files with 20 additions and 1 deletions
+18 -1
View File
@@ -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, ...) {
+2
View File
@@ -47,6 +47,7 @@
#include <string.h>
#include <unistd.h>
#define MAINFILE
#include "compat.h"
#include "grep.h"
@@ -319,6 +320,7 @@ main(int argc, char *argv[])
int c, lastc, needpattern, newarg, prevoptind;
bool matched;
initprogname(argv[0]);
setlocale(LC_ALL, "");
/*