コード例 #1
0
ファイル: vmm_rtcdev.c プロジェクト: Florentah/xvisor-next
int vmm_rtcdev_sync_wallclock(struct vmm_rtcdev *rdev)
{
	int rc;
	struct vmm_timezone tz, utc_tz;
	struct vmm_timeval tv;
	struct vmm_rtc_time tm;

	if (!rdev) {
		return VMM_EFAIL;
	}

	if ((rc = vmm_rtcdev_get_time(rdev, &tm))) {
		return rc;
	}

	if ((rc = vmm_wallclock_get_timezone(&tz))) {
		return rc;
	}

	utc_tz.tz_minuteswest = 0;
	utc_tz.tz_dsttime = 0;

	tv.tv_sec = vmm_wallclock_mktime(tm.tm_year + 1900, 
					 tm.tm_mon + 1, 
					 tm.tm_mday, 
					 tm.tm_hour, 
					 tm.tm_min, 
					 tm.tm_sec);
	tv.tv_nsec = 0;

	if ((rc = vmm_wallclock_set_timeofday(&tv, &utc_tz))) {
		return rc;
	}

	if ((rc = vmm_wallclock_set_timezone(&tz))) {
		return rc;
	}

	return VMM_OK;
}
コード例 #2
0
static int cmd_wallclock_set_time(struct vmm_chardev *cdev, 
				  int targc, char **targv)
{
	int rc;
	char * s;
	struct vmm_timeinfo ti;
	struct vmm_timeval tv;
	struct vmm_timezone tz;

	if (targc > 4) {
		s = targv[4];
		rc = 0;
		tz.tz_minuteswest = 0;
		tz.tz_dsttime = 0;
		if (*s == '-' || *s == '+') {
			s++;
		}
		while (*s) {
			if (*s == ':') {
				rc++;
			} else if ('0' <= *s && *s <= '9') {
				switch(rc) {
				case 0:
					tz.tz_dsttime = 
					tz.tz_dsttime * 10 + (*s - '0');
					break;
				case 1:
					tz.tz_minuteswest = 
					tz.tz_minuteswest * 10 + (*s - '0');
					break;
				default:
					break;
				};
			}
			s++;
		}
		rc = 0;
		tz.tz_minuteswest += tz.tz_dsttime * 60;
		tz.tz_dsttime = 0;
		s = targv[4];
		if (*s == '-') {
			tz.tz_minuteswest *= -1;
		}

		if ((rc = vmm_wallclock_set_timezone(&tz))) {
			vmm_cprintf(cdev, "Error: set_timezone failed\n");
			return rc;
		}
	}

	s = targv[0];
	rc = 0;
	ti.tm_hour = 0;
	ti.tm_min = 0;
	ti.tm_sec = 0;
	while (*s) {
		if (*s == ':') {
			rc++;
		} else if ('0' <= *s && *s <= '9') {
			switch(rc) {
			case 0:
				ti.tm_hour = ti.tm_hour * 10 + (*s - '0');
				break;
			case 1:
				ti.tm_min = ti.tm_min * 10 + (*s - '0');
				break;
			case 2:
				ti.tm_sec = ti.tm_sec * 10 + (*s - '0');
				break;
			default:
				break;
			};
		}
		s++;
	}
	rc = 0;
	ti.tm_mday = atoi(targv[1]);
	str2lower(targv[2]);
	if (strcmp(targv[2], "jan") == 0) {
		ti.tm_mon = 0;
	} else if (strcmp(targv[2], "feb") == 0) {
		ti.tm_mon = 1;
	} else if (strcmp(targv[2], "mar") == 0) {
		ti.tm_mon = 2;
	} else if (strcmp(targv[2], "apr") == 0) {
		ti.tm_mon = 3;
	} else if (strcmp(targv[2], "may") == 0) {
		ti.tm_mon = 4;
	} else if (strcmp(targv[2], "jun") == 0) {
		ti.tm_mon = 5;
	} else if (strcmp(targv[2], "jul") == 0) {
		ti.tm_mon = 6;
	} else if (strcmp(targv[2], "aug") == 0) {
		ti.tm_mon = 7;
	} else if (strcmp(targv[2], "sep") == 0) {
		ti.tm_mon = 8;
	} else if (strcmp(targv[2], "oct") == 0) {
		ti.tm_mon = 9;
	} else if (strcmp(targv[2], "nov") == 0) {
		ti.tm_mon = 10;
	} else if (strcmp(targv[2], "dec") == 0) {
		ti.tm_mon = 11;
	} else {
		ti.tm_mon = atoi(targv[2]);
		/* Directly entered month will have range 1-12. */
		ti.tm_mon--;
	}
	ti.tm_year = atoi(targv[3]) - 1900;

	tv.tv_sec = vmm_wallclock_mktime(ti.tm_year + 1900, 
					 ti.tm_mon + 1, 
					 ti.tm_mday, 
					 ti.tm_hour, 
					 ti.tm_min, 
					 ti.tm_sec);
	tv.tv_nsec = 0;

	if ((rc = vmm_wallclock_set_local_time(&tv))) {
		vmm_cprintf(cdev, "Error: set_local_time failed\n");
		return rc;
	}

	return VMM_OK;
}