?? os2.c
字號:
dosfiletime._fdt.ft.twosecs = 0; dosfiletime._fdt.ft.minutes = 0; dosfiletime._fdt.ft.hours = 0; dosfiletime._fdt.fd.day = 1; dosfiletime._fdt.fd.month = 1; dosfiletime._fdt.fd.year = 0; } else { dosfiletime._fdt.ft.twosecs = t->tm_sec >> 1; dosfiletime._fdt.ft.minutes = t->tm_min; dosfiletime._fdt.ft.hours = t->tm_hour; dosfiletime._fdt.fd.day = t->tm_mday; dosfiletime._fdt.fd.month = t->tm_mon + 1; dosfiletime._fdt.fd.year = t->tm_year - 80; } return dosfiletime.timevalue;} /* end function Utime2DosDateTime() */#endif /* USE_EF_UT_TIME || TIMESTAMP */static int getOS2filetimes(__GPRO__ ulg *pM_dt, ulg *pA_dt, ulg *pC_dt){#ifdef USE_EF_UT_TIME unsigned eb_izux_flg; iztimes z_utime;#endif /* Copy and/or convert time and date variables, if necessary; */ /* return a flag indicating which time stamps are available. */#ifdef USE_EF_UT_TIME if (G.extra_field &&#ifdef IZ_CHECK_TZ G.tz_is_valid &&#endif ((eb_izux_flg = ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime, &z_utime, NULL)) & EB_UT_FL_MTIME)) { TTrace((stderr, "getOS2filetimes: UT e.f. modif. time = %lu\n", z_utime.mtime)); *pM_dt = Utime2DosDateTime(z_utime.mtime); if (eb_izux_flg & EB_UT_FL_ATIME) { TTrace((stderr, "getOS2filetimes: UT e.f. access time = %lu\n", z_utime.atime)); *pA_dt = Utime2DosDateTime(z_utime.atime); } if (eb_izux_flg & EB_UT_FL_CTIME) { TTrace((stderr, "getOS2filetimes: UT e.f. creation time = %lu\n", z_utime.ctime)); *pC_dt = Utime2DosDateTime(z_utime.ctime); } else { /* no creation time value supplied, set it to modification time */ *pC_dt = *pM_dt; eb_izux_flg |= EB_UT_FL_CTIME; } return (int)eb_izux_flg; }#endif /* USE_EF_UT_TIME */ *pC_dt = *pM_dt = G.lrec.last_mod_dos_datetime; TTrace((stderr, "\ngetOS2filetimes: DOS dir modific./creation time = %lu\n", *pM_dt)); return (EB_UT_FL_MTIME | EB_UT_FL_CTIME);}static void SetPathAttrTimes(__GPRO__ int flags, int dir){ HFILE hFile;#ifdef __32BIT__ ULONG nAction;#else USHORT nAction;#endif FILESTATUS fs; USHORT nLength; char szName[CCHMAXPATH]; ulg Mod_dt, Acc_dt, Cre_dt; int gotTimes; strcpy(szName, G.filename); nLength = strlen(szName); if (szName[nLength - 1] == '/') szName[nLength - 1] = 0; if (dir) { if ( DosQueryPathInfo(szName, FIL_STANDARD, (PBYTE) &fs, sizeof(fs)) ) return; } else { /* for regular files, open them and operate on the file handle, to work around certain network operating system bugs ... */ if ( DosOpen(szName, &hFile, &nAction, 0, 0, OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW, OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE, 0) ) return; if ( DosQueryFileInfo(hFile, FIL_STANDARD, (PBYTE) &fs, sizeof(fs)) ) return; } /* set date/time stamps */ gotTimes = getOS2filetimes(__G__ &Mod_dt, &Acc_dt, &Cre_dt); if (gotTimes & EB_UT_FL_MTIME) { fs.fdateLastWrite = ((F_DATE_TIME *)&Mod_dt)->_fdt.fd; fs.ftimeLastWrite = ((F_DATE_TIME *)&Mod_dt)->_fdt.ft; } if (gotTimes & EB_UT_FL_ATIME) { fs.fdateLastAccess = ((F_DATE_TIME *)&Acc_dt)->_fdt.fd; fs.ftimeLastAccess = ((F_DATE_TIME *)&Acc_dt)->_fdt.ft; } if (gotTimes & EB_UT_FL_CTIME) { fs.fdateCreation = ((F_DATE_TIME *)&Cre_dt)->_fdt.fd; fs.ftimeCreation = ((F_DATE_TIME *)&Cre_dt)->_fdt.ft; } if ( flags != -1 ) fs.attrFile = flags; /* hidden, system, archive, read-only */ if (dir) { DosSetPathInfo(szName, FIL_STANDARD, (PBYTE) &fs, sizeof(fs), 0); } else { DosSetFileInfo(hFile, FIL_STANDARD, (PBYTE) &fs, sizeof(fs)); DosClose(hFile); }}typedef struct{ ULONG cbList; /* length of value + 22 */#ifdef __32BIT__ ULONG oNext;#endif BYTE fEA; /* 0 */ BYTE cbName; /* length of ".LONGNAME" = 9 */ USHORT cbValue; /* length of value + 4 */ BYTE szName[10]; /* ".LONGNAME" */ USHORT eaType; /* 0xFFFD for length-preceded ASCII */ USHORT eaSize; /* length of value */ BYTE szValue[CCHMAXPATH];}FEALST;static int SetEAs(__GPRO__ const char *path, void *ef_block){ /* returns almost-PK errors */ EFHEADER *pEAblock = (PEFHEADER) ef_block;#ifdef __32BIT__ EAOP2 eaop; PFEA2LIST pFEA2list;#else EAOP eaop; PFEALIST pFEAlist; PFEA pFEA; PFEA2LIST pFEA2list; PFEA2 pFEA2; ULONG nLength2;#endif USHORT nLength; char szName[CCHMAXPATH]; int error; if ( ef_block == NULL || pEAblock -> nID != EF_OS2 ) return PK_OK; /* not an OS/2 extra field: assume OK */ if ( pEAblock->nSize < 4 || (pEAblock->lSize > 0L && pEAblock->nSize <= 10) ) return IZ_EF_TRUNC; /* no compressed data! */ strcpy(szName, path); nLength = strlen(szName); if (szName[nLength - 1] == '/') szName[nLength - 1] = 0; if ( (pFEA2list = (PFEA2LIST) malloc((size_t) pEAblock -> lSize)) == NULL ) return PK_MEM4; if ( (error = memextract(__G__ (uch *)pFEA2list, pEAblock->lSize, (uch *)(pEAblock+1), (ulg)(pEAblock->nSize - 4))) != PK_OK ) { free(pFEA2list); return error; }#ifdef __32BIT__ eaop.fpGEA2List = NULL; eaop.fpFEA2List = pFEA2list;#else pFEAlist = (PVOID) pFEA2list; pFEA2 = pFEA2list -> list; pFEA = pFEAlist -> list; do { nLength2 = pFEA2 -> oNextEntryOffset; nLength = sizeof(FEA) + pFEA2 -> cbName + 1 + pFEA2 -> cbValue; memcpy(pFEA, (PCH) pFEA2 + sizeof(pFEA2 -> oNextEntryOffset), nLength); pFEA2 = (PFEA2) ((PCH) pFEA2 + nLength2); pFEA = (PFEA) ((PCH) pFEA + nLength); } while ( nLength2 != 0 ); pFEAlist -> cbList = (PCH) pFEA - (PCH) pFEAlist; eaop.fpGEAList = NULL; eaop.fpFEAList = pFEAlist;#endif eaop.oError = 0; DosSetPathInfo(szName, FIL_QUERYEASIZE, (PBYTE) &eaop, sizeof(eaop), 0); if (!uO.tflag && QCOND2) Info(slide, 0, ((char *)slide, " (%ld bytes EAs)", pFEA2list -> cbList)); free(pFEA2list); return PK_COOL;}static int SetACL(__GPRO__ const char *path, void *ef_block){ /* returns almost-PK errors */ EFHEADER *pACLblock = (PEFHEADER) ef_block; char *szACL; int error; if ( ef_block == NULL || pACLblock -> nID != EF_ACL ) return PK_OK; /* not an OS/2 extra field: assume OK */ if (pACLblock->nSize < 4 || (pACLblock->lSize > 0L && pACLblock->nSize <= 10)) return IZ_EF_TRUNC; /* no compressed data! */ if ( (szACL = malloc((size_t) pACLblock -> lSize)) == NULL ) return PK_MEM4; if ( (error = memextract(__G__ (uch *)szACL, pACLblock->lSize, (uch *)(pACLblock+1), (ulg)(pACLblock->nSize - 4))) != PK_OK ) { free(szACL); return error; } if (acl_set(NULL, path, szACL) == 0) if (!uO.tflag && QCOND2) Info(slide, 0, ((char *)slide, " (%ld bytes ACL)", strlen(szACL))); free(szACL); return PK_COOL;}#ifdef SFXchar *GetLoadPath(__GPRO){#ifdef __32BIT__ /* generic for 32-bit API */ PTIB pptib; PPIB pppib; char *szPath; DosGetInfoBlocks(&pptib, &pppib); szPath = pppib -> pib_pchenv;#else /* 16-bit, note: requires large data model */ SEL selEnv; USHORT offCmd; char *szPath; DosGetEnv(&selEnv, &offCmd); szPath = MAKEP(selEnv, 0);#endif while (*szPath) /* find end of process environment */ szPath = strchr(szPath, 0) + 1; return szPath + 1; /* .exe file name follows environment */} /* end function GetLoadPath() */#else /* !SFX */DIR *opendir(__GPRO__ const char *name){ struct stat statb; DIR *dirp; char c; char *s; struct _dircontents *dp; char nbuf[MAXPATHLEN + 1]; int len; strcpy(nbuf, name); if ((len = strlen(nbuf)) == 0) return NULL; if ( ((c = nbuf[len - 1]) == '\\' || c == '/') && (len > 1) ) { nbuf[len - 1] = 0; --len; if ( nbuf[len - 1] == ':' ) { strcpy(nbuf+len, "\\."); len += 2; } } else if ( nbuf[len - 1] == ':' ) { strcpy(nbuf+len, "."); ++len; } /* GRR: Borland and Watcom C return non-zero on wildcards... < 0 ? */ if (stat(nbuf, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR) { Trace((stderr, "opendir: stat(%s) returns negative or not directory\n", FnFilter1(nbuf))); return NULL; } if ( (dirp = malloc(sizeof(DIR))) == NULL ) return NULL; if ( nbuf[len - 1] == '.' && (len == 1 || nbuf[len - 2] != '.') ) strcpy(nbuf+len-1, "*"); else if ( ((c = nbuf[len - 1]) == '\\' || c == '/') && (len == 1) ) strcpy(nbuf+len, "*"); else strcpy(nbuf+len, "\\*"); /* len is no longer correct (but no longer needed) */ Trace((stderr, "opendir: nbuf = [%s]\n", FnFilter1(nbuf))); dirp -> dd_loc = 0; dirp -> dd_contents = dirp -> dd_cp = NULL; if ((s = getdirent(__G__ nbuf)) == NULL) return dirp; do { if (((dp = malloc(sizeof(struct _dircontents))) == NULL) || ((dp -> _d_entry = malloc(strlen(s) + 1)) == NULL) ) { if (dp) free(dp); free_dircontents(dirp -> dd_contents); return NULL; } if (dirp -> dd_contents) { dirp -> dd_cp -> _d_next = dp; dirp -> dd_cp = dirp -> dd_cp -> _d_next; } else dirp -> dd_contents = dirp -> dd_cp = dp; strcpy(dp -> _d_entry, s); dp -> _d_next = NULL; dp -> _d_size = G.os2.find.cbFile; dp -> _d_mode = G.os2.find.attrFile; dp -> _d_time = *(unsigned *) &(G.os2.find.ftimeLastWrite); dp -> _d_date = *(unsigned *) &(G.os2.find.fdateLastWrite); } while ((s = getdirent(__G__ NULL)) != NULL); dirp -> dd_cp = dirp -> dd_contents; return dirp;}void closedir(DIR * dirp){ free_dircontents(dirp -> dd_contents); free(dirp);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -