Exemplo n.º 1
0
  /** 
   * unpack a array data from database
   * 
   * @param dbase database handle
   * @param data array 
   * @param len sizeof(type)*n
   * @param idx -1 for continious, [0, len-1] for idx
   * 
   * @return 
   */
int unpack_arr(struct db* dbase, void *data, int len, int idx)
{
  int code = -1;
  struct db_node *node = undump(dbase, idx);
  if (node != NULL)
  {
    memcpy(data,node->data,len);
    code = 0;
  }
  return code;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	int c;
	FILE *fp;
	int reverse = 0, forever = 0, oldfmt = 0;

	while ((c = getopt(argc, argv, "froh")) != EOF) {
		switch (c) {
		case 'r':
			reverse = 1;
			break;

		case 'f':
			forever = 1;
			break;

		case 'o':
			oldfmt = 1;
			break;

		case 'h':
			usage(0);
			break;

		default:
			usage(1);
		}
	}

	if (optind < argc) {
		fprintf(stderr, "Utmp %sdump of %s\n", reverse ? "un" : "", argv[optind]);
		if ((fp = fopen(argv[optind], "r")) == NULL) {
			perror("Unable to open file");
			exit(1);
		}
	}
	else {
		fprintf(stderr, "Utmp %sdump of stdin\n", reverse ? "un" : "");
		fp = stdin;
	}

	if (reverse)
		undump(fp, forever, oldfmt);
	else
		dump(fp, forever, oldfmt);

	fclose(fp);

	return 0;
}
Exemplo n.º 3
0
void ReadKkit::readData( const string& line )
{
	vector< string > argv;
	chopLine( line, argv ); 
	
	if ( argv[0] == "simundump" )
		undump( argv );
	else if ( argv[0] == "addmsg" )
		addmsg( argv );
	else if ( argv[0] == "call" )
		call( argv );
	else if ( argv[0] == "simobjdump" )
		objdump( argv );
	else if ( argv[0] == "xtextload" )
		textload( argv );
	else if ( argv[0] == "loadtab" )
		loadTab( argv );
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	int c;
	FILE *in = NULL, *out = NULL;
	int reverse = 0, follow = 0;
	const char *filename = NULL;

	static const struct option longopts[] = {
		{ "follow",  0, 0, 'f' },
		{ "reverse", 0, 0, 'r' },
		{ "output",  required_argument, 0, 'o' },
		{ "help",    0, 0, 'h' },
		{ "version", 0, 0, 'V' },
		{ NULL, 0, 0, 0 }
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	while ((c = getopt_long(argc, argv, "fro:hV", longopts, NULL)) != -1) {
		switch (c) {
		case 'r':
			reverse = 1;
			break;

		case 'f':
			follow = 1;
			break;

		case 'o':
			out = fopen(optarg, "w");
			if (!out)
				err(EXIT_FAILURE, _("cannot open %s"),
				    optarg);
			break;

		case 'h':
			usage(stdout);
			break;
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		default:
			usage(stderr);
		}
	}

	if (!out)
		out = stdout;

	if (optind < argc) {
		filename = argv[optind];
		in = fopen(filename, "r");
		if (!in)
			err(EXIT_FAILURE, _("cannot open %s"), filename);
	} else {
		if (follow)
			errx(EXIT_FAILURE, _("following standard input is unsupported"));
		filename = "/dev/stdin";
		in = stdin;
	}

	if (reverse) {
		fprintf(stderr, _("Utmp undump of %s\n"), filename);
		undump(in, out);
	} else {
		fprintf(stderr, _("Utmp dump of %s\n"), filename);
		in = dump(in, filename, follow, out);
	}

	if (out != stdout)
		if (close_stream(out))
			err(EXIT_FAILURE, _("write failed"));

	if (in && in != stdin)
		fclose(in);

	return EXIT_SUCCESS;
}