static jlong File_lastModifiedImpl(JNIEnv* env, jclass, jstring javaPath) { struct stat sb; if (!doStat(env, javaPath, sb)) { return 0; } return static_cast<jlong>(sb.st_mtime) * 1000L; }
static jlong java_io_File_lastModifiedImpl(JNIEnv* env, jobject, jbyteArray pathBytes) { struct stat sb; if (!doStat(env, pathBytes, sb)) { return 0; } return static_cast<jlong>(sb.st_mtime) * 1000L; }
uint QFileInfo::groupId() const { if ( !fic || !cache ) doStat(); if ( fic ) return fic->st.st_gid; return nobodyID; }
uint QFileInfo::size() const { if ( !fic || !cache ) doStat(); if ( fic ) return (uint)fic->st.st_size; else return 0; }
QDateTime QFileInfo::lastRead() const { QDateTime dt; if ( !fic || !cache ) doStat(); if ( fic ) dt.setTime_t( fic->st.st_atime ); return dt; }
/*! \internal */ qint64 QFSFileEnginePrivate::sizeFdFh() const { Q_Q(const QFSFileEngine); const_cast<QFSFileEngine *>(q)->flush(); tried_stat = 0; metaData.clearFlags(QFileSystemMetaData::SizeAttribute); if (!doStat(QFileSystemMetaData::SizeAttribute)) return 0; return metaData.size(); }
/*! \internal */ bool QFSFileEnginePrivate::isSequentialFdFh() const { if (!tried_stat) doStat(); if (could_stat) { #ifdef Q_OS_UNIX return (st.st_mode & S_IFMT) != S_IFREG; // ### WINDOWS! #endif } return true; }
QIODevice::Offset QFileInfo::size() const #else uint QFileInfo::size() const #endif { if ( !fic || !cache ) doStat(); if ( fic ) #if defined(QT_ABI_QT4) return (QIODevice::Offset)fic->st.st_size; #elif defined(QT_LARGEFILE_SUPPORT) return (uint)fic->st.st_size > UINT_MAX ? UINT_MAX : (uint)fic->st.st_size; #else return (uint)fic->st.st_size; #endif else return 0;
bool QFileInfo::isSymLink() const { if ( !fic || !cache ) doStat(); if(symLink) return TRUE; #if !defined(QWS) && defined(Q_OS_MAC) { FSRef fref; if(FSPathMakeRef((const UInt8 *)QFile::encodeName(fn).data(), &fref, NULL) == noErr) { Boolean isAlias, isFolder; if(FSIsAliasFile(&fref, &isAlias, &isFolder) == noErr) return isAlias; } } #endif return FALSE; }
bool QFileInfo::permission( int permissionSpec ) const { if ( !fic || !cache ) doStat(); if ( fic ) { uint mask = 0; if ( permissionSpec & ReadOwner ) mask |= S_IRUSR; if ( permissionSpec & WriteOwner ) mask |= S_IWUSR; if ( permissionSpec & ExeOwner ) mask |= S_IXUSR; if ( permissionSpec & ReadUser ) mask |= S_IRUSR; if ( permissionSpec & WriteUser ) mask |= S_IWUSR; if ( permissionSpec & ExeUser ) mask |= S_IXUSR; if ( permissionSpec & ReadGroup ) mask |= S_IRGRP; if ( permissionSpec & WriteGroup ) mask |= S_IWGRP; if ( permissionSpec & ExeGroup ) mask |= S_IXGRP; if ( permissionSpec & ReadOther ) mask |= S_IROTH; if ( permissionSpec & WriteOther ) mask |= S_IWOTH; if ( permissionSpec & ExeOther ) mask |= S_IXOTH; if ( mask ) { return (fic->st.st_mode & mask) == mask; } else { #if defined(QT_CHECK_NULL) qWarning( "QFileInfo::permission: permissionSpec is 0" ); #endif return TRUE; } } else { return FALSE; } }
/* \internal */ qint64 QFSFileEnginePrivate::nativeSize() const { Q_Q(const QFSFileEngine); QFSFileEngine *thatQ = const_cast<QFSFileEngine *>(q); // ### Don't flush; for buffered files, we should get away with ftell. thatQ->flush(); // Always retrive the current information metaData.clearFlags(QFileSystemMetaData::SizeAttribute); #if defined(Q_OS_WINCE) // Buffered stdlib mode. if (fh) { QT_OFF_T oldPos = QT_FTELL(fh); QT_FSEEK(fh, 0, SEEK_END); qint64 fileSize = (qint64)QT_FTELL(fh); QT_FSEEK(fh, oldPos, SEEK_SET); if (fileSize == -1) { fileSize = 0; thatQ->setError(QFile::UnspecifiedError, qt_error_string(errno)); } return fileSize; } if (fd != -1) { thatQ->setError(QFile::UnspecifiedError, QLatin1String("Not implemented!")); return 0; } #endif bool filled = false; if (fileHandle != INVALID_HANDLE_VALUE && openMode != QIODevice::NotOpen ) filled = QFileSystemEngine::fillMetaData(fileHandle, metaData, QFileSystemMetaData::SizeAttribute); else filled = doStat(QFileSystemMetaData::SizeAttribute); if (!filled) { thatQ->setError(QFile::UnspecifiedError, qt_error_string(errno)); return 0; } return metaData.size(); }
static jlong File_lengthImpl(JNIEnv* env, jclass, jstring javaPath) { struct stat sb; if (!doStat(env, javaPath, sb)) { // We must return 0 for files that don't exist. // TODO: shouldn't we throw an IOException for ELOOP or EACCES? return 0; } /* * This android-changed code explicitly treats non-regular files (e.g., * sockets and block-special devices) as having size zero. Some synthetic * "regular" files may report an arbitrary non-zero size, but * in these cases they generally report a block count of zero. * So, use a zero block count to trump any other concept of * size. * * TODO: why do we do this? */ if (!S_ISREG(sb.st_mode) || sb.st_blocks == 0) { return 0; } return sb.st_size; }
void grepp(struct mesg_t data,struct sockaddr_in respondto) { doStat(); if (strncmp(data.mes,"req",3)==0) { sendmsgto(respondto,dnsIncoming); } if (strncmp(data.mes,"res",3)==0) { sendmsgto(respondto,dnsOutgoing); } if (strncmp(data.mes,"st_ifdrop",9)==0) { sendmsgto(respondto,ps_ifdrop); } if (strncmp(data.mes,"st_drop",7)==0) { sendmsgto(respondto,ps_drop); } if (strncmp(data.mes,"st_recv",7)==0) { sendmsgto(respondto,ps_recv); } if (strncmp(data.mes,"time_t",6)==0) { sendmsgto(respondto,dnsRTT.tiny); } if (strncmp(data.mes,"time_s",6)==0) { sendmsgto(respondto,dnsRTT.small); } if (strncmp(data.mes,"time_l",6)==0) { sendmsgto(respondto,dnsRTT.litle); } if (strncmp(data.mes,"time_m",6)==0) { sendmsgto(respondto,dnsRTT.middle); } if (strncmp(data.mes,"time_b",6)==0) { sendmsgto(respondto,dnsRTT.big); } if (strncmp(data.mes,"time_h",6)==0) { sendmsgto(respondto,dnsRTT.huge); } }
bool QFileInfo::isSymLink() const { if ( !fic || !cache ) doStat(); return fic ? fic->isSymLink : FALSE; }
bool QFileInfo::isDir() const { if ( !fic || !cache ) doStat(); return fic ? (fic->st.st_mode & STAT_MASK) == STAT_DIR : FALSE; }
uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags) { Q_Q(QFSFileEngine); Q_UNUSED(flags); if (openMode == QIODevice::NotOpen) { q->setError(QFile::PermissionsError, qt_error_string(int(EACCES))); return 0; } if (offset < 0 || offset != qint64(QT_OFF_T(offset)) || size < 0 || quint64(size) > quint64(size_t(-1))) { q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL))); return 0; } // If we know the mapping will extend beyond EOF, fail early to avoid // undefined behavior. Otherwise, let mmap have its say. if (doStat(QFileSystemMetaData::SizeAttribute) && (QT_OFF_T(size) > metaData.size() - QT_OFF_T(offset))) qWarning("QFSFileEngine::map: Mapping a file beyond its size is not portable"); int access = 0; if (openMode & QIODevice::ReadOnly) access |= PROT_READ; if (openMode & QIODevice::WriteOnly) access |= PROT_WRITE; int sharemode = MAP_SHARED; if (flags & QFileDevice::MapPrivateOption) { sharemode = MAP_PRIVATE; access |= PROT_WRITE; } #if defined(Q_OS_INTEGRITY) int pageSize = sysconf(_SC_PAGESIZE); #else int pageSize = getpagesize(); #endif int extra = offset % pageSize; if (quint64(size + extra) > quint64((size_t)-1)) { q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL))); return 0; } size_t realSize = (size_t)size + extra; QT_OFF_T realOffset = QT_OFF_T(offset); realOffset &= ~(QT_OFF_T(pageSize - 1)); void *mapAddress = QT_MMAP((void*)0, realSize, access, sharemode, nativeHandle(), realOffset); if (MAP_FAILED != mapAddress) { uchar *address = extra + static_cast<uchar*>(mapAddress); maps[address] = QPair<int,size_t>(extra, realSize); return address; } switch(errno) { case EBADF: q->setError(QFile::PermissionsError, qt_error_string(int(EACCES))); break; case ENFILE: case ENOMEM: q->setError(QFile::ResourceError, qt_error_string(int(errno))); break; case EINVAL: // size are out of bounds default: q->setError(QFile::UnspecifiedError, qt_error_string(int(errno))); break; } return 0; }
uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags) { Q_Q(QFSFileEngine); Q_UNUSED(flags); if (openMode == QIODevice::NotOpen) { q->setError(QFile::PermissionsError, qt_error_string(int(EACCES))); return 0; } if (offset < 0 || offset != qint64(QT_OFF_T(offset)) || size < 0 || quint64(size) > quint64(size_t(-1))) { q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL))); return 0; } // If we know the mapping will extend beyond EOF, fail early to avoid // undefined behavior. Otherwise, let mmap have its say. if (doStat(QFileSystemMetaData::SizeAttribute) && (QT_OFF_T(size) > metaData.size() - QT_OFF_T(offset))) qWarning("QFSFileEngine::map: Mapping a file beyond its size is not portable"); int access = 0; if (openMode & QIODevice::ReadOnly) access |= PROT_READ; if (openMode & QIODevice::WriteOnly) access |= PROT_WRITE; #if defined(Q_OS_INTEGRITY) int pageSize = sysconf(_SC_PAGESIZE); #else int pageSize = getpagesize(); #endif int extra = offset % pageSize; if (quint64(size + extra) > quint64((size_t)-1)) { q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL))); return 0; } size_t realSize = (size_t)size + extra; QT_OFF_T realOffset = QT_OFF_T(offset); realOffset &= ~(QT_OFF_T(pageSize - 1)); #ifdef QT_SYMBIAN_USE_NATIVE_FILEMAP TInt nativeMapError = KErrNone; RFileMap mapping; TUint mode(EFileMapRemovableMedia); TUint64 nativeOffset = offset & ~(mapping.PageSizeInBytes() - 1); //If the file was opened for write or read/write, then open the map for read/write if (openMode & QIODevice::WriteOnly) mode |= EFileMapWrite; if (symbianFile.SubSessionHandle()) { nativeMapError = mapping.Open(symbianFile, nativeOffset, size, mode); } else { //map file by name if we don't have a native handle QString fn = QFileSystemEngine::absoluteName(fileEntry).nativeFilePath(); TUint filemode = EFileShareReadersOrWriters | EFileRead; if (openMode & QIODevice::WriteOnly) filemode |= EFileWrite; nativeMapError = mapping.Open(qt_s60GetRFs(), qt_QString2TPtrC(fn), filemode, nativeOffset, size, mode); } if (nativeMapError == KErrNone) { QScopedResource<RFileMap> ptr(mapping); //will call Close if adding to mapping throws an exception uchar *address = mapping.Base() + (offset - nativeOffset); maps[address] = mapping; ptr.take(); return address; } QFile::FileError reportedError = QFile::UnspecifiedError; switch (nativeMapError) { case KErrAccessDenied: case KErrPermissionDenied: reportedError = QFile::PermissionsError; break; case KErrNoMemory: reportedError = QFile::ResourceError; break; } q->setError(reportedError, QSystemError(nativeMapError, QSystemError::NativeError).toString()); return 0; #else #ifdef Q_OS_SYMBIAN //older phones & emulator don't support native mapping, so need to keep the open C way around for those. void *mapAddress; TRAPD(err, mapAddress = QT_MMAP((void*)0, realSize, access, MAP_SHARED, getMapHandle(), realOffset)); if (err != KErrNone) { qWarning("OpenC bug: leave from mmap %d", err); mapAddress = MAP_FAILED; errno = EINVAL; } #else void *mapAddress = QT_MMAP((void*)0, realSize, access, MAP_SHARED, nativeHandle(), realOffset); #endif if (MAP_FAILED != mapAddress) { uchar *address = extra + static_cast<uchar*>(mapAddress); maps[address] = QPair<int,size_t>(extra, realSize); return address; } switch(errno) { case EBADF: q->setError(QFile::PermissionsError, qt_error_string(int(EACCES))); break; case ENFILE: case ENOMEM: q->setError(QFile::ResourceError, qt_error_string(int(errno))); break; case EINVAL: // size are out of bounds default: q->setError(QFile::UnspecifiedError, qt_error_string(int(errno))); break; } return 0; #endif }
static jboolean File_isFileImpl(JNIEnv* env, jclass, jstring javaPath) { struct stat sb; return (doStat(env, javaPath, sb) && S_ISREG(sb.st_mode)); }
int LiveCDFS::doReaddir(const char *name, struct directory *dir) { FUNC_START("name='%s', dir=%p", name, dir); if (!whiteout->isVisible(name)) { FUNC_RET("%d", -1, -1); } DIR *rdir = NULL, *tdir = NULL; struct lufs_fattr attr; struct dirent *ent; vector<string> entries; string rootpath = path->mkroot(name); string tmppath = path->mktmp(name); if ((tdir = opendir(tmppath.c_str()))) { while ((ent = readdir(tdir))) { string subpath = path->join(name, ent->d_name); if (whiteout->isVisible(subpath)) { TRACE("Adding direntry='%s'", ent->d_name); if ((doStat(subpath.c_str(), &attr)) < 0) { ERROR("Could not stat file='%s'", ent->d_name); closedir(rdir); FUNC_RET("%d", -1, -1); } lu_cache_add2dir(dir, ent->d_name, NULL, &attr); } entries.push_back(subpath); } closedir(tdir); } else { path->recurseMkdir(name); } if (whiteout->isVisible(name) && Path::exists(rootpath, S_IFDIR) && (rdir = opendir(rootpath.c_str()))) { while ((ent = readdir(rdir))){ string subpath = path->join(name, ent->d_name); bool found = false; vector<string>::iterator i = entries.begin(); while (!found && (i != entries.end())) { if (i->compare(subpath) == 0) { found = true; } i++; } if (!found && whiteout->isVisible(subpath)) { TRACE("Adding direntry='%s'", ent->d_name); if ((doStat(subpath.c_str(), &attr)) < 0) { ERROR("could not stat file='%s'", ent->d_name); closedir(rdir); FUNC_RET("%d", -1, -1); } lu_cache_add2dir(dir, ent->d_name, NULL, &attr); } } closedir(rdir); } else { WARN("could not open directory, name='%s'", name); } FUNC_RET("%d", 0, 0); }
static jboolean java_io_File_isFileImpl(JNIEnv* env, jobject, jbyteArray pathBytes) { struct stat sb; return (doStat(env, pathBytes, sb) && S_ISREG(sb.st_mode)); }
/*! Returns TRUE if this object points to a directory or to a symbolic link to a directory; otherwise returns FALSE. \sa isFile(), isSymLink() */ bool QFileInfo::isDir() const { if ( !fic || !cache ) doStat(); return fic ? (fic->st.st_mode & S_IFMT) == S_IFDIR : FALSE; }
static int SumGrps (AcsSumInfo *acs, char *mtype) { extern int status; SingleGroup x; /* first imset */ SingleGroupLine y; /* line from Nth imset */ double exptime; /* exposure time of current image */ double sumexptime = 0.; /* accumulated exposure time */ char *message; /* for printtime info */ int extver; /* imset number */ int i; /* counter for current image */ int chip, ychip; /*Chip being summed */ int extchip; /* Extension of chip being summed */ int line; /* Line of chip being summed */ char uroot[CHAR_FNAME_LENGTH]; /* Upper case version of rootname */ int doStat (SingleGroup *, short); void TimeStamp (char *, char *); void PrGrpBegin (char *, int); void PrGrpEnd (char *, int); void PrSwitch (char *, int); void UCalVer (Hdr *); void UFilename (char *, Hdr *); void UMemType (char *, Hdr *); void UExpname (char *, Hdr *); int DetCCDChip (char *, int, int, int *); void UpperAll (char *, char *, int); int GetKeyInt (Hdr *, char *, int, int, int *); int GetKeyDbl (Hdr *, char *, int, double, double *); int PutKeyStr (Hdr *, char *, char *, char *); initSingleGroup (&x); initSingleGroupLine (&y); if (acs->printtime) { if ((message = calloc (CHAR_LINE_LENGTH+1, sizeof (char))) == NULL) return (status = OUT_OF_MEMORY); } for (extver = 1; extver <= acs->nimsets; extver++) { PrGrpBegin ("imset", extver); getSingleGroup (acs->input[0], extver, &x); if (hstio_err()) return (status = OPEN_FAILED); if (acs->printtime) TimeStamp ("first imset read", acs->input[0]); /* get from x */ if (GetKeyInt (&x.sci.hdr, "CCDCHIP", USE_DEFAULT, 1, &chip)) return (status); if (GetKeyDbl (x.globalhdr, "EXPEND", NO_DEFAULT, 0., &acs->expend)) return (status); sumexptime = acs->exptime; /* Square the errors to convert to variance. */ SquareErr (&x); /* operate on x */ /* For each imset/extver, loop over all images */ for (i = 1; i < acs->nimages; i++) { /* Determine which extension corresponds to desired chip ** for the remainder of the images. */ extchip = 0; if (DetCCDChip(acs->input[i], chip, acs->nimsets, &extchip) ) { return (status); } /* Get the first line of bias image data. */ openSingleGroupLine (acs->input[i], extchip, &y); if (hstio_err()) return (status = OPEN_FAILED); /* Update exposure time info. */ /* get from y */ if (GetKeyInt (&y.sci.hdr, "CCDCHIP", USE_DEFAULT, 1, &ychip)) return (status); if (GetKeyDbl (y.globalhdr, "EXPTIME", NO_DEFAULT, 0., &exptime)) return (status); if (GetKeyDbl (y.globalhdr, "EXPEND", NO_DEFAULT, 0., &acs->expend)) return (status); sumexptime += exptime; /*Loop over lines in each subsequent image */ for (line = 0; line < x.sci.data.ny; line++) { status = getSingleGroupLine (acs->input[i], line, &y); if (status) { sprintf(MsgText,"Could not read line %d from image %d.",line+1,i+1); trlerror(MsgText); return (status = OPEN_FAILED); } SquareErrLine (&y); /* operate on y */ /* Add current imset to sum (i.e. add y to x). This differs from add2d in that RptSum adds variances, rather than adding errors in quadrature. */ if (RptSumLine (&x, line, &y)) return (status); } /*End loop over lines */ if (acs->printtime) { if (i == 1) strcpy (message, "1st imset added"); else if (i == 2) strcpy (message, "2nd imset added"); else if (i == 3) strcpy (message, "3rd imset added"); else sprintf (message, "%dth imset added", i); TimeStamp (message, acs->input[i]); } closeSingleGroupLine (&y); } /* End loop over images */ freeSingleGroupLine (&y); /* Take the square root of variance to convert back to errors. */ SqrtErr (&x); /* Compute statistics and update keywords in output headers. */ trlmessage ("\n"); if (doStat (&x, acs->sdqflags)) return (status); if (acs->printtime) TimeStamp ("Image statistics computed", acs->rootname); /* Update header info in output. */ if (PutSumHdrInfo (&x, sumexptime, acs->expend, acs->nimages, acs->nimsets)) return (status); /* Update CAL_VER and FILENAME, then write output file. EXPNAME values modified for all extensions in a SingleGroup. WJH 7 July 1999 */ UCalVer (x.globalhdr); UFilename (acs->output, x.globalhdr); UMemType (mtype, x.globalhdr); UExpname (acs->rootname, &x.sci.hdr); UExpname (acs->rootname, &x.err.hdr); UExpname (acs->rootname, &x.dq.hdr); UpperAll (acs->rootname, uroot, strlen(acs->rootname)+1 ); PutKeyStr (x.globalhdr, "ROOTNAME", uroot,"Rootname of the observation set"); putSingleGroup (acs->output, extver, &x, 0); if (hstio_err()) return (status = 1001); freeSingleGroup (&x); PrGrpEnd ("imset", extver); if (acs->printtime) TimeStamp ("Output written to disk", acs->rootname); } /* End loop over imsets */ if (acs->printtime) free (message); return (status); }
int __PHYSFS_platformExists(const char *fname) { struct stat statbuf; BAIL_IF_MACRO(doStat(fname, &statbuf) == -1, strerror(errno), 0); return(1); } /* __PHYSFS_platformExists */
bool QFSFileEnginePrivate::isSequentialFdFh() const { if (doStat(QFileSystemMetaData::SequentialType)) return metaData.isSequential(); return true; }