📄 msdos.c
字号:
setftime(fileno(outfile), &td.ft);
#else
_dos_setftime(fileno(outfile), lrec.last_mod_file_date,
lrec.last_mod_file_time);
#endif
/*---------------------------------------------------------------------------
And finally we can close the file...at least everybody agrees on how to
do *this*. I think... Also change the mode according to the stored file
attributes, since we didn't do that when we opened the dude.
---------------------------------------------------------------------------*/
fclose(outfile);
#ifdef __TURBOC__
# if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0452))
# define Chmod _rtl_chmod
# else
# define Chmod _chmod
# endif
if (Chmod(filename, 1, pInfo->file_attr) != pInfo->file_attr)
FPRINTF(stderr, "\nwarning: file attributes may not be correct\n");
#else /* !__TURBOC__ */
_dos_setfileattr(filename, pInfo->file_attr);
#endif /* ?__TURBOC__ */
} /* end function close_outfile() */
#ifndef SFX
/*************************/
/* Function dateformat() */
/*************************/
int dateformat()
{
/*---------------------------------------------------------------------------
For those operating systems which support it, this function returns a
value which 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 MSWIN
#if (!defined(__GO32__) && !defined(__EMX__))
unsigned short _CountryInfo[18];
unsigned short far *CountryInfo = _CountryInfo;
struct SREGS sregs;
union REGS regs;
sregs.ds = FP_SEG(CountryInfo);
regs.x.dx = FP_OFF(CountryInfo);
regs.x.ax = 0x3800;
int86x(0x21, ®s, ®s, &sregs);
#else /* __GO32__ || __EMX__ */
unsigned short CountryInfo[18];
_dos_getcountryinfo(CountryInfo);
#endif
switch(CountryInfo[0]) {
case 0:
return DF_MDY;
case 1:
return DF_DMY;
case 2:
return DF_YMD;
}
#endif /* !MSWIN */
return DF_MDY; /* default for systems without locale info */
} /* end function dateformat() */
/************************/
/* Function version() */
/************************/
void version()
{
extern char Far CompiledWith[];
#if defined(__WATCOMC__) || defined(__TURBOC__) || defined(_MSC_VER)
char buf[80];
#endif
PRINTF(LoadFarString(CompiledWith),
#ifdef __GNUC__
# ifdef __EMX__ /* __EMX__ is defined as "1" only (sigh) */
"emx+gcc ",
# else
# ifdef __GO32__ /* ...so is __GO32__ (double sigh) */
"djgpp gcc ",
# else
"gcc ",
# endif
# endif
__VERSION__,
#else
#ifdef __WATCOMC__
"Watcom C", (sprintf(buf, " (__WATCOMC__ = %d)", __WATCOMC__), buf),
#else
#ifdef __TURBOC__
# ifdef __BORLANDC__
"Borland C++",
# if (__BORLANDC__ < 0x0200)
" 1.0",
# else
# if (__BORLANDC__ == 0x0200) /* James: __TURBOC__ = 0x0297 */
" 2.0",
# else
# if (__BORLANDC__ == 0x0400)
" 3.0",
# else
# if (__BORLANDC__ == 0x0410) /* __BCPLUSPLUS__ = 0x0310 */
" 3.1",
# else
# if (__BORLANDC__ == 0x0452) /* __BCPLUSPLUS__ = 0x0320 */
" 4.0 or 4.02",
# else
" later than 4.1",
# endif
# endif
# endif
# endif
# endif
# else
"Turbo C",
# if (__TURBOC__ >= 0x0400) /* Kevin: 3.0 -> 0x0401 */
"++ 3.0 or later",
# else
# if (__TURBOC__ == 0x0295) /* [661] vfy'd by Kevin */
"++ 1.0",
# else
# if ((__TURBOC__ >= 0x018d) && (__TURBOC__ <= 0x0200)) /* James: 0x0200 */
" 2.0",
# else
# if (__TURBOC__ > 0x0100)
" 1.5", /* James: 0x0105? */
# else
" 1.0", /* James: 0x0100 */
# endif
# endif
# endif
# endif
# endif
#else
#ifdef MSC
"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
#else
"unknown compiler", "",
#endif /* MSC */
#endif /* __TURBOC__ */
#endif /* __WATCOMC__ */
#endif /* __GNUC__ */
"MS-DOS",
#if (defined(__GNUC__) || (defined(__WATCOMC__) && defined(__386__)))
" (32-bit)",
#else
# if defined(M_I86HM) || defined(__HUGE__)
" (16-bit, huge)",
# else
# if defined(M_I86LM) || defined(__LARGE__)
" (16-bit, large)",
# else
# if defined(M_I86MM) || defined(__MEDIUM__)
" (16-bit, medium)",
# else
# if defined(M_I86CM) || defined(__COMPACT__)
" (16-bit, compact)",
# else
# if defined(M_I86SM) || defined(__SMALL__)
" (16-bit, small)",
# else
# if defined(M_I86TM) || defined(__TINY__)
" (16-bit, tiny)",
# else
" (16-bit)",
# endif
# endif
# endif
# endif
# endif
# endif
#endif
#ifdef __DATE__
" on ", __DATE__
#else
"", ""
#endif
);
/* temporary debugging code for Borland compilers only */
#ifdef __TURBOC__
PRINTF("\tdebug(__TURBOC__ = 0x%04x = %d)\n", __TURBOC__, __TURBOC__);
#ifdef __BORLANDC__
PRINTF("\tdebug(__BORLANDC__ = 0x%04x)\n", __BORLANDC__);
#else
PRINTF("\tdebug(__BORLANDC__ not defined)\n");
#endif
#ifdef __TCPLUSPLUS__
PRINTF("\tdebug(__TCPLUSPLUS__ = 0x%04x)\n", __TCPLUSPLUS__);
#else
PRINTF("\tdebug(__TCPLUSPLUS__ not defined)\n");
#endif
#ifdef __BCPLUSPLUS__
PRINTF("\tdebug(__BCPLUSPLUS__ = 0x%04x)\n\n", __BCPLUSPLUS__);
#else
PRINTF("\tdebug(__BCPLUSPLUS__ not defined)\n\n");
#endif
#endif
} /* end function version() */
#endif /* !SFX */
#if (defined(__GO32__) || defined(__EMX__))
int volatile _doserrno;
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 _doserrno;
}
void _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");
}
void _dos_setfileattr(char *name, int attr)
{
asm("movl %0, %%edx": : "g" (name));
asm("movl %0, %%ecx": : "g" (attr));
asm("movl $0x4301, %eax");
asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
}
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));
_doserrno = 0;
asm("jnc 1f");
_doserrno = *fd;
switch (_doserrno) {
case 3:
errno = ENOENT;
break;
case 4:
errno = EMFILE;
break;
case 5:
errno = EACCES;
break;
}
asm("1:");
return _doserrno;
}
unsigned _dos_close(int fd)
{
asm("movl %0, %%ebx": : "g" (fd));
asm("movl $0x3e00, %eax");
asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
_doserrno = 0;
asm("jnc 1f");
asm ("movl %%eax, %0": "=m" (_doserrno));
if (_doserrno == 6) {
errno = EBADF;
}
asm("1:");
return _doserrno;
}
static int volumelabel(char *name)
{
int fd;
return _dos_creat(name, FA_LABEL, &fd) ? fd : _dos_close(fd);
}
#endif /* __GO32__ || __EMX__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -