⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asctime.c

📁 minux的源代码,一个非常小的操作系统
💻 C
字号:
/*
 * asctime - print a date
 */
/* $Header: asctime.c,v 1.3 91/04/22 13:20:15 ceriel Exp $ */

#include	<string.h>
#include	<time.h>
#include	"loc_time.h"

#define	DATE_STR	"??? ??? ?? ??:??:?? ????\n"

static char *
two_digits(register char *pb, int i, int nospace)
{
	*pb = (i / 10) % 10 + '0';
	if (!nospace && *pb == '0') *pb = ' ';
	pb++;
	*pb++ = (i % 10) + '0';
	return ++pb;
}

static char *
four_digits(register char *pb, int i)
{
	i %= 10000;
	*pb++ = (i / 1000) + '0';
	i %= 1000;
	*pb++ = (i / 100) + '0';
	i %= 100;
	*pb++ = (i / 10) + '0';
	*pb++ = (i % 10) + '0';
	return ++pb;
}

char *asctime(const struct tm *timeptr)
{
	static char buf[26];
	register char *pb = buf;
	register const char *ps;
	register int n;

	strcpy(pb, DATE_STR);
	ps = _days[timeptr->tm_wday];
	n = ABB_LEN;
	while(--n >= 0) *pb++ = *ps++;
	pb++;
	ps = _months[timeptr->tm_mon];
	n = ABB_LEN;
	while(--n >= 0) *pb++ = *ps++;
	pb++;
	pb = two_digits(
		    two_digits(
			    two_digits(two_digits(pb, timeptr->tm_mday, 0)
					, timeptr->tm_hour, 1)
			    , timeptr->tm_min, 1)
		    , timeptr->tm_sec, 1);

	four_digits(pb, timeptr->tm_year + 1900);
	return buf;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -