コード例 #1
0
ファイル: HashmapCount.c プロジェクト: OpenSharp/NDceRpc
int
load_words(struct test *t)
{
	int n;
	char *word;
	int count = 1;

	while ((n = get_word(t, &word)) > 0) {
errno = 0;
		if (hashmap_put(t->words, word, (void *)count) == -1) {
			char *key = word;
			int data;

			if (errno != EEXIST) {
				AMSG("");
				return -1;
			}
			if (hashmap_remove(t->words, (void **)&key, (void **)&data) == -1) {
				AMSG("");
				return -1;
			}
			data++;
			if (hashmap_put(t->words, word, (void *)data) == -1) {
				AMSG("");
				return -1;
			}
		}
	}
	if (n == -1) {
		MMSG("");
		return -1;
	}

	return 0;
}
コード例 #2
0
ファイル: tmba.c プロジェクト: OpenSharp/NDceRpc
int
main(int argc, char *argv[])
{
	char *arg, *cfgname, *csvname;
	int ai, testnums[256], ti, num;

	setlocale(LC_CTYPE, "");

	cfgname = csvname = NULL;
	for (ai = 1; ai < argc; ai++) {
		arg = argv[ai];
		if (strcmp("-f", arg) == 0) {
			arg = argv[++ai];
			if (ai >= argc) {
				PMNF(EINVAL, ": -f requires a .cfg filename");
				goto err;
			}
			cfgname = arg;
		} else if (strcmp("-t", arg) == 0) {
			arg = argv[++ai];
			if (ai >= argc) {
				PMNF(EINVAL, ": -t requires a .csv filename");
				goto err;
			}
			csvname = arg;
		} else {
			break;
		}
	}
	if (cfgname == NULL) {
		cfgname = "tmba.cfg";
	}
	if (csvname == NULL) {
		csvname = "tmba.csv";
	}

	ti = 0;
	while (ai < argc) {
		arg = argv[ai++];
		if ((num = strtol(arg, NULL, 10)) == LONG_MIN || num == LONG_MAX) {
			PMNF(errno, ": Invalid test number: %s", arg);
			goto err;
		}
		testnums[ti++] = num;
	}

	if (run_suite(cfgname, csvname, testnums, ti) == -1) {
		AMSG("");
		goto err;
	}

	return EXIT_SUCCESS;
err:
	MMSG("usage: %s [-f <suite.cfg>] [-t <suite.csv>] [<test num> <test num> <test num> ...]\n", argv[0]);
	return EXIT_FAILURE;
}
コード例 #3
0
ファイル: spell.c プロジェクト: OpenSharp/NDceRpc
int
main(int argc, char *argv[])
{
	if (argc < 2) {
		fprintf(stderr, "usage: spell <word>\n");
		return EXIT_FAILURE;
	}

	if (lookup(argv[1]) == -1) {
		MMSG("");
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: OpenCre.c プロジェクト: nosources/httpServer
static void
run(svsem_t *sem, int n, int verbose)
{
	int i, rst;
	char buf[255];

	for (i = 0; i < n; i++) {
		sprintf(buf, "/tmp/file.%d", i);
		svsem_wait(sem);

		if (copen(buf, O_CREAT, 0600, &rst) == -1) {
			MMSG("");
		} else if (verbose) {
printf("%d %d: %d %s\n", getpid(), i, rst, buf);
		}

		usleep(100);
	}
	
}
コード例 #5
0
ファイル: tmba.c プロジェクト: OpenSharp/NDceRpc
int
run_suite(const char *cfgname, const char *csvname, int testnums[], int tlen)
{
	struct cfg *cfg;
	FILE *csv;
	unsigned char buf[4096], *row[32];
	int tnum, ti, ret, flags;

	if ((cfg = cfg_new(NULL)) == NULL ||
				cfg_load(cfg, cfgname)) {
		AMSG(": %s", cfgname);
		return -1;
	}
	if ((csv = fopen(csvname, "r")) == NULL) {
		PMNF(errno, ": %s", csvname);
		return -1;
	}

	while ((ret = csv_row_fread(csv, buf, 4096, row, 32, ',', CSV_TRIM | CSV_QUOTES)) > 0) { 
		if ((flags = strtol(row[1], NULL, 10)) == LONG_MIN || flags == LONG_MAX) {
			PMNF(errno, ": Invalid test flags: %s", row[1]);
			return -1;
		}
		if (flags == 0) {
			continue;
		}
		if ((tnum = strtol(row[0], NULL, 10)) == LONG_MIN || tnum == LONG_MAX) {
			PMNF(errno, ": Invalid test number: %s", row[0]);
			return -1;
		}
		if (tlen) {
			for (ti = 0; ti < tlen; ti++) {
				if (tnum == testnums[ti]) {
					break;
				}
			}
			if (ti == tlen) {
				continue;
			}
		}

		for (ti = 0; test_tbl[ti].test; ti++) {
			if (tnum == test_tbl[ti].num) {
				break;
			}
		}
		if (test_tbl[ti].test == NULL) {
			PMSG("Test not found: %d", tnum);
			return -1;
		}

		errno = 0;

		fprintf(stderr, "%d:%s: ", tnum, row[2]);
		fflush(stderr);
		if (test_tbl[ti].test(flags > 1 ? flags : 0, cfg, (char **)row + 4) == 0) {
			fprintf(stderr, "pass\n");
		} else {
			MMSG("%d failed", tnum);
		}
	}

	fclose(csv);
	cfg_del(cfg);

	return ret;
}
コード例 #6
0
ファイル: SvsemCounter.c プロジェクト: OpenSharp/NDceRpc
int
SvsemCounter(int verbose, struct cfg *cfg, char *args[])
{
	svsem_t sem;
	int pi, nprocs, *pids, fd, *ptr, status;
	const char *path = "/tmp/SvsemCounter.sem";

	if (svsem_open(&sem, path, O_CREAT | SEM_UNDO, 0600, 1) == -1) {
		if (errno != EEXIST) {
			perror("svsem_open");
			return EXIT_FAILURE;
		}
	}

	if ((fd = open("/tmp/SvsemCounter.shm", O_RDWR | O_CREAT, 0600)) == -1 ||
			ftruncate(fd, sizeof *ptr) == -1 ||
			(ptr = (int *)mmap(NULL, sizeof *ptr, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == NULL) {
		perror("");
		return -1;
	}
	close(fd);

	nprocs = strtoul(args[0], NULL, 10);
	count = strtoul(args[1], NULL, 10);

	if ((pids = malloc(nprocs * sizeof *pids)) == NULL) {
		perror("");
		return -1;
	}

	*ptr = 0;
	for (pi = 0; pi < nprocs; pi++) {
		pid_t pid;
		if ((pid = fork()) == -1) {
			perror("");
			return EXIT_FAILURE;
		}
		if (pid) {
			pids[pi] = pid;
		} else {
			int ret;
			ret = run();
			free(pids);
			munmap(ptr, sizeof *ptr);
			svsem_close(&sem);
			exit(ret);
		}
	}
	do {
		waitpid(pids[--pi], &status, 0);
		if ((errno = WEXITSTATUS(status))) {
			perror("");
		}
		tcase_printf(verbose, "process complete\n");
	} while (pi);

	if (*ptr != (nprocs * count)) {
		tcase_printf(verbose, "nprocs=%d,count=%d,ptr=%d\n", nprocs, count, *ptr);
		return -1;
	}

	free(pids);
	munmap(ptr, sizeof *ptr);
	if (svsem_close(&sem) != 0) {
		MMSG("");
	}

	tcase_printf(verbose, "done");

	cfg = NULL;
	return 0;
}
コード例 #7
0
ファイル: midlc.c プロジェクト: OpenSharp/NDceRpc
int
main(int argc, char *argv[])
{
	char **args;
	char *type = "jcifs";
	int verbose = 0;
	char *filename = NULL, *outname = NULL;
	char symtabpath[PATH_MAX + 1], *sp;
	struct hashmap macros;

	if (argc < 2) {
usage:
		fprintf(stderr, "usage: %s [-v|-d] [-s <symtab>] [-t jcifs|java|samba|c] [-o outfile] [-Dmacro=defn] <filename>\n", argv[0]);
		return EXIT_FAILURE;
	}

	errno = 0;

	if (hashmap_init(&macros, 0, hash_text, cmp_text, NULL, NULL) == -1) {
		MMSG("");
		return EXIT_FAILURE;
	}

	args = argv;
	args++; argc--;

	sp = symtabpath;
#ifdef _DATADIR
	sp += sprintf(sp, "%s%c", _DATADIR, SEP);
#endif
	sprintf(sp, "symtab%s.txt", type);

	while (argc) {
		if (strcmp(*args, "-v") == 0) {
			verbose++;
		} else if (strcmp(*args, "-d") == 0) {
			verbose += 2;
		} else if (strcmp(*args, "-s") == 0) {
			args++; argc--;
			if (!argc) {
				MMSG("-s requires a symtab path");
				goto usage;
			}
			strncpy(symtabpath, *args, PATH_MAX);
		} else if (strcmp(*args, "-t") == 0) {
			args++; argc--;
			if (!argc) {
				MMSG("-t requires a type");
				goto usage;
			}

			sp = symtabpath;
#ifdef _DATADIR
			sp += sprintf(sp, "%s%c", _DATADIR, SEP);
#endif
			type = *args;
			sprintf(sp, "symtab%s.txt", type);
		} else if (strncmp(*args, "-D", 2) == 0) {
			char *p, *macro, *defn = NULL;

			p = macro = (*args) + 2;

			for ( ;; p++) {
				if (*p == '\0') {
					if (p == macro) {
						macro = NULL;
					} else if (defn == NULL) {
						defn = "1";
					}
					break;
				} else if (defn == NULL && isspace(*p)) {
					MMSG("invalid macro: %s", *args);
					goto usage;
				} else if (*p == '=') {
					if (p == macro) {
						MMSG("invalid macro: %s", *args);
						goto usage;
					}
					*p = '\0';
					defn = p + 1;
				}
			}
			if (macro && hashmap_put(&macros, macro, defn) == -1) {
				MMSG("");
				return EXIT_FAILURE;
			}
		} else if (strcmp(*args, "-o") == 0) {
			args++; argc--;
			if (!argc) {
				MMSG("-o requires a filename");
				goto usage;
			}
			outname = *args;
		} else if (filename || **args == '-') {
			MMSG("Invalid argument: %s", *args);
			goto usage;
		} else {
			filename = *args;
		}
		args++; argc--;
	}
	if (!filename) {
		MMSG("A filename must be specified");
		goto usage;
	}

	if (run(argc, argv, filename, outname, type, symtabpath, &macros, verbose) == -1) {
		MMSG("");
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}