Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/tandem/tanunz.c view on Meta::CPAN
eb_id = makeword(EB_ID + ef_buf);
eb_len = makeword(EB_LEN + ef_buf);
if (eb_len > (ef_len - EB_HEADSIZE)) {
/* discovered some extra field inconsistency! */
TTrace((stderr,
"ef_scan_for_tandem: block length %u > rest ef_size %u\n", eb_len,
ef_len - EB_HEADSIZE));
break;
}
switch (eb_id) {
case EF_TANDEM:
return (nsk_file_attrs *)(char *)(ef_buf + EB_HEADSIZE);
break;
default:
break;
}
/* Skip this extra field block */
ef_buf += (eb_len + EB_HEADSIZE);
ef_len -= (eb_len + EB_HEADSIZE);
}
return NULL;
}
/***************************/
/* Function open_outfile() */
/***************************/
int open_outfile(__G) /* return 1 if fail */
__GDEF
{
int fdesc;
short fnum, err, len;
int priext, secext;
short maxext, filecode, blocksize;
#define alist_items 1
#define vlist_bytes 2
short alist[alist_items]={42};
unsigned short vlist[alist_items];
short extra, *err_item=&extra;
nsk_file_attrs *znsk_attr;
ulg eof, pages;
char nsk_work[FILENAME_MAX + 1], *nsk_fname=&nsk_work[0];
#ifdef DLL
if (G.redirect_data)
return (redirect_outfile(__G) == FALSE);
#endif
if (SSTAT(G.filename, &G.statbuf) == 0) {
Trace((stderr, "open_outfile: stat(%s) returns 0: file exists\n",
FnFilter1(G.filename)));
if (unlink(G.filename) != 0) {
Trace((stderr, "open_outfile: existing file %s is read-only\n",
FnFilter1(G.filename)));
chmod(G.filename, S_IRUSR | S_IWUSR);
Trace((stderr, "open_outfile: %s now writable\n",
FnFilter1(G.filename)));
if (unlink(G.filename) != 0) {
Info(slide, 0x401, ((char *)slide,
LoadFarString(CannotDeleteOldFile), FnFilter1(G.filename)));
return 1;
}
}
Trace((stderr, "open_outfile: %s now deleted\n",
FnFilter1(G.filename)));
}
/* Set up Tandem specific file information if present */
znsk_attr = ef_scan_for_tandem(G.extra_field, G.lrec.extra_field_length);
if (znsk_attr != NULL) {
/* Set extent sizes */
priext = znsk_attr->priext;
secext = znsk_attr->secext;
maxext = (int) znsk_attr->maxext;
/* If original file was Enscribe and text then recreate as Edit */
filecode = (znsk_attr->filetype != NSK_UNSTRUCTURED ?
(G.pInfo->textmode ? NSK_EDITFILECODE : NSK_UNSTRUCTURED) :
znsk_attr->filecode);
blocksize = znsk_attr->block;
} else {
/* Try to work out some decent sizes based on how big the file is */
eof = G.lrec.ucsize;
pages = (eof/2048) + 2;
if (pages <= 500) {
priext = pages; /* fits into one extent */
maxext = 16;
} else {
priext = 500; /* Try and fit into 500 page chunks */
maxext = pages/(priext - 50); /* Allow for Enscribe overhead */
if (maxext > 978) {
priext = eof >> 10; /* 512 equal extents */
maxext = 978; /* 2048 * 512 == 2^10 */
}
}
secext = priext;
filecode = (G.pInfo->textmode ? NSK_EDITFILECODE : NSK_UNSTRUCTURED);
blocksize = TANDEM_BLOCKSIZE;
}
if ((fdesc = creat(G.filename,,priext,secext)) != -1){
fnum = fdtogfn ((short)fdesc);
err = (SETMODE (fnum, SET_FILE_BUFFERSIZE, blocksize) != CCE);
err = (SETMODE (fnum, SET_FILE_BUFFERED, 0, 0) != CCE);
err = (SETMODE (fnum, SET_FILE_BUFFERED, 0, 1) != CCE);
err = (SETMODE (fnum, SET_FILE_MAXEXTENTS, maxext) != CCE);
err = close(fdesc);
vlist[0] = filecode;
/* Note that FILE_ALTERLIST_ expects uppercase names */
/* Need to call strlen and upshift */
len = strlen(G.filename);
err = STRING_UPSHIFT_(G.filename,
len,
nsk_fname,
unzip-6.0/tandem/tanunz.c view on Meta::CPAN
}
}
/*---------------------------------------------------------------------------
Convert from MSDOS-format local time and date to Unix-format 32-bit GMT
time: adjust base year from 1980 to 1970, do usual conversions from
yy/mm/dd hh:mm:ss to elapsed seconds, and account for timezone and day-
light savings time differences. If we have a Unix extra field, however,
we're laughing: both mtime and atime are ours. On the other hand, we
then have to check for restoration of UID/GID.
---------------------------------------------------------------------------*/
eb_izux_flg = (G.extra_field ? ef_scan_for_izux(G.extra_field,
G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime,
#ifdef IZ_CHECK_TZ
(G.tz_is_valid ? &(zt.t3) : NULL),
#else
&(zt.t3),
#endif
z_uidgid) : 0);
if (eb_izux_flg & EB_UT_FL_MTIME) {
TTrace((stderr, "\nclose_outfile: Unix e.f. modif. time = %ld\n",
zt.t3.mtime));
} else {
zt.t3.mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
}
if (eb_izux_flg & EB_UT_FL_ATIME) {
TTrace((stderr, "close_outfile: Unix e.f. access time = %ld\n",
zt.t3.atime));
} else {
zt.t3.atime = zt.t3.mtime;
TTrace((stderr, "\nclose_outfile: modification/access times = %ld\n",
zt.t3.mtime));
}
/*---------------------------------------------------------------------------
Change the file's last modified time to that stored in the zipfile.
Not sure how (yet) or whether it's a good idea to set the last open time
---------------------------------------------------------------------------*/
/* skip restoring time stamps on user's request */
if (uO.D_flag <= 1) {
/* set the file's access and modification times */
if (utime(G.filename, &(zt.t2)))
if (uO.qflag)
Info(slide, 0x201, ((char *)slide,
"warning: cannot set times for %s\n",
FnFilter1(G.filename)));
else
Info(slide, 0x201, ((char *)slide,
" (warning) cannot set times"));
}
/*---------------------------------------------------------------------------
Change the file permissions from default ones to those stored in the
zipfile.
---------------------------------------------------------------------------*/
#ifndef NO_CHMOD
if (chmod(G.filename, 0xffff & G.pInfo->file_attr))
perror("chmod (file attributes) error");
#endif
/*---------------------------------------------------------------------------
if -X option was specified and we have UID/GID info, restore it
this must come after the file security and modtimes changes - since once
we have secured the file to somebody else we cannot access it again.
---------------------------------------------------------------------------*/
if (uO.X_flag && eb_izux_flg & EB_UX2_VALID) {
TTrace((stderr, "close_outfile: restoring Unix UID/GID info\n"));
if (chown(G.filename, (uid_t)z_uidgid[0], (gid_t)z_uidgid[1]))
{
if (uO.qflag)
Info(slide, 0x201, ((char *)slide,
"warning: cannot set UID %lu and/or GID %lu for %s\n",
z_uidgid[0], z_uidgid[1], FnFilter1(G.filename)));
else
Info(slide, 0x201, ((char *)slide,
" (warning) cannot set UID %lu and/or GID %lu",
z_uidgid[0], z_uidgid[1]));
}
}
} /* end function close_outfile() */
#ifndef SFX
/************************/
/* Function version() */
/************************/
void version(__G)
__GDEF
{
/* Pyramid, NeXT have problems with huge macro expansion, too: no Info() */
sprintf((char *)slide, LoadFarString(CompiledWith),
"C ",
"T9255D44 - (16OCT98)",
"NonStop ",
"(Tandem/NSK)",
#ifdef __DATE__
" on ", __DATE__
#else
"", ""
#endif
);
(*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
} /* end function version() */
#endif /* !SFX */
( run in 0.822 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )