?? win32.c
字號:
if (gotTime) { FILETIME *pModft = (gotTime & EB_UT_FL_MTIME) ? &Modft : NULL; FILETIME *pAccft = (gotTime & EB_UT_FL_ATIME) ? &Accft : NULL; FILETIME *pCreft = (gotTime & EB_UT_FL_CTIME) ? &Creft : NULL; if (!SetFileTime(hFile, pCreft, pAccft, pModft)) Info(slide, 0, ((char *)slide, "\nSetFileTime failed: %d\n", (int)GetLastError())); } CloseHandle(hFile); } return;#undef Ansi_Fname} /* end function close_outfile() */#ifdef TIMESTAMP/*************************//* Function stamp_file() *//*************************/int stamp_file(__GPRO__ ZCONST char *fname, time_t modtime){ FILETIME Modft; /* File time type defined in NT, `last modified' time */ HANDLE hFile; /* File handle defined in NT */ int errstat = 0; /* return status: 0 == "OK", -1 == "Failure" */#ifndef NT_TZBUG_WORKAROUND time_t utime_dosmin; /* internal variable for UTIME_BOUNDCHECK_1 */#endif int fs_uses_loctime = FStampIsLocTime(__G__ fname);#ifdef __RSXNT__ /* RSXNT/EMX C rtl uses OEM charset */ char *ansi_name = (char *)alloca(strlen(fname) + 1); INTERN_TO_ISO(fname, ansi_name);# define Ansi_Fname ansi_name#else# define Ansi_Fname fname#endif /* open a handle to the file to prepare setting the mod-time stamp */ hFile = CreateFile(Ansi_Fname, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( hFile == INVALID_HANDLE_VALUE ) { errstat = -1; } else { /* convert time_t modtime into WIN32 native 64bit format */ UTIME_BOUNDCHECK_1(modtime) utime2FileTime(modtime, &Modft); NT_TZBUG_PRECOMPENSATE(modtime, &Modft) /* set Access and Modification times of the file to modtime */ if (!SetFileTime(hFile, NULL, &Modft, &Modft)) { errstat = -1; } CloseHandle(hFile); } return errstat;#undef Ansi_Fname} /* end function stamp_file() */#endif /* TIMESTAMP *//***********************//* Function isfloppy() */ /* more precisely, is it removable? *//***********************/static int isfloppy(int nDrive) /* 1 == A:, 2 == B:, etc. */{ char rootPathName[4]; rootPathName[0] = (char)('A' + nDrive - 1); /* build the root path */ rootPathName[1] = ':'; /* name, e.g. "A:/" */ rootPathName[2] = '/'; rootPathName[3] = '\0'; return (GetDriveType(rootPathName) == DRIVE_REMOVABLE);} /* end function isfloppy() *//*****************************//* Function NTQueryVolInfo() *//*****************************//* * Note: 8.3 limits on filenames apply only to old-style FAT filesystems. * More recent versions of Windows (Windows NT 3.5 / Windows 4.0) * can support long filenames (LFN) on FAT filesystems. Check the * filesystem maximum component length field to detect LFN support. */static int NTQueryVolInfo(__GPRO__ const char *name){ /* static char lastRootPath[4] = ""; */ /* static int lastVolOldFAT; */ /* static int lastVolLocTim; */ char *tmp0; char tmp1[MAX_PATH], tmp2[MAX_PATH]; unsigned volSerNo, maxCompLen, fileSysFlags;#ifdef __RSXNT__ /* RSXNT/EMX C rtl uses OEM charset */ char *ansi_name = (char *)alloca(strlen(name) + 1); INTERN_TO_ISO(name, ansi_name); name = ansi_name;#endif if ((!strncmp(name, "//", 2) || !strncmp(name,"\\\\", 2)) && (name[2] != '\0' && name[2] != '/' && name[2] != '\\')) { /* GetFullPathname() and GetVolumeInformation() do not work * on UNC names. For now, we return "error". * **FIXME**: check if UNC name is mapped to a drive letter * and use mapped drive for volume info query. */ return FALSE; } if (isalpha((uch)name[0]) && (name[1] == ':')) tmp0 = (char *)name; else { if (!GetFullPathName(name, MAX_PATH, tmp1, &tmp0)) return FALSE; tmp0 = &tmp1[0]; } if (strncmp(G.lastRootPath, tmp0, 2) != 0) { /* For speed, we skip repeated queries for the same device */ strncpy(G.lastRootPath, tmp0, 2); /* Build the root path name, */ G.lastRootPath[2] = '/'; /* e.g. "A:/" */ G.lastRootPath[3] = '\0'; if (!GetVolumeInformation((LPCTSTR)G.lastRootPath, (LPTSTR)tmp1, (DWORD)MAX_PATH, (LPDWORD)&volSerNo, (LPDWORD)&maxCompLen, (LPDWORD)&fileSysFlags, (LPTSTR)tmp2, (DWORD)MAX_PATH)) { G.lastRootPath[0] = '\0'; return FALSE; } /* LFNs are available if the component length is > 12 */ G.lastVolOldFAT = (maxCompLen <= 12);/* G.lastVolOldFAT = !strncmp(strupr(tmp2), "FAT", 3); old version */ /* Volumes in (V)FAT and (OS/2) HPFS format store file timestamps in * local time! */ G.lastVolLocTim = !strncmp(strupr(tmp2), "VFAT", 4) || !strncmp(tmp2, "HPFS", 4) || !strncmp(tmp2, "FAT", 3); } return TRUE;} /* end function NTQueryVolInfo() *//*****************************//* Function IsVolumeOldFAT() *//*****************************/static int IsVolumeOldFAT(__GPRO__ const char *name){ return (NTQueryVolInfo(__G__ name) ? G.lastVolOldFAT : FALSE);}#ifndef SFX/************************//* Function do_wild() */ /* identical to OS/2 version *//************************/char *do_wild(__G__ wildspec) __GDEF ZCONST char *wildspec; /* only used first time on a given dir */{/* these statics are now declared in SYSTEM_SPECIFIC_GLOBALS in w32cfg.h: static zDIR *wild_dir = NULL; static ZCONST char *wildname; static char *dirname, matchname[FILNAMSIZ]; static int notfirstcall=FALSE, have_dirname, dirnamelen;*/ char *fnamestart; struct zdirent *file; /* Even when we're just returning wildspec, we *always* do so in * matchname[]--calling routine is allowed to append four characters * to the returned string, and wildspec may be a pointer to argv[]. */ if (!G.notfirstcall) { /* first call: must initialize everything */ G.notfirstcall = TRUE; if (!iswild(wildspec)) { strcpy(G.matchname, wildspec); G.have_dirname = FALSE; G.wild_dir = NULL; return G.matchname; } /* break the wildspec into a directory part and a wildcard filename */ if ((G.wildname = MBSRCHR(wildspec, '/')) == (ZCONST char *)NULL && (G.wildname = MBSRCHR(wildspec, ':')) == (ZCONST char *)NULL) { G.dirname = "."; G.dirnamelen = 1; G.have_dirname = FALSE; G.wildname = wildspec; } else { ++G.wildname; /* point at character after '/' or ':' */ G.dirnamelen = G.wildname - wildspec; if ((G.dirname = (char *)malloc(G.dirnamelen+1)) == NULL) { Info(slide, 1, ((char *)slide, "warning: cannot allocate wildcard buffers\n")); strcpy(G.matchname, wildspec); return G.matchname; /* but maybe filespec was not a wildcard */ } strncpy(G.dirname, wildspec, G.dirnamelen); G.dirname[G.dirnamelen] = '\0'; /* terminate for strcpy below */ G.have_dirname = TRUE; } Trace((stderr, "do_wild: dirname = [%s]\n", FnFilter1(G.dirname))); if ((G.wild_dir = (zvoid *)Opendir(G.dirname)) != NULL) { if (G.have_dirname) { strcpy(G.matchname, G.dirname); fnamestart = G.matchname + G.dirnamelen; } else fnamestart = G.matchname; while ((file = Readdir((zDIR *)G.wild_dir)) != NULL) { Trace((stderr, "do_wild: Readdir returns %s\n", FnFilter1(file->d_name))); strcpy(fnamestart, file->d_name); if (MBSRCHR(fnamestart, '.') == (char *)NULL) strcat(fnamestart, "."); if (match(fnamestart, G.wildname, 1) && /* 1 == ignore case */ /* skip "." and ".." directory entries */ strcmp(fnamestart, ".") && strcmp(fnamestart, "..")) { Trace((stderr, "do_wild: match() succeeds\n")); /* remove trailing dot */ fnamestart = plastchar(fnamestart, strlen(fnamestart)); if (*fnamestart == '.') *fnamestart = '\0'; return G.matchname; } } /* if we get to here directory is exhausted, so close it */ Closedir((zDIR *)G.wild_dir); G.wild_dir = NULL; } Trace((stderr, "do_wild: Opendir(%s) returns NULL\n", FnFilter1(G.dirname))); /* return the raw wildspec in case that works (e.g., directory not * searchable, but filespec was not wild and file is readable) */ strcpy(G.matchname, wildspec); return G.matchname; } /* last time through, might have failed opendir but returned raw wildspec */ if (G.wild_dir == NULL) { G.notfirstcall = FALSE; /* reset for new wildspec */ if (G.have_dirname) free(G.dirname); return (char *)NULL; } /* If we've gotten this far, we've read and matched at least one entry * successfully (in a previous call), so dirname has been copied into * matchname already. */ if (G.have_dirname) { /* strcpy(G.matchname, G.dirname); */ fnamestart = G.matchname + G.dirnamelen; } else fnamestart = G.matchname; while ((file = Readdir((zDIR *)G.wild_dir)) != NULL) { Trace((stderr, "do_wild: readdir returns %s\n", FnFilter1(file->d_name))); strcpy(fnamestart, file->d_name); if (MBSRCHR(fnamestart, '.') == (char *)NULL) strcat(fnamestart, "."); if (match(fnamestart, G.wildname, 1)) { /* 1 == ignore case */ Trace((stderr, "do_wild: match() succeeds\n")); /* remove trailing dot */ fnamestart = plastchar(fnamestart, strlen(fnamestart)); if (*fnamestart == '.') *fnamestart = '\0'; return G.matchname; } } Closedir((zDIR *)G.wild_dir); /* at least one entry read; nothing left */ G.wild_dir = NULL; G.notfirstcall = FALSE; /* reset for new wildspec */ if (G.have_dirname) free(G.dirname); return (char *)NULL;} /* end function do_wild() */#endif /* !SFX *//**********************//* Function mapattr() *//**********************//* Identical to MS-DOS, OS/2 versions. However, NT has a lot of extra * permission stuff, so this function should probably be extended in the * future. */int mapattr(__G) __GDEF{ /* set archive bit for file entries (file is not backed up): */ G.pInfo->file_attr = ((unsigned)G.crec.external_file_attributes | (G.crec.external_file_attributes & FILE_ATTRIBUTE_DIRECTORY ? 0 : FILE_ATTRIBUTE_ARCHIVE)) & 0xff; return 0;} /* end function mapattr() *//************************//* Function mapname() *//************************/int mapname(__G__ renamed) __GDEF int renamed;/* * returns: * MPN_OK - no problem detected * MPN_INF_TRUNC - caution (truncated filename) * MPN_INF_SKIP - info "skip entry" (dir doesn't exist) * MPN_ERR_SKIP - error -> skip entry * MPN_ERR_TOOLONG - error -> path is too long * MPN_NOMEM - error (memory allocation failed) -> skip entry * [also MPN_VOL_LABEL, MPN_CREATED_DIR] */{ char pathcomp[FILNAMSIZ]; /* path-component buffer */ char *pp, *cp=NULL; /* character pointers */ char *lastsemi = NULL; /* pointer to last semi-colon in pathcomp */#ifdef ACORN_FTYPE_NFS char *lastcomma=(char *)NULL; /* pointer to last comma in pathcomp */ RO_extra_block *ef_spark; /* pointer Acorn FTYPE ef block */#endif int killed_ddot = FALSE; /* is set when skipping "../" pathcomp */ int error; register unsigned workch; /* hold the character being tested *//*--------------------------------------------------------------------------- Initialize various pointers and counters and stuff. ---------------------------------------------------------------------------*/ /* can create path as long as not just freshening, or if user told us */ G.create_dirs = (!uO.fflag || renamed); G.created_dir = FALSE; /* not yet */ G.renamed_fullpath = FALSE; G.fnlen = strlen(G.filename); if (renamed) { cp = G.filename; /* point to beginning of renamed name... */ if (*cp) do { if (*cp == '\\') /* convert backslashes to forward */ *cp = '/'; } while (*PREINCSTR(cp)); cp = G.filename; /* use temporary rootpath if user gave full pathname */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -