home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 December
/
VPR9712A.ISO
/
OLS
/
OS2
/
LHA2P205
/
LHA2P205.LZH
/
lha2-2.05pre
/
source.lzh
/
src
/
port2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-25
|
28KB
|
1,133 lines
/*
* port2.c --- LHA OS/2 HPFS version porting library
* Copyright (C) 1991-1996, Satoshi HIRAMATSU.
*
* $Log$
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <ctype.h>
#include "port2.h"
#include "typedef.h"
#include "lh.h"
#ifdef __API16__
USHORT __version__ = 1000; /* First version. */
#endif
int ifs; /* Installable File System Type */
unsigned char *
jstrlwr(unsigned char *s)
{
unsigned char *p = s;
while(*p)
{
if(iskanji(*p) && *(p + 1))
++p;
else
*p = isupper(*p) ? _tolower(*p) : *p;
++p;
}
return s;
}
unsigned char *
jstrupr(unsigned char *s)
{
unsigned char *p = s;
while(*p)
{
if(iskanji(*p) && *(p + 1))
++p;
else
*p = islower(*p) ? _toupper(*p) : *p;
++p;
}
return s;
}
#if defined(__IBMC__) || defined(__IBMCPP__)
/*
* Replace a fopen() library function.
* Beacuse, IBM C Set++ and IBM VisualAge C++ have a BUG in fopen().
*/
#ifndef _IMPORT
#define _IMPORT
#endif
#ifndef _LNK_CONV
#define _LNK_CONV
#endif
FILE * _IMPORT _LNK_CONV
fopen(const char *path, const char *mode)
{
int id;
switch(*mode)
{
case 'r':
if(strchr(mode, '+'))
id = open(path, O_RDWR);
else
id = open(path, O_RDONLY);
break;
case 'w':
id = open(path, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
break;
case 'a':
id = open(path, O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
break;
default:
return (FILE *)NULL;
}
if(id < 0)
return (FILE *)NULL;
return fdopen(id, mode);
}
#endif /* __IBMC__ || __IBMCPP__ */
#ifdef __SUPPORT_EA__
static char pathname[MAXPATHLEN];
static void
SetPathname(const char *path)
{
char *sep1, *sep2, *null;
strcpy(pathname, path);
null = pathname;
sep1 = strrchr(path, '\\');
if((sep2 = strrchr(path, '/')) == (char *)NULL)
sep2 = strrchr(path, ':');
if(sep1 == (char *)NULL && sep2 == (char *)NULL)
{
*null = '\0';
return;
}
null = pathname + ((sep1 > sep2 ? sep1 : sep2) - path) + 1;
*null = '\0';
}
static void
BackPath(void)
{
char *sep1, *sep2, *null;
register int len;
if(!(len = strlen(pathname)))
return;
null = pathname + len - 1;
*null = '\0';
sep1 = strrchr(pathname, '\\');
if((sep2 = strrchr(pathname, '/')) == (char *)NULL)
sep2 = strrchr(pathname, ':');
if(sep1 == (char *)NULL && sep2 == (char *)NULL)
{
*pathname = '\0';
return;
}
null = (sep1 > sep2 ? sep1 : sep2) + 1;
*null = '\0';
}
static FEA2LIST *
GetEA(const char *path, unsigned long easize)
{
ULONG ec = -1L, saveec; /* EA count */
DENA2 *dena2, *dena2Base;
EAOP2 eaop2;
GEA2 *gea2;
GEA2LIST *gea2list;
FEA2LIST *fea2list;
size_t listsize; /* for calculate next EA offset */
#ifdef __DEBUG__
FEA2 *fea2;
printf("\nFilename = %s\n", path);
printf("EA size = %ld\n", easize);
#endif
/* Allocte EA buffer */
listsize = easize + sizeof(DENA2);
#if 0
listsize = (listsize/4 + (listsize%4 ? 1 : 0))*4;
#else
listsize = ((listsize >> 2) + ((listsize & 0x03) ? 1 : 0)) << 2;
#endif
dena2 = (DENA2 *)e_malloc(listsize);
dena2Base = dena2; /* save base address */
fea2list = (FEA2LIST *)dena2;
if(DosEnumAttribute(ENUMEA_REFTYPE_PATH, (PVOID)path, 1L,
(PVOID)dena2, easize, &ec, ENUMEA_LEVEL_NO_VALUE))
{
free(dena2);
return (FEA2LIST *)NULL;
}
#ifdef __DEBUG__
printf("EA num = %ld\n", ec);
#endif
if(!ec) /* Nothing EA */
{
free(dena2);
return (FEA2LIST *)NULL;
}
saveec = ec;
listsize = ec*sizeof(GEA2); /* Fixed buffer size */
do
{
#ifdef __DEBUG__
printf("Next EA offset = %ld\n", dena2->oNextEntryOffset);
printf("EA name length = %d\n", dena2->cbName);
printf("EA value length = %d\n", dena2->cbValue);
printf("EA name = %s\n\n", dena2->szName);
#endif
listsize += dena2->cbName + 1; /* NULL文字の領域を足す */
/* DWORD alignment */
#if 0
listsize = (listsize/4 + (listsize%4 ? 1 : 0))*4;
#else
listsize = ((listsize >> 2) + ((listsize & 0x03) ? 1 : 0)) << 2;
#endif
/* Set next EA entry address */
dena2 = (DENA2 *)((ULONG)dena2 + dena2->oNextEntryOffset);
}
while(--ec);
#ifdef __DEBUG__
printf("GEA2LIST size = %d\n", listsize);
#endif
/* Allocate GEA2 buffer (add offset entry) */
gea2list = (GEA2LIST *)e_malloc(sizeof(ULONG) + listsize);
gea2list->cbList = listsize; /* set total buffer size */
ec = saveec; /* reset EA counter */
dena2 = dena2Base; /* reset base address */
/* set gea2 base address */
gea2 = (GEA2 *)((ULONG)gea2list + sizeof(ULONG));
do
{
/* calculate next EA offset */
listsize = sizeof(GEA2) + dena2->cbName;
/* DWORD alignment */
#if 0
listsize = (listsize/4 + (listsize%4 ? 1 : 0))*4;
#else
listsize = ((listsize >> 2) + ((listsize & 0x03) ? 1 : 0)) << 2;
#endif
/* set GEA2 information */
gea2->oNextEntryOffset = dena2->oNextEntryOffset ? listsize : 0;
gea2->cbName = dena2->cbName;
strcpy(gea2->szName, dena2->szName);
/* set next EA entry address */
dena2 = (DENA2 *)((ULONG)dena2 + dena2->oNextEntryOffset);
gea2 = (GEA2 *)((ULONG)gea2 + gea2->oNextEntryOffset);
}
while(--ec);
/* set EAOP2 */
eaop2.fpGEA2List = gea2list;
eaop2.fpFEA2List = fea2list;
fea2list->cbList = easize;
/* Get EA */
if(DosQueryPathInfo((PSZ)path, FIL_QUERYEASFROMLIST, (PVOID)&eaop2,
sizeof(EAOP2)))
{
free(gea2list);
free(fea2list);
return (FEA2LIST *)NULL;
}
#ifdef __DEBUG__
ec = saveec;
fea2 = fea2list->list;
printf("EA list size = %ld\n", fea2list->cbList);
do
{
printf("Next EA offset = %ld\n", fea2->oNextEntryOffset);
printf("EA name length = %d\n", fea2->cbName);
printf("EA value length = %d\n", fea2->cbValue);
printf("EA name = %s\n\n", fea2->szName);
fea2 = (FEA2 *)((ULONG)fea2 + fea2->oNextEntryOffset);
}
while(--ec);
#endif
free(gea2list);
return fea2list;
}
unsigned
SetEA(const char *path, FEA2LIST* fea2list)
{
EAOP2 eaop2;
APIRET err;
eaop2.fpGEA2List = (GEA2LIST *)NULL;
eaop2.fpFEA2List = fea2list;
err = DosSetPathInfo((PSZ)path, FIL_QUERYEASIZE, (PVOID)&eaop2,
sizeof(EAOP2), DSPI_WRTTHRU);
return err;
}
#endif /* __SUPPORT_EA__ */
unsigned
_dos_findfirst(const char *path, unsigned attr, struct find_t *buf)
{
#ifdef __API16__
FILEFINDBUF findbuf;
USHORT err;
#else
FILEFINDBUF4 findbuf;
APIRET err;
#endif
#ifdef __SUPPORT_EA__
char realname[MAXPATHLEN];
#endif
buf->sc = 1;
buf->hdir = HDIR_CREATE;
#ifdef __API16__
if(__version__ < 1020) /* for OS/2 v1.0 and v1.1. */
{
err = DosFindFirst((PSZ)path, &(buf->hdir), attr, &findbuf,
sizeof(findbuf), &(buf->sc), 0L);
}
else
{
err = DosFindFirst2((PSZ)path, &(buf->hdir), attr, &findbuf,
sizeof(findbuf), &(buf->sc), FIL_STANDARD, 0L);
}
#else
err = DosFindFirst((PSZ)path, &(buf->hdir), (ULONG)attr, (PVOID)&findbuf,
sizeof(findbuf), &(buf->sc), FIL_QUERYEASIZE);
#endif
buf->attrib = findbuf.attrFile;
buf->wr_time = (findbuf.ftimeLastWrite.hours << 11)
+ (findbuf.ftimeLastWrite.minutes << 5)
+ findbuf.ftimeLastWrite.twosecs;
buf->wr_date = (findbuf.fdateLastWrite.year << 9)
+ (findbuf.fdateLastWrite.month << 5)
+ findbuf.fdateLastWrite.day;
buf->size = findbuf.cbFileAlloc;
strcpy(buf->name, findbuf.achName);
if(err)
{
#ifdef __SUPPORT_EA__
buf->ea = (FEA2LIST *)NULL;
#endif
errno = ENOENT;
return (unsigned)err;
}
#ifdef __SUPPORT_EA__
SetPathname(path);
if(strcmp(findbuf.achName, ".") && strcmp(findbuf.achName, ".."))
{
strcat(strcpy(realname, pathname), findbuf.achName);
buf->ea = GetEA(realname, findbuf.cbList); /* Get EA */
}
else
buf->ea = (FEA2LIST *)NULL;
#endif
return (unsigned)err;
}
unsigned
_dos_findnext(struct find_t *buf)
{
#ifdef __API16__
FILEFINDBUF findbuf;
USHORT err;
#else
FILEFINDBUF4 findbuf;
APIRET err;
#endif
#ifdef __SUPPORT_EA__
char realname[MAXPATHLEN];
#endif
buf->sc = 1;
#ifdef __API16__
err = DosFindNext(buf->hdir, &findbuf, sizeof(findbuf), &(buf->sc));
#else
err = DosFindNext(buf->hdir, (PVOID)&findbuf, sizeof(findbuf), &(buf->sc));
#endif
buf->attrib = findbuf.attrFile;
buf->wr_time = (findbuf.ftimeLastWrite.hours << 11)
+ (findbuf.ftimeLastWrite.minutes << 5)
+ findbuf.ftimeLastWrite.twosecs;
buf->wr_date = (findbuf.fdateLastWrite.year << 9)
+ (findbuf.fdateLastWrite.month << 5)
+ findbuf.fdateLastWrite.day;
buf->size = findbuf.cbFileAlloc;
strcpy(buf->name, findbuf.achName);
if(err)
{
#ifdef __SUPPORT_EA__
BackPath();
buf->ea = (FEA2LIST *)NULL;
#endif
errno = ENOENT;
return (unsigned)err;
}
#ifdef __SUPPORT_EA__
if(strcmp(findbuf.achName, ".") && strcmp(findbuf.achName, ".."))
{
strcat(strcpy(realname, pathname), findbuf.achName);
buf->ea = GetEA(realname, findbuf.cbList); /* Get EA */
}
else
buf->ea = (FEA2LIST *)NULL;
#endif
return (unsigned)err;
}
#ifndef __SUPPORT_CTIME_ATIME__
unsigned
_dos_getftime(int handle, unsigned *date, unsigned *time)
{
#ifdef __API16__
FILESTATUS filebuf;
if(DosQFileInfo((HFILE)handle, FIL_STANDARD, (PBYTE)&filebuf,
sizeof(filebuf)))
{
errno = EBADF;
return 1;
}
#else
FILESTATUS3 filebuf;
if(DosQueryFileInfo((HFILE)handle, FIL_STANDARD, (PVOID)&filebuf,
sizeof(filebuf)))
{
errno = EBADF;
return 1;
}
#endif
*time = (filebuf.ftimeLastWrite.hours << 11)
+ (filebuf.ftimeLastWrite.minutes << 5)
+ filebuf.ftimeLastWrite.twosecs;
*date = (filebuf.fdateLastWrite.year << 9)
+ (filebuf.fdateLastWrite.month << 5)
+ filebuf.fdateLastWrite.day;
*time &= 0xffff;
*date &= 0xffff;
return 0;
}
#else
unsigned
_os2_getftime(int handle, time_t *mod, time_t *cre, time_t *acc)
{
FILESTATUS3 filebuf;
union stamp stamp;
if(DosQueryFileInfo((HFILE)handle, FIL_STANDARD, (PVOID)&filebuf,
sizeof(filebuf)))
{
errno = EBADF;
return 1;
}
stamp.t.time = (filebuf.ftimeLastWrite.hours << 11)
+ (filebuf.ftimeLastWrite.minutes << 5)
+ filebuf.ftimeLastWrite.twosecs;
stamp.t.date = (filebuf.fdateLastWrite.year << 9)
+ (filebuf.fdateLastWrite.month << 5)
+ filebuf.fdateLastWrite.day;
stamp.t.time &= 0xffff;
stamp.t.date &= 0xffff;
*mod = dos2unix(&stamp.s);
stamp.t.time = (filebuf.ftimeCreation.hours << 11)
+ (filebuf.ftimeCreation.minutes << 5)
+ filebuf.ftimeCreation.twosecs;
stamp.t.date = (filebuf.fdateCreation.year << 9)
+ (filebuf.fdateCreation.month << 5)
+ filebuf.fdateCreation.day;
stamp.t.time &= 0xffff;
stamp.t.date &= 0xffff;
*cre = dos2unix(&stamp.s);
stamp.t.time = (filebuf.ftimeLastAccess.hours << 11)
+ (filebuf.ftimeLastAccess.minutes << 5)
+ filebuf.ftimeLastAccess.twosecs;
stamp.t.date = (filebuf.fdateLastAccess.year << 9)
+ (filebuf.fdateLastAccess.month << 5)
+ filebuf.fdateLastAccess.day;
stamp.t.time &= 0xffff;
stamp.t.date &= 0xffff;
*acc = dos2unix(&stamp.s);
return 0;
}
#endif
unsigned
_dos_getdtime(char *path, unsigned *date, unsigned *time)
{
#ifdef __API16__
FILESTATUS filebuf;
if(DosQPathInfo((PSZ)path, FIL_STANDARD, (PBYTE)&filebuf,
sizeof(filebuf), 0L))
{
errno = EBADF;
return 1;
}
#else
FILESTATUS3 filebuf;
if(DosQueryPathInfo((PSZ)path, FIL_STANDARD, (PVOID)&filebuf,
sizeof(filebuf)))
{
errno = EBADF;
return 1;
}
#endif
*time = (filebuf.ftimeLastWrite.hours << 11)
+ (filebuf.ftimeLastWrite.minutes << 5)
+ filebuf.ftimeLastWrite.twosecs;
*date = (filebuf.fdateLastWrite.year << 9)
+ (filebuf.fdateLastWrite.month << 5)
+ filebuf.fdateLastWrite.day;
*time &= 0xffff;
*date &= 0xffff;
return 0;
}
time_t
getdirectorytime(const char *f)
{
union stamp stamp;
char p[MAXPATHLEN];
int namlen;
unsigned date, time;
namlen = strlen(f) - 1;
if(*(f + namlen) == '/')
{
strncpy(p, f, namlen);
p[namlen] = '\0';
}
else
strcpy(p, f);
_dos_getdtime(p, &date, &time);
stamp.t.date = date & 0xffff;
stamp.t.time = time & 0xffff;
return dos2unix(&stamp.s);
}
#ifndef __SUPPORT_CTIME_ATIME__
unsigned
_dos_setftime(int handle, unsigned date, unsigned time)
{
#ifdef __API16__
FILESTATUS filebuf;
#else
FILESTATUS3 filebuf;
date &= 0xffff;
time &= 0xffff;
#endif
filebuf.ftimeLastWrite.hours = 0x1f & (time >> 11);
filebuf.ftimeLastWrite.minutes = 0x3f & (time >> 5);
filebuf.ftimeLastWrite.twosecs = 0x1f & time;
filebuf.fdateLastWrite.year = 0x1f & (date >> 9);
filebuf.fdateLastWrite.month = 0x0f & (date >> 5);
filebuf.fdateLastWrite.day = 0x7f & date;
filebuf.ftimeLastAccess.hours = filebuf.ftimeLastWrite.hours;
filebuf.ftimeLastAccess.minutes = filebuf.ftimeLastWrite.minutes;
filebuf.ftimeLastAccess.twosecs = filebuf.ftimeLastWrite.twosecs;
filebuf.fdateLastAccess.year = filebuf.fdateLastWrite.year;
filebuf.fdateLastAccess.month = filebuf.fdateLastWrite.month;
filebuf.fdateLastAccess.day = filebuf.fdateLastWrite.day;
filebuf.ftimeCreation.hours = filebuf.ftimeLastWrite.hours;
filebuf.ftimeCreation.minutes = filebuf.ftimeLastWrite.minutes;
filebuf.ftimeCreation.twosecs = filebuf.ftimeLastWrite.twosecs;
filebuf.fdateCreation.year = filebuf.fdateLastWrite.year;
filebuf.fdateCreation.month = filebuf.fdateLastWrite.month;
filebuf.fdateCreation.day = filebuf.fdateLastWrite.day;
filebuf.cbFile = 0L;
filebuf.cbFileAlloc = 0L;
filebuf.attrFile = 0;
#ifdef __API16__
if(DosSetFileInfo((HFILE)handle, 0x0001, (PBYTE)&filebuf, sizeof(filebuf)))
{
errno = EBADF;
return 1;
}
#else
if(DosSetFileInfo((HFILE)handle, FIL_STANDARD, (PVOID)&filebuf,
sizeof(filebuf)))
{
errno = EBADF;
return 1;
}
#endif
return 0;
}
#else
unsigned
_os2_setftime(int handle, time_t *t_mod, time_t *t_cre, time_t *t_acc)
{
FILESTATUS3 filebuf;
union stamp mod, cre, acc;
mod.s = *unix2dos(*t_mod);
if(t_cre)
cre.s = *unix2dos(*t_cre);
else
cre.t.time = cre.t.date = 0;
if(t_acc)
acc.s = *unix2dos(*t_acc);
else
acc.t.time = acc.t.date = 0;
mod.t.time &= 0xffff;
mod.t.date &= 0xffff;
filebuf.ftimeLastWrite.hours = 0x1f & (mod.t.time >> 11);
filebuf.ftimeLastWrite.minutes = 0x3f & (mod.t.time >> 5);
filebuf.ftimeLastWrite.twosecs = 0x1f & mod.t.time;
filebuf.fdateLastWrite.year = 0x1f & (mod.t.date >> 9);
filebuf.fdateLastWrite.month = 0x0f & (mod.t.date >> 5);
filebuf.fdateLastWrite.day = 0x7f & mod.t.date;
cre.t.time &= 0xffff;
cre.t.date &= 0xffff;
filebuf.ftimeCreation.hours = 0x1f & (cre.t.time >> 11);
filebuf.ftimeCreation.minutes = 0x3f & (cre.t.time >> 5);
filebuf.ftimeCreation.twosecs = 0x1f & cre.t.time;
filebuf.fdateCreation.year = 0x1f & (cre.t.date >> 9);
filebuf.fdateCreation.month = 0x0f & (cre.t.date >> 5);
filebuf.fdateCreation.day = 0x7f & cre.t.date;
acc.t.time &= 0xffff;
acc.t.date &= 0xffff;
filebuf.ftimeLastAccess.hours = 0x1f & (acc.t.time >> 11);
filebuf.ftimeLastAccess.minutes = 0x3f & (acc.t.time >> 5);
filebuf.ftimeLastAccess.twosecs = 0x1f & acc.t.time;
filebuf.fdateLastAccess.year = 0x1f & (acc.t.date >> 9);
filebuf.fdateLastAccess.month = 0x0f & (acc.t.date >> 5);
filebuf.fdateLastAccess.day = 0x7f & acc.t.date;
filebuf.cbFile = 0L;
filebuf.cbFileAlloc = 0L;
filebuf.attrFile = 0;
if(DosSetFileInfo((HFILE)handle, FIL_STANDARD, (PVOID)&filebuf,
sizeof(filebuf)))
{
errno = EBADF;
return 1;
}
return 0;
}
#endif
unsigned
_dos_getfileattr(const char *path, unsigned *attr)
{
char p[MAXPATHLEN];
int namlen;
#ifndef __API16__
FILESTATUS3 fileinfo;
#endif
namlen = strlen(path) - 1;
if(*(path + namlen) == '/')
{
strncpy(p, path, namlen);
p[namlen] = '\0';
}
else
strcpy(p, path);
#ifdef __API16__
if(DosQFileMode((PSZ)p, attr, 0L))
{
errno = ENOENT;
return 1;
}
#else
if(DosQueryPathInfo((PSZ)path, FIL_STANDARD, (PVOID)&fileinfo,
sizeof(fileinfo)))
return 1;
*attr = (unsigned)fileinfo.attrFile;
#endif
return 0;
}
unsigned
_dos_setfileattr(const char *path, unsigned attr)
{
#ifdef __API16__
USHORT result;
result = DosSetFileMode((PSZ)path, attr, 0L);
switch(result)
{
case 108: /* ERROR_DRIVE_LOCKED */
errno = EACCES;
return 1;
default:
errno = ENOENT;
return 1;
}
#else
FILESTATUS3 fileinfo;
if(DosQueryPathInfo((PSZ)path, FIL_STANDARD, (PVOID)&fileinfo,
sizeof(fileinfo)))
return 1;
fileinfo.attrFile = (USHORT)(0xffff & attr);
DosSetPathInfo((PSZ)path, FIL_STANDARD, (PVOID)&fileinfo,
sizeof(fileinfo), 0);
#endif
return 0;
}
unsigned
_dos_getdiskfree(unsigned drv, struct diskfree_t *space)
{
FSALLOCATE info;
#ifdef __API16__
if(DosQFSInfo(drv, 0x0001, (PBYTE)&info, sizeof(info)))
{
errno = EINVAL;
return 1;
}
#else
if(DosQueryFSInfo(drv, FSIL_ALLOC, (PVOID)&info, sizeof(info)))
{
errno = EINVAL;
return 1;
}
#endif
space->total_clusters = info.cUnit;
space->avail_clusters = info.cUnitAvail;
space->sectors_per_cluster = info.cSectorUnit;
space->bytes_per_sector = info.cbSector;
return 0;
}
char *
stpcpy(char *dest, const char *src)
{
strcpy(dest, src);
return (char *)(dest + strlen(src));
}
char *
mktemp(char *template)
{
static char prefix[]
= "0123456789abcdefghijklmnopqrstuvwxyz";
register size_t tlen, plen;
register int cnt = 0;
struct stat statbuf;
PTIB tib;
PPIB pib;
if(!template)
return template; /* NULL pointer */
if((tlen = strlen(template)) < 6)
return (char *)NULL; /* Wrong template string */
if(strcmp(&template[tlen - 6], "XXXXXX"))
return (char *)NULL; /* Wrong template string */
DosGetInfoBlocks(&tib, &pib);
if(sprintf(&template[tlen - 5], "%.5lu", pib->pib_ulpid % 100000) != 5)
return (char *)NULL; /* Invalid? PID */
plen = strlen(prefix);
do
{
template[tlen - 6] = prefix[cnt++];
if(stat(template, &statbuf))
return template; /* Cannot find "template". */
}
while(cnt < plen);
return (char *)NULL; /* Cannot make unique name. */
}
static int
CheckLongname(USHORT drvno)
{
char check[] = "a:.longname.XXXXXX";
int id;
check[0] = (char)('a' + drvno);
mktemp(check);
id = open(check, O_CREAT | O_EXCL | O_WRONLY, S_IWRITE);
if(id < 0)
switch(errno)
{
case EEXIST:
case EACCESS:
return HPFS;
/* case ENOENT: */
/* case EMFILE: */
/* case EOS2ERR: */
default:
return FAT;
}
close(id);
remove(check);
return HPFS;
}
void
SetFileSystem(int cmd, const char *dir)
{
PSZ psz;
char drv[3];
USHORT Version, drvno;
#ifdef __API16__
PUSHORT pcb;
USHORT cb;
SEL sel;
#else
BYTE fsinfo[sizeof(FSQBUFFER2) + (3*CCHMAXPATH)];
ULONG fsinfosize = sizeof(fsinfo);
#endif
#ifdef __API16__
DosGetVersion(&Version);
__version__ = HIBYTE(Version)*100;
__version__ += LOBYTE(Version);
if(__version__ < 1020)
{
ifs = FAT;
return;
}
#endif
if(!cmd && strlen(dir)) /* extract */
{
if(*(dir + 1) == ':')
drv[0] = *dir;
else /* NO have drive information */
{
drvno = _getdrive();
drv[0] = (char)('a' + (--drvno));
}
}
else
{ /* archive or NO base-directory extract */
drvno = _getdrive();
drv[0] = (char)('a' + (--drvno));
}
drv[1] = ':';
drv[2] = '\0';
#ifdef __API16__
DosAllocSeg(128, (PSEL)&sel, SEG_NONSHARED);
cb = 128;
DosQFSAttach(&drv[0], 0, FSAIL_QUERYNAME, (PBYTE)MAKEP(sel, 0), &cb, 0L);
pcb = MAKEP(sel, 2); /* length of device name */
psz = MAKEP(sel, 4); /* device name */
psz += *pcb + 3; /* add '\0' and length of divice name */
#else
DosQueryFSAttach(drv, 0, FSAIL_QUERYNAME, (PFSQBUFFER2)&fsinfo, &fsinfosize);
psz = ((PFSQBUFFER2)&fsinfo)->szName + ((PFSQBUFFER2)&fsinfo)->cbName + 1;
#endif
if(!strcmp("FAT", psz) || !strcmp("CDFS", psz) || !strcmp("NETWARE", psz))
ifs = FAT;
else if(!strcmp("HPFS", psz))
ifs = HPFS;
else
ifs = CheckLongname(drvno);
return;
}
int
GetFileSystem(const char *name)
{
PSZ psz;
char drv[3];
USHORT Version, drvno;
#ifdef __API16__
PUSHORT pcb;
USHORT cb;
SEL sel;
#else
BYTE fsinfo[sizeof(FSQBUFFER2) + (3*CCHMAXPATH)];
ULONG fsinfosize = sizeof(fsinfo);
#endif
#ifdef __API16__
DosGetVersion(&Version);
__version__ = HIBYTE(Version)*100;
__version__ += LOBYTE(Version);
if(__version__ < 1020)
return FAT;
#endif
if(*(name + 1) == ':')
drv[0] = *name;
else /* NO have drive information */
{
drvno = _getdrive();
drv[0] = (char)('a' + (--drvno));
}
drv[1] = ':';
drv[2] = '\0';
#ifdef __API16__
DosAllocSeg(128, (PSEL)&sel, SEG_NONSHARED);
cb = 128;
DosQFSAttach(&drv[0], 0, FSAIL_QUERYNAME, (PBYTE)MAKEP(sel, 0), &cb, 0L);
pcb = MAKEP(sel, 2); /* length of device name */
psz = MAKEP(sel, 4); /* device name */
psz += *pcb + 3; /* add '\0' and length of divice name */
#else
DosQueryFSAttach(drv, 0, FSAIL_QUERYNAME, (PFSQBUFFER2)&fsinfo, &fsinfosize);
psz = ((PFSQBUFFER2)&fsinfo)->szName + ((PFSQBUFFER2)&fsinfo)->cbName + 1;
#endif
if(!strcmp("FAT", psz) || !strcmp("CDFS", psz) || !strcmp("NETWARE", psz))
return FAT;
else
return HPFS;
}
/* common message pointer */
char *_NOARCNMERR, *_NOFNERR, *_NOARCERR, *_MKTMPERR, *_DUPFNERR, *_TOOLONGERR;
char *_NOFILEERR, *_MKFILEERR, *_RDERR, *_WTERR, *_MEMOVRERR, *_CTRLBRK;
char *_NOMATCHERR, *_NOTLZH, *_SAMEFILE, *_OVERWT, *_MKDIR, *_MKDIRERR;
char *_RDONLY, *_COPYERR, *_BROKENARC, *_MAYDELETE, *_MAYCONT, *_SAMEDIR;
char *_NEWFILE, *_METHODERR, *_DISKFULL, *_NOCRC, *_NOMOREEXT, *_SPECIALATTR;
char *_EXTRADATA;
#if 0
char *_UNKNOWNERR, *_INVCMDERR, *_MANYPATERR, *_RENAMEERR, *_TOOMANYERR;
char *_INVSWERR, *_CRCERR, *_MKARCERR, *_NESTERR;
#endif
#ifndef FIRST_COMPILATION
char *use;
#endif
/* support code page 437 and 932 */
extern char NOARCNMERR_437[], NOFNERR_437[], NOARCERR_437[], MKTMPERR_437[];
extern char DUPFNERR_437[], TOOLONGERR_437[], NOFILEERR_437[], MKFILEERR_437[];
extern char RDERR_437[], WTERR_437[], MEMOVRERR_437[], CTRLBRK_437[];
extern char NOMATCHERR_437[], NOTLZH_437[], SAMEFILE_437[], OVERWT_437[];
extern char MKDIR_437[], MKDIRERR_437[], RDONLY_437[], COPYERR_437[];
extern char BROKENARC_437[], MAYDELETE_437[], MAYCONT_437[], SAMEDIR_437[];
extern char NEWFILE_437[], METHODERR_437[], DISKFULL_437[], NOCRC_437[];
extern char NOMOREEXT_437[], SPECIALATTR_437[], EXTRADATA_437[];
extern char NOARCNMERR_932[], NOFNERR_932[], NOARCERR_932[], MKTMPERR_932[];
extern char DUPFNERR_932[], TOOLONGERR_932[], NOFILEERR_932[], MKFILEERR_932[];
extern char RDERR_932[], WTERR_932[], MEMOVRERR_932[], CTRLBRK_932[];
extern char NOMATCHERR_932[], NOTLZH_932[], SAMEFILE_932[], OVERWT_932[];
extern char MKDIR_932[], MKDIRERR_932[], RDONLY_932[], COPYERR_932[];
extern char BROKENARC_932[], MAYDELETE_932[], MAYCONT_932[], SAMEDIR_932[];
extern char NEWFILE_932[], METHODERR_932[], DISKFULL_932[], NOCRC_932[];
extern char NOMOREEXT_932[], SPECIALATTR_932[], EXTRADATA_932[];
#if 0
extern char UNKNOWNERR_437[], INVCMDERR_437[], MANYPATERR_437[];
extern char RENAMEERR_437[], TOOMANYERR_437[], INVSWERR_437[], CRCERR_437[];
extern char MKARCERR_437[], NESTERR_437[];
extern char UNKNOWNERR_932[], INVCMDERR_932[], MANYPATERR_932[];
extern char RENAMEERR_932[], TOOMANYERR_932[], INVSWERR_932[], CRCERR_932[];
extern char MKARCERR_932[], NESTERR_932[];
#endif
#ifndef FIRST_COMPILATION
extern char use_e[], use_j[];
#endif
void
SetMessage(void)
{
#ifdef __API16__
USHORT CodePage = 0, cnt;
#else
ULONG CodePage = 0, cnt;
#endif
DosGetCp(sizeof(CodePage), &CodePage, &cnt);
if((CodePage == 932) || (CodePage == 942)) /* JAPANESE */
{
_NOARCNMERR = NOARCNMERR_932;
_NOFNERR = NOFNERR_932;
_NOARCERR = NOARCERR_932;
_MKTMPERR = MKTMPERR_932;
_DUPFNERR = DUPFNERR_932;
_TOOLONGERR = TOOLONGERR_932;
_NOFILEERR = NOFILEERR_932;
_MKFILEERR = MKFILEERR_932;
_RDERR = RDERR_932;
_WTERR = WTERR_932;
_MEMOVRERR = MEMOVRERR_932;
_CTRLBRK = CTRLBRK_932;
_NOMATCHERR = NOMATCHERR_932;
_NOTLZH = NOTLZH_932;
_SAMEFILE = SAMEFILE_932;
_OVERWT = OVERWT_932;
_MKDIR = MKDIR_932;
_MKDIRERR = MKDIRERR_932;
_RDONLY = RDONLY_932;
_COPYERR = COPYERR_932;
_BROKENARC = BROKENARC_932;
_MAYDELETE = MAYDELETE_932;
_MAYCONT = MAYCONT_932;
_SAMEDIR = SAMEDIR_932;
_NEWFILE = NEWFILE_932;
_METHODERR = METHODERR_932;
_DISKFULL = DISKFULL_932;
_NOCRC = NOCRC_932;
_NOMOREEXT = NOMOREEXT_932;
_SPECIALATTR = SPECIALATTR_932;
_EXTRADATA = EXTRADATA_932;
#if 0
_UNKNOWNERR = UNKNOWNERR_932;
_INVCMDERR = INVCMDERR_932;
_MANYPATERR = MANYPATERR_932;
_RENAMEERR = RENAMEERR_932;
_TOOMANYERR = TOOMANYERR_932;
_INVSWERR = INVSWERR_932;
_CRCERR = CRCERR_932;
_MKARCERR = MKARCERR_932;
_NESTERR = NESTERR_932;
#endif
#ifndef FIRST_COMPILATION
use = use_j;
#endif
}
else
{
_NOARCNMERR = NOARCNMERR_437;
_NOFNERR = NOFNERR_437;
_NOARCERR = NOARCERR_437;
_MKTMPERR = MKTMPERR_437;
_DUPFNERR = DUPFNERR_437;
_TOOLONGERR = TOOLONGERR_437;
_NOFILEERR = NOFILEERR_437;
_MKFILEERR = MKFILEERR_437;
_RDERR = RDERR_437;
_WTERR = WTERR_437;
_MEMOVRERR = MEMOVRERR_437;
_CTRLBRK = CTRLBRK_437;
_NOMATCHERR = NOMATCHERR_437;
_NOTLZH = NOTLZH_437;
_SAMEFILE = SAMEFILE_437;
_OVERWT = OVERWT_437;
_MKDIR = MKDIR_437;
_MKDIRERR = MKDIRERR_437;
_RDONLY = RDONLY_437;
_COPYERR = COPYERR_437;
_BROKENARC = BROKENARC_437;
_MAYDELETE = MAYDELETE_437;
_MAYCONT = MAYCONT_437;
_SAMEDIR = SAMEDIR_437;
_NEWFILE = NEWFILE_437;
_METHODERR = METHODERR_437;
_DISKFULL = DISKFULL_437;
_NOCRC = NOCRC_437;
_NOMOREEXT = NOMOREEXT_437;
_SPECIALATTR = SPECIALATTR_437;
_EXTRADATA = EXTRADATA_437;
#if 0
_UNKNOWNERR = UNKNOWNERR_437;
_INVCMDERR = INVCMDERR_437;
_MANYPATERR = MANYPATERR_437;
_RENAMEERR = RENAMEERR_437;
_TOOMANYERR = TOOMANYERR_437;
_INVSWERR = INVSWERR_437;
_CRCERR = CRCERR_437;
_MKARCERR = MKARCERR_437;
_NESTERR = NESTERR_437;
#endif
#ifndef FIRST_COMPILATION
use = use_e;
#endif
}
}