Ejemplo n.º 1
0
int rdate_main(int argc UNUSED_PARAM, char **argv)
{
	time_t remote_time;
	unsigned long flags;

	opt_complementary = "-1";
	flags = getopt32(argv, "sp");

	remote_time = askremotedate(argv[optind]);

	if ((flags & 2) == 0) {
		time_t current_time;

		time(&current_time);
		if (current_time == remote_time)
			bb_error_msg("current time matches remote time");
		else
			if (stime(&remote_time) < 0)
				bb_perror_msg_and_die("can't set time of day");
	}

	if ((flags & 1) == 0)
		printf("%s", ctime(&remote_time));

	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
int rdate_main(int argc, char **argv)
{
	time_t remote_time;
	struct tm *p;
	int opt;
	int setdate = 1;
	int printdate = 1;
	int setzone = 1;
	int zone = 0;

	/* Interpret command line args */
	while ((opt = getopt(argc, argv, "spz:")) > 0) {
		switch (opt) {
			case 's':
				printdate = 0;
				setdate = 1;
				setzone = 0;
				break;
			case 'p':
				printdate = 1;
				setdate = 0;
				setzone = 0;
				break;
			case 'z':
				printdate = 0;
				setdate = 1;
				setzone = 1;
				zone = atoi(optarg);
				break;
			default:
				bb_show_usage();
		}
	}

	if (optind == argc)
		bb_show_usage();

	remote_time = askremotedate(argv[optind]);

	if (setdate)
	{
		if(setzone)
		{
			p=localtime(&remote_time);
			p->tm_hour += zone;
			remote_time=mktime(p);
		}
		if (stime(&remote_time) < 0)
			bb_perror_msg_and_die("Could not set time of day");
	}

	if (printdate)
		printf("%s", ctime(&remote_time));

	return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
int rdate_main(int argc, char **argv)
{
	time_t remote_time;
	int opt;
	int setdate = 1;
	int printdate = 1;

	/* Interpret command line args */
	while ((opt = getopt(argc, argv, "sp")) > 0) {
		switch (opt) {
			case 's':
				printdate = 0;
				setdate = 1;
				break;
			case 'p':
				printdate = 1;
				setdate = 0;
				break;
			default:
				bb_show_usage();
		}
	}

	if (optind == argc)
		bb_show_usage();

	remote_time = askremotedate(argv[optind]);

	if (setdate) {
		time_t current_time;

		time(&current_time);
		if (current_time == remote_time)
			bb_error_msg("Current time matches remote time.");
		else
			if (stime(&remote_time) < 0)
				bb_perror_msg_and_die("Could not set time of day");
	}

	if (printdate)
		printf("%s", ctime(&remote_time));

	return EXIT_SUCCESS;
}