From: Tim Kientzle Date: Sun, 6 Sep 2009 18:15:11 +0000 (-0400) Subject: Remove some unused code. X-Git-Tag: v2.8.0~372 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ba43c6fb9244569473d99ee12447cd8656fd220;p=thirdparty%2Flibarchive.git Remove some unused code. SVN-Revision: 1436 --- diff --git a/cpio/cpio_windows.c b/cpio/cpio_windows.c index f2813c204..0fc8c898e 100644 --- a/cpio/cpio_windows.c +++ b/cpio/cpio_windows.c @@ -644,189 +644,6 @@ fileTimeToUTC(const FILETIME *filetime, time_t *time, long *ns) } } -/* Stat by handle - * Windows' stat() does not accept path which is added "\\?\" especially "?" - * character. - * It means we cannot access a long name path(which is longer than MAX_PATH). - * So I've implemented simular Windows' stat() to access the long name path. - * And I've added some feature. - * 1. set st_ino by nFileIndexHigh and nFileIndexLow of - * BY_HANDLE_FILE_INFORMATION. - * 2. set st_nlink by nNumberOfLinks of BY_HANDLE_FILE_INFORMATION. - * 3. set st_dev by dwVolumeSerialNumber by BY_HANDLE_FILE_INFORMATION. - */ -static int -__hstat(HANDLE handle, struct ustat *st) -{ - BY_HANDLE_FILE_INFORMATION info; - ULARGE_INTEGER ino64; - DWORD ftype; - mode_t mode; - time_t time; - long ns; - - switch (ftype = GetFileType(handle)) { - case FILE_TYPE_UNKNOWN: - errno = EBADF; - return (-1); - case FILE_TYPE_CHAR: - case FILE_TYPE_PIPE: - if (ftype == FILE_TYPE_CHAR) { - st->st_mode = S_IFCHR; - st->st_size = 0; - } else { - DWORD avail; - - st->st_mode = AE_IFIFO; - if (PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL)) - st->st_size = avail; - else - st->st_size = 0; - } - st->st_atime = 0; - st->st_atime_nsec = 0; - st->st_mtime = 0; - st->st_mtime_nsec = 0; - st->st_ctime = 0; - st->st_ctime_nsec = 0; - st->st_ino = 0; - st->st_nlink = 1; - st->st_uid = 0; - st->st_gid = 0; - st->st_rdev = 0; - st->st_dev = 0; - return (0); - case FILE_TYPE_DISK: - break; - default: - /* This ftype is undocumented type. */ - cpio_dosmaperr(GetLastError()); - return (-1); - } - - ZeroMemory(&info, sizeof(info)); - if (!GetFileInformationByHandle (handle, &info)) { - cpio_dosmaperr(GetLastError()); - return (-1); - } - - mode = 0444; - if ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0) - mode |= 0222; - if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - mode |= S_IFDIR | 0111; - else - mode |= S_IFREG; - st->st_mode = mode; - - fileTimeToUTC(&info.ftLastAccessTime, &time, &ns); - st->st_atime = time; - st->st_atime_nsec = ns; - fileTimeToUTC(&info.ftLastWriteTime, &time, &ns); - st->st_mtime = time; - st->st_mtime_nsec = ns; - fileTimeToUTC(&info.ftCreationTime, &time, &ns); - st->st_ctime = time; - st->st_ctime_nsec = ns; - st->st_size = - ((int64_t)(info.nFileSizeHigh) * ((int64_t)MAXDWORD + 1)) - + (int64_t)(info.nFileSizeLow); -#ifdef SIMULATE_WIN_STAT - st->st_ino = 0; - st->st_nlink = 1; - st->st_dev = 0; -#else - /* Getting FileIndex as i-node. We have to remove a sequence which - * is high-16-bits of nFileIndexHigh. */ - ino64.HighPart = info.nFileIndexHigh & 0x0000FFFFUL; - ino64.LowPart = info.nFileIndexLow; - st->st_ino = ino64.QuadPart; - st->st_nlink = info.nNumberOfLinks; - if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - ++st->st_nlink;/* Add parent directory. */ - st->st_dev = info.dwVolumeSerialNumber; -#endif - st->st_uid = 0; - st->st_gid = 0; - st->st_rdev = 0; - return (0); -} - -static void -copy_stat(struct stat *st, struct ustat *us) -{ - st->st_atime = us->st_atime; - st->st_ctime = us->st_ctime; - st->st_mtime = us->st_mtime; - st->st_gid = us->st_gid; - st->st_ino = getino(us); - st->st_mode = us->st_mode; - st->st_nlink = us->st_nlink; - st->st_size = us->st_size; - st->st_uid = us->st_uid; - st->st_dev = us->st_dev; - st->st_rdev = us->st_rdev; -} - -int -la_fstat(int fd, struct stat *st) -{ - struct ustat u; - int ret; - - if (fd < 0) { - errno = EBADF; - return (-1); - } - ret = __hstat((HANDLE)_get_osfhandle(fd), &u); - if (ret >= 0) { - copy_stat(st, &u); - if ((u.st_mode & AE_IFMT) == AE_IFCHR - || (u.st_mode & AE_IFMT) == AE_IFIFO) { - st->st_dev = fd; - st->st_rdev = fd; - } - } - return (ret); -} - -int -la_stat(const char *path, struct stat *st) -{ - HANDLE handle; - struct ustat u; - int ret; - - handle = la_CreateFile(path, 0, 0, NULL, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_READONLY, - NULL); - if (handle == INVALID_HANDLE_VALUE) { - cpio_dosmaperr(GetLastError()); - return (-1); - } - ret = __hstat(handle, &u); - CloseHandle(handle); - if (ret >= 0) { - char *p; - - copy_stat(st, &u); - p = strrchr(path, '.'); - if (p != NULL && strlen(p) == 4) { - char exttype[4]; - - ++ p; - exttype[0] = toupper(*p++); - exttype[1] = toupper(*p++); - exttype[2] = toupper(*p++); - exttype[3] = '\0'; - if (!strcmp(exttype, "EXE") || !strcmp(exttype, "CMD") || - !strcmp(exttype, "BAT") || !strcmp(exttype, "COM")) - st->st_mode |= 0111; - } - } - return (ret); -} - ssize_t la_write(int fd, const void *buf, size_t nbytes) {