#include #include #include #include #include int main(int argc, char **argv) { char *str = NULL; size_t n = 0; openlog(NULL, LOG_PID, LOG_LOCAL0); for (int i = 0; i < argc; i++) n += strlen(*argv+i); if ((str = malloc(n + 1)) == NULL) { perror("main: malloc failed"); exit(EXIT_FAILURE); } str = "[0] "; strcpy(str, argv[0]); for (int i = 1; i < argc; i++) { char *tmp = NULL; if ((tmp = malloc(strlen(argv[i]) + 4)) == NULL) { perror("main: malloc failed"); exit(EXIT_FAILURE); } sprintf(tmp, "[%d] %s", i, argv[i]); strcat(str, tmp); free(tmp); } syslog(LOG_DEBUG, "args: %s\n", str); closelog(); free(str); return 0; }