diff --git a/Makefile b/Makefile index 5b0306d..f8e4511 100644 --- a/Makefile +++ b/Makefile @@ -147,7 +147,7 @@ LIB_FILE=libgit.a LIB_H = \ blob.h cache.h commit.h count-delta.h csum-file.h delta.h \ diff.h epoch.h object.h pack.h pkt-line.h quote.h refs.h \ - run-command.h strbuf.h tag.h tree.h + run-command.h strbuf.h tag.h tree.h main.h DIFF_OBJS = \ diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \ diff --git a/cache.h b/cache.h index d776016..db5d667 100644 --- a/cache.h +++ b/cache.h @@ -45,6 +45,13 @@ #endif #endif +#if defined(__GLIBC__) +extern const char *__progname; +#define git_progname __progname +#else +extern const char *git_progname; +#endif + /* * Intensive research over the course of many years has shown that * port 9418 is totally unused by anything else. Or diff --git a/daemon.c b/daemon.c index 0c6182f..c197ee5 100644 --- a/daemon.c +++ b/daemon.c @@ -1,3 +1,4 @@ +#include "main.h" #include "cache.h" #include "pkt-line.h" #include diff --git a/main.h b/main.h new file mode 100644 index 0000000..472f134 --- /dev/null +++ b/main.h @@ -0,0 +1,22 @@ +/* unistd.h must be available and the glibc version includes features.h + * from it which #defines __GLIBC__ and friends */ +#include +#ifndef __GLIBC__ +const char *git_progname; +static int git_main(int, char **); + +int main(int argc, char **argv) +{ + char *p; + git_progname = p = *argv; + + /* don't use any library functions. We won't have the headers */ + while(*p) + if(*p++ == '/') + git_progname = p; + + return git_main(argc, argv); +} + +#define main(argc, argv) git_main(argc, argv) +#endif /* __GLIBC__ */