--- ympd-1.2.2/htdocs/mkdata.c +++ ympd-1.2.2/htdocs/mkdata.c @@ -7,7 +7,11 @@ #include #include +#if HAVE_ERROR_H #include +#else +#include +#endif #include #include @@ -53,6 +57,60 @@ return "text/plain"; } +/* + * Program name. + */ +#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME +# ifdef HAVE___PROGNAME +extern char *__progname; +# define program_invocation_short_name __progname +# else +# ifdef HAVE_GETEXECNAME +# define program_invocation_short_name \ + prog_inv_sh_nm_from_file(getexecname(), 0) +# else +# define program_invocation_short_name \ + prog_inv_sh_nm_from_file(__FILE__, 1) +# endif +static char prog_inv_sh_nm_buf[256]; +static inline char *prog_inv_sh_nm_from_file(char *f, char stripext) +{ + char *t; + + if ((t = strrchr(f, '/')) != NULL) + t++; + else + t = f; + + strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1); + prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0'; + + if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL) + *t = '\0'; + + return prog_inv_sh_nm_buf; +} +# endif +#endif + +#ifndef HAVE_ERROR_H +/* Emulate the error() function from glibc */ +__attribute__((__format__(__printf__, 3, 4))) +static void error(int status, int errnum, const char *format, ...) +{ + va_list argp; + fprintf(stderr, "%s: ", program_invocation_short_name); + va_start(argp, format); + vfprintf(stderr, format, argp); + va_end(argp); + if (errnum != 0) + fprintf(stderr, ": error code %d", errnum); + fprintf(stderr, "\n"); + if (status != 0) + exit(status); +} +#endif + int main(int argc, char *argv[]) { int i, j, buf; @@ -92,3 +150,4 @@ fputs(footer, stdout); return EXIT_SUCCESS; } +