📄 beos.c
字号:
if ((end-buildpath) >= FILNAMSIZ) { *--end = '\0'; Info(slide, 0x201, ((char *)slide, "checkdir warning: path too long; truncating\n\ %s\n -> %s\n", FnFilter1(G.filename), FnFilter2(buildpath))); return MPN_INF_TRUNC; /* filename truncated */ } } Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath))); /* could check for existence here, prompt for new name... */ return MPN_OK; }/*--------------------------------------------------------------------------- INIT: allocate and initialize buffer space for the file currently being extracted. If file was renamed with an absolute path, don't prepend the extract-to path. ---------------------------------------------------------------------------*//* GRR: for VMS and TOPS-20, add up to 13 to strlen */ if (FUNCTION == INIT) { Trace((stderr, "initializing buildpath to "));#ifdef ACORN_FTYPE_NFS if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+ (uO.acorn_nfs_ext ? 5 : 1)))#else if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1))#endif == (char *)NULL) return MPN_NOMEM; if ((rootlen > 0) && !renamed_fullpath) { strcpy(buildpath, rootpath); end = buildpath + rootlen; } else { *buildpath = '\0'; end = buildpath; } Trace((stderr, "[%s]\n", FnFilter1(buildpath))); return MPN_OK; }/*--------------------------------------------------------------------------- ROOT: if appropriate, store the path in rootpath and create it if necessary; else assume it's a zipfile member and return. This path segment gets used in extracting all members from every zipfile specified on the command line. ---------------------------------------------------------------------------*/#if (!defined(SFX) || defined(SFX_EXDIR)) if (FUNCTION == ROOT) { Trace((stderr, "initializing root path to [%s]\n", FnFilter1(pathcomp))); if (pathcomp == (char *)NULL) { rootlen = 0; return MPN_OK; } if (rootlen > 0) /* rootpath was already set, nothing to do */ return MPN_OK; if ((rootlen = strlen(pathcomp)) > 0) { char *tmproot; if ((tmproot = (char *)malloc(rootlen+2)) == (char *)NULL) { rootlen = 0; return MPN_NOMEM; } strcpy(tmproot, pathcomp); if (tmproot[rootlen-1] == '/') { tmproot[--rootlen] = '\0'; } if (rootlen > 0 && (stat(tmproot, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode))) { /* path does not exist */ if (!G.create_dirs /* || iswild(tmproot) */ ) { free(tmproot); rootlen = 0; /* skip (or treat as stored file) */ return MPN_INF_SKIP; } /* create the directory (could add loop here scanning tmproot * to create more than one level, but why really necessary?) */ if (mkdir(tmproot, 0777) == -1) { Info(slide, 1, ((char *)slide, "checkdir: cannot create extraction directory: %s\n", FnFilter1(tmproot))); free(tmproot); rootlen = 0; /* path didn't exist, tried to create, and failed: */ /* file exists, or 2+ subdir levels required */ return MPN_ERR_SKIP; } } tmproot[rootlen++] = '/'; tmproot[rootlen] = '\0'; if ((rootpath = (char *)realloc(tmproot, rootlen+1)) == NULL) { free(tmproot); rootlen = 0; return MPN_NOMEM; } Trace((stderr, "rootpath now = [%s]\n", FnFilter1(rootpath))); } return MPN_OK; }#endif /* !SFX || SFX_EXDIR *//*--------------------------------------------------------------------------- END: free rootpath, immediately prior to program exit. ---------------------------------------------------------------------------*/ if (FUNCTION == END) { Trace((stderr, "freeing rootpath\n")); if (rootlen > 0) { free(rootpath); rootlen = 0; } return MPN_OK; } return MPN_INVALID; /* should never reach */} /* end function checkdir() *//****************************//* Function close_outfile() *//****************************/void close_outfile(__G) /* GRR: change to return PK-style warning level */ __GDEF{ iztimes zt; ush z_uidgid[2]; unsigned eb_izux_flg;/*--------------------------------------------------------------------------- If symbolic links are supported, allocate a storage area, put the uncom- pressed "data" in it, and create the link. Since we know it's a symbolic link to start with, we shouldn't have to worry about overflowing unsigned ints with unsigned longs. ---------------------------------------------------------------------------*/#ifdef SYMLINKS if (G.symlnk) { unsigned ucsize = (unsigned)G.lrec.ucsize; char *linktarget = (char *)malloc((unsigned)G.lrec.ucsize+1); fclose(G.outfile); /* close "data" file... */ G.outfile = fopen(G.filename, FOPR); /* ...and reopen for reading */ if (!linktarget || fread(linktarget, 1, ucsize, G.outfile) != (int)ucsize) { Info(slide, 0x201, ((char *)slide, "warning: symbolic link (%s) failed\n", FnFilter1(G.filename))); if (linktarget) free(linktarget); fclose(G.outfile); return; } fclose(G.outfile); /* close "data" file for good... */ unlink(G.filename); /* ...and delete it */ linktarget[ucsize] = '\0'; if (QCOND2) Info(slide, 0, ((char *)slide, "-> %s ", FnFilter1(linktarget))); if (symlink(linktarget, G.filename)) /* create the real link */ perror("symlink error"); if (!uO.J_flag) { /* Symlinks can have attributes, too. */ void *ptr = scanBeOSexfield( G.extra_field, G.lrec.extra_field_length ); if (ptr) { setBeOSexfield( G.filename, ptr ); } } free(linktarget); return; /* can't set time on symlinks */ }#endif /* SYMLINKS */ fclose(G.outfile); /* handle the BeOS extra field if present */ if (!uO.J_flag) { void *ptr = scanBeOSexfield( G.extra_field, G.lrec.extra_field_length ); if (ptr) { setBeOSexfield( G.filename, ptr );#ifdef BEOS_ASSIGN_FILETYPE } else { /* Otherwise, ask the system to try assigning a MIME type. */ assign_MIME( G.filename );#endif } }/*--------------------------------------------------------------------------- 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/*--------------------------------------------------------------------------- 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 : NULL),#else &zt,#endif z_uidgid) : 0); if (eb_izux_flg & EB_UT_FL_MTIME) { TTrace((stderr, "\nclose_outfile: Unix e.f. modif. time = %ld\n", zt.mtime)); } else { zt.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.atime)); } else { zt.atime = zt.mtime; TTrace((stderr, "\nclose_outfile: modification/access times = %ld\n", zt.mtime)); } /* if -X option was specified and we have UID/GID info, restore it */ 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 %d and/or GID %d for %s\n", z_uidgid[0], z_uidgid[1], FnFilter1(G.filename))); else Info(slide, 0x201, ((char *)slide, " (warning) cannot set UID %d and/or GID %d", z_uidgid[0], z_uidgid[1])); } } /* set the file's access and modification times */ if (utime(G.filename, (struct utimbuf *)&zt)) { if (uO.qflag) Info(slide, 0x201, ((char *)slide, "warning: cannot set time for %s\n", FnFilter1(G.filename))); else Info(slide, 0x201, ((char *)slide, " (warning) cannot set time")); }} /* end function close_outfile() */#ifdef SET_DIR_ATTRIB/* messages of code for setting directory attributes */static char Far DirlistUidGidFailed[] = "warning: cannot set UID %d and/or GID %d for %s\n";static char Far DirlistUtimeFailed[] = "warning: cannot set modification, access times for %s\n";# ifndef NO_CHMOD static char Far DirlistChmodFailed[] = "warning: cannot set permissions for %s\n";# endifint set_direc_attribs(__G__ d) __GDEF dirtime *d;{ int errval = PK_OK; if (d->have_uidgid && chown(d->fn, (uid_t)d->uidgid[0], (gid_t)d->uidgid[1])) { Info(slide, 0x201, ((char *)slide, LoadFarString(DirlistUidGidFailed), d->uidgid[0], d->uidgid[1], d->fn)); if (!errval) errval = PK_WARN; } if (utime(d->fn, (const struct utimbuf *)&d->u.t2)) { Info(slide, 0x201, ((char *)slide, LoadFarString(DirlistUtimeFailed), FnFilter1(d->fn))); if (!errval) errval = PK_WARN; }#ifndef NO_CHMOD if (chmod(d->fn, 0xffff & d->perms)) { Info(slide, 0x201, ((char *)slide, LoadFarString(DirlistChmodFailed), FnFilter1(d->fn))); /* perror("chmod (file attributes) error"); */ if (!errval) errval = PK_WARN; }#endif /* !NO_CHMOD */ return errval;} /* end function set_directory_attributes() */#endif /* SET_DIR_ATTRIB */#ifdef TIMESTAMP/***************************//* Function stamp_file() *//***************************/int stamp_file(fname, modtime) ZCONST char *fname;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -