📄 msdos.c
字号:
if (t->tm_year < 80) { dos_dt.z_dtf.zt_se = 0; dos_dt.z_dtf.zt_mi = 0; dos_dt.z_dtf.zt_hr = 0; dos_dt.z_dtf.zd_dy = 1; dos_dt.z_dtf.zd_mo = 1; dos_dt.z_dtf.zd_yr = 0; } else { dos_dt.z_dtf.zt_se = t->tm_sec >> 1; dos_dt.z_dtf.zt_mi = t->tm_min; dos_dt.z_dtf.zt_hr = t->tm_hour; dos_dt.z_dtf.zd_dy = t->tm_mday; dos_dt.z_dtf.zd_mo = t->tm_mon + 1; dos_dt.z_dtf.zd_yr = t->tm_year - 80; } if (((fd = open((char *)fname, 0)) == -1) ||# ifdef __TURBOC__ (setftime(fd, &dos_dt.ft)))# else (_dos_setftime(fd, dos_dt.zft.zdate, dos_dt.zft.ztime)))# endif { if (fd != -1) close(fd); return -1; } close(fd); return 0;} /* end function stamp_file() */#endif /* TIMESTAMP */#ifndef SFX/*************************//* Function dateformat() *//*************************/int dateformat(){/*--------------------------------------------------------------------------- For those operating systems that support it, this function returns a value that tells how national convention says that numeric dates are displayed. Return values are DF_YMD, DF_DMY and DF_MDY (the meanings should be fairly obvious). ---------------------------------------------------------------------------*/#ifndef WINDLL ush CountryInfo[18];#if (!defined(__GO32__) && !defined(__EMX__)) ush far *_CountryInfo = CountryInfo; struct SREGS sregs; union REGS regs;#ifdef WATCOMC_386 ush seg, para; memset(&sregs, 0, sizeof(sregs)); memset(®s, 0, sizeof(regs)); /* PMODE/W does not support an extended version of dos function 38, */ /* so we have to use brute force, allocating real mode memory for it. */ regs.w.ax = 0x0100; regs.w.bx = 3; /* 36 bytes rounds up to 48 */ int386(0x31, ®s, ®s); /* DPMI allocate DOS memory */ if (regs.w.cflag) return DF_MDY; /* no memory, return default */ seg = regs.w.dx; para = regs.w.ax;#ifdef XXX__MK_FP_IS_BROKEN /* XXX This code may not be trustworthy in general, though it is * valid with DOS/4GW and PMODE/w, which is all we support for now. */ /* _CountryInfo = (ush far *) (para << 4); */ /* works for some extenders */ regs.w.ax = 6; regs.w.bx = seg; int386(0x31, ®s, ®s); /* convert seg to linear address */ _CountryInfo = (ush far *) (((ulg) regs.w.cx << 16) | regs.w.dx);#else _CountryInfo = (ush far *) MK_FP(seg, 0);#endif sregs.ds = para; /* real mode paragraph */ regs.w.dx = 0; /* no offset from segment */ regs.w.ax = 0x3800; int86x_realmode(0x21, ®s, ®s, &sregs); CountryInfo[0] = regs.w.cflag ? 0 : _CountryInfo[0]; regs.w.ax = 0x0101; regs.w.dx = seg; int386(0x31, ®s, ®s); /* DPMI free DOS memory */#else /* !WATCOMC_386 */ sregs.ds = FP_SEG(_CountryInfo); regs.x.dx = FP_OFF(_CountryInfo); regs.x.ax = 0x3800; intdosx(®s, ®s, &sregs);#endif /* ?WATCOMC_386 */#else /* __GO32__ || __EMX__ */ _dos_getcountryinfo(CountryInfo);#endif /* ?(__GO32__ || __EMX__) */ switch(CountryInfo[0]) { case 0: return DF_MDY; case 1: return DF_DMY; case 2: return DF_YMD; }#endif /* !WINDLL && !WATCOMC_386 */ return DF_MDY; /* default for systems without locale info */} /* end function dateformat() */#ifndef WINDLL/************************//* Function version() *//************************/void version(__G) __GDEF{ int len;#if defined(__DJGPP__) || defined(__WATCOMC__) || \ (defined(_MSC_VER) && (_MSC_VER != 800)) char buf[80];#endif len = sprintf((char *)slide, LoadFarString(CompiledWith),#if defined(__GNUC__)# if defined(__DJGPP__) (sprintf(buf, "djgpp v%d.%02d / gcc ", __DJGPP__, __DJGPP_MINOR__), buf),# elif defined(__GO32__) /* __GO32__ is defined as "1" only (sigh) */ "djgpp v1.x / gcc ",# elif defined(__EMX__) /* ...so is __EMX__ (double sigh) */ "emx+gcc ",# else "gcc ",# endif __VERSION__,#elif defined(__WATCOMC__)# if (__WATCOMC__ % 10 != 0) "Watcom C/C++", (sprintf(buf, " %d.%02d", __WATCOMC__ / 100, __WATCOMC__ % 100), buf),# else "Watcom C/C++", (sprintf(buf, " %d.%d", __WATCOMC__ / 100, (__WATCOMC__ % 100) / 10), buf),# endif#elif defined(__TURBOC__)# ifdef __BORLANDC__ "Borland C++",# if (__BORLANDC__ < 0x0200) " 1.0",# elif (__BORLANDC__ == 0x0200) /* James: __TURBOC__ = 0x0297 */ " 2.0",# elif (__BORLANDC__ == 0x0400) " 3.0",# elif (__BORLANDC__ == 0x0410) /* __BCPLUSPLUS__ = 0x0310 */ " 3.1",# elif (__BORLANDC__ == 0x0452) /* __BCPLUSPLUS__ = 0x0320 */ " 4.0 or 4.02",# elif (__BORLANDC__ == 0x0460) /* __BCPLUSPLUS__ = 0x0340 */ " 4.5",# elif (__BORLANDC__ == 0x0500) " 5.0",# else " later than 5.0",# endif# else "Turbo C",# if (__TURBOC__ > 0x0401) /* Kevin: 3.0 -> 0x0401 */ "++ later than 3.0",# elif (__TURBOC__ >= 0x0400) "++ 3.0",# elif (__TURBOC__ == 0x0295) /* [661] vfy'd by Kevin */ "++ 1.0",# elif ((__TURBOC__ >= 0x018d) && (__TURBOC__ <= 0x0200)) /* James: 0x0200 */ " 2.0",# elif (__TURBOC__ > 0x0100) " 1.5", /* James: 0x0105? */# else " 1.0", /* James: 0x0100 */# endif# endif#elif defined(MSC)# if defined(_QC) && !defined(_MSC_VER) "MS Quick C ", "2.0 or earlier", /* _QC is defined as 1 */# elif defined(_QC) && (_MSC_VER == 600) "MS Quick C ", "2.5 (MSC 6.00)",# else "Microsoft C ",# ifdef _MSC_VER# if (_MSC_VER == 800) "8.0/8.0c (Visual C++ 1.0/1.5)",# else (sprintf(buf, "%d.%02d", _MSC_VER/100, _MSC_VER%100), buf),# endif# else "5.1 or earlier",# endif# endif#else "unknown compiler", "",#endif /* ?compilers */ "MS-DOS",#if (defined(__GNUC__) || defined(WATCOMC_386)) " (32-bit)",#else# if defined(M_I86HM) || defined(__HUGE__) " (16-bit, huge)",# elif defined(M_I86LM) || defined(__LARGE__) " (16-bit, large)",# elif defined(M_I86MM) || defined(__MEDIUM__) " (16-bit, medium)",# elif defined(M_I86CM) || defined(__COMPACT__) " (16-bit, compact)",# elif defined(M_I86SM) || defined(__SMALL__) " (16-bit, small)",# elif defined(M_I86TM) || defined(__TINY__) " (16-bit, tiny)",# else " (16-bit)",# endif#endif#ifdef __DATE__ " on ", __DATE__#else "", ""#endif ); (*G.message)((zvoid *)&G, slide, (ulg)len, 0); /* MSC can't handle huge macro expansion */ /* temporary debugging code for Borland compilers only */#if (defined(__TURBOC__) && defined(DEBUG)) Info(slide, 0, ((char *)slide, "\tdebug(__TURBOC__ = 0x%04x = %d)\n", __TURBOC__, __TURBOC__));#ifdef __BORLANDC__ Info(slide, 0, ((char *)slide, "\tdebug(__BORLANDC__ = 0x%04x)\n", __BORLANDC__));#else Info(slide, 0, ((char *)slide, "\tdebug(__BORLANDC__ not defined)\n"));#endif#ifdef __TCPLUSPLUS__ Info(slide, 0, ((char *)slide, "\tdebug(__TCPLUSPLUS__ = 0x%04x)\n", __TCPLUSPLUS__));#else Info(slide, 0, ((char *)slide, "\tdebug(__TCPLUSPLUS__ not defined)\n"));#endif#ifdef __BCPLUSPLUS__ Info(slide, 0, ((char *)slide, "\tdebug(__BCPLUSPLUS__ = 0x%04x)\n\n", __BCPLUSPLUS__));#else Info(slide, 0, ((char *)slide, "\tdebug(__BCPLUSPLUS__ not defined)\n\n"));#endif#endif /* __TURBOC__ && DEBUG */} /* end function version() */#endif /* !WINDLL */#endif /* !SFX */#if (defined(__GO32__) || defined(__EMX__))#if (!defined(__DJGPP__) || (__DJGPP__ < 2) || \ ((__DJGPP__ == 2) && (__DJGPP_MINOR__ < 2)))int volatile _doserrno;#endif /* not "djgpp v2.02 or newer" */#if (!defined(__DJGPP__) || (__DJGPP__ < 2))unsigned _dos_getcountryinfo(void *countrybuffer){ asm("movl %0, %%edx": : "g" (countrybuffer)); asm("movl $0x3800, %eax"); asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"); _doserrno = 0; asm("jnc 1f"); asm("movl %%eax, %0": "=m" (_doserrno)); asm("1:"); return (unsigned)_doserrno;}unsigned _dos_setftime(int fd, ush dosdate, ush dostime){ asm("movl %0, %%ebx": : "g" (fd)); asm("movl %0, %%ecx": : "g" (dostime)); asm("movl %0, %%edx": : "g" (dosdate)); asm("movl $0x5701, %eax"); asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"); _doserrno = 0; asm("jnc 1f"); asm("movl %%eax, %0": "=m" (_doserrno)); errno = EBADF; asm("1:"); return (unsigned)_doserrno;}unsigned _dos_setfileattr(char *name, unsigned attr){#if 0 /* stripping of trailing '/' is not needed for unzip-internal use */ unsigned namlen = strlen(name); char *i_name = alloca(namlen + 1); strcpy(i_name, name); if (namlen > 1 && i_name[namlen-1] == '/' && i_name[namlen-2] != ':') i_name[namlen-1] = '\0'; asm("movl %0, %%edx": : "g" (i_name));#else asm("movl %0, %%edx": : "g" (name));#endif asm("movl %0, %%ecx": : "g" (attr)); asm("movl $0x4301, %eax"); asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"); _doserrno = 0; asm("jnc 1f"); asm("movl %%eax, %0": "=m" (_doserrno)); switch (_doserrno) { case 2: case 3: errno = ENOENT; break; case 5: errno = EACCES; break; } asm("1:"); return (unsigned)_doserrno;}void _dos_getdrive(unsigned *d){ asm("movl $0x1900, %eax"); asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"); asm("xorb %ah, %ah"); asm("incb %al"); asm("movl %%eax, %0": "=a" (*d));}unsigned _dos_creat(char *path, unsigned attr, int *fd){ asm("movl $0x3c00, %eax"); asm("movl %0, %%edx": :"g" (path)); asm("movl %0, %%ecx": :"g" (attr)); asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"); asm("movl %%eax, %0": "=a" (*fd)); _dos
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -