Ejemplo n.º 1
0
void
perf_opt_parse(int argc, char **argv)
{
	int c;
	opt_t *opt;
	isc_result_t result;
	unsigned int i;

	progname = isc_file_basename(argv[0]);

	perf_opt_add('h', perf_opt_boolean, NULL, "print this help",
		     NULL, NULL);

	while ((c = getopt(argc, argv, optstr)) != -1) {
		for (i = 0; i < nopts; i++) {
			if (opts[i].c == c)
				break;
		}
		if (i == nopts) {
			perf_opt_usage();
			exit(1);
		}
		if (c == 'h') {
			perf_opt_usage();
			exit(0);
		}
		opt = &opts[i];
		result = ISC_R_SUCCESS;
		switch (opt->type) {
		case perf_opt_string:
			*opt->u.stringp = optarg;
			break;
		case perf_opt_boolean:
			*opt->u.boolp = ISC_TRUE;
			break;
		case perf_opt_uint:
			*opt->u.uintp = parse_uint(opt->desc, optarg,
						   1, 0xFFFFFFFF);
			break;
		case perf_opt_timeval:
			*opt->u.uint64p = parse_timeval(opt->desc, optarg);
			break;
		case perf_opt_double:
			*opt->u.doublep = parse_double(opt->desc, optarg);
			break;
		case perf_opt_port:
			*opt->u.portp = parse_uint(opt->desc, optarg,
						   0, 0xFFFF);
			break;
		}
	}
	if (optind != argc) {
		fprintf(stderr, "unexpected argument %s\n", argv[optind]);
		perf_opt_usage();
		exit(1);
	}
}
Ejemplo n.º 2
0
static void
setup_syslog(const char *progname) {
	int options;

	options = LOG_PID;
#ifdef LOG_NDELAY
	options |= LOG_NDELAY;
#endif
	openlog(isc_file_basename(progname), options, ISC_FACILITY);
}
Ejemplo n.º 3
0
isc_result_t
isc_file_progname(const char *filename, char *buf, size_t buflen) {
	const char *base;
	size_t len;

	REQUIRE(filename != NULL);
	REQUIRE(buf != NULL);

	base = isc_file_basename(filename);
	len = strlen(base) + 1;

	if (len > buflen)
		return (ISC_R_NOSPACE);
	memcpy(buf, base, len);

	return (ISC_R_SUCCESS);
}
Ejemplo n.º 4
0
Archivo: file.c Proyecto: 274914765/C
isc_result_t isc_file_progname (const char *filename, char *progname, size_t namelen)
{
    const char *s;

    char *p;

    size_t len;

    REQUIRE (filename != NULL);
    REQUIRE (progname != NULL);

    /*
     * Strip the path from the name
     */
    s = isc_file_basename (filename);
    if (s == NULL)
    {
        return (ISC_R_NOSPACE);
    }

    /*
     * Strip any and all suffixes
     */
    p = strchr (s, '.');
    if (p == NULL)
    {
        if (namelen <= strlen (s))
            return (ISC_R_NOSPACE);

        strcpy (progname, s);
        return (ISC_R_SUCCESS);
    }

    /*
     * Copy the result to the buffer
     */
    len = p - s;
    if (len >= namelen)
        return (ISC_R_NOSPACE);

    strncpy (progname, s, len);
    progname[len] = '\0';
    return (ISC_R_SUCCESS);
}