Exemplo n.º 1
0
static int
filstat(char *nm, enum token mode)
{
	struct stat64 s;

	if (mode == FILSYM ? lstat64(nm, &s) : stat64(nm, &s))
		return 0;

	switch (mode) {
#ifndef HAVE_FACCESSAT
	case FILRD:
		return test_st_mode(&s, R_OK);
	case FILWR:
		return test_st_mode(&s, W_OK);
	case FILEX:
		return test_st_mode(&s, X_OK);
#endif
	case FILEXIST:
		return 1;
	case FILREG:
		return S_ISREG(s.st_mode);
	case FILDIR:
		return S_ISDIR(s.st_mode);
	case FILCDEV:
		return S_ISCHR(s.st_mode);
	case FILBDEV:
		return S_ISBLK(s.st_mode);
	case FILFIFO:
		return S_ISFIFO(s.st_mode);
	case FILSOCK:
		return S_ISSOCK(s.st_mode);
	case FILSYM:
		return S_ISLNK(s.st_mode);
	case FILSUID:
		return (s.st_mode & S_ISUID) != 0;
	case FILSGID:
		return (s.st_mode & S_ISGID) != 0;
	case FILSTCK:
		return (s.st_mode & S_ISVTX) != 0;
	case FILGZ:
		return !!s.st_size;
	case FILUID:
		return s.st_uid == geteuid();
	case FILGID:
		return s.st_gid == getegid();
	default:
		return 1;
	}
}
Exemplo n.º 2
0
BOOL   FindNextFile(HANDLE hHandle, LPWIN32_FIND_DATA lpFindData)
{
  if (lpFindData == NULL || hHandle == NULL || hHandle->GetType() != CXHandle::HND_FIND_FILE)
    return FALSE;

  if ((unsigned int) hHandle->m_nFindFileIterator >= hHandle->m_FindFileResults.size())
    return FALSE;

  CStdString strFileName = hHandle->m_FindFileResults[hHandle->m_nFindFileIterator++];
  CStdString strFileNameTest = hHandle->m_FindFileDir + strFileName;

  if (IsAliasShortcut(strFileNameTest))
    TranslateAliasShortcut(strFileNameTest);

  struct stat64 fileStat;
  memset(&fileStat, 0, sizeof(fileStat));
 
  if (stat64(strFileNameTest, &fileStat) == -1)
    return FALSE;

  bool bIsDir = false;
  if (S_ISDIR(fileStat.st_mode))
  {
    bIsDir = true;
  }

  memset(lpFindData,0,sizeof(WIN32_FIND_DATA));

  lpFindData->dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
  strcpy(lpFindData->cFileName, strFileName.c_str());

  if (bIsDir)
    lpFindData->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;

  if (strFileName[0] == '.')
    lpFindData->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN;

  if (access(strFileName, R_OK) == 0 && access(strFileName, W_OK) != 0)
    lpFindData->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;

  TimeTToFileTime(fileStat.st_ctime, &lpFindData->ftCreationTime);
  TimeTToFileTime(fileStat.st_atime, &lpFindData->ftLastAccessTime);
  TimeTToFileTime(fileStat.st_mtime, &lpFindData->ftLastWriteTime);

  lpFindData->nFileSizeHigh = (DWORD)(fileStat.st_size >> 32);
  lpFindData->nFileSizeLow =  (DWORD)fileStat.st_size;

  return TRUE;
}
Exemplo n.º 3
0
int eDVRPlayerThread::FillSliceSizes()
{
	slicesizes.clear();
	struct stat64 s;
	int filelength=0;
	int slice = 0;
	while (!stat64((filename + (slice ? eString().sprintf(".%03d", slice) : eString(""))).c_str(), &s))
	{
		filelength+=s.st_size/1880;
		slicesizes.push_back(s.st_size);
		slice++;
	}
	//eDebug("FillSliceSizes:%s,%d",filename.c_str(),filelength);
	return filelength;
}
Exemplo n.º 4
0
int os_file_type(char *file)
{
	struct stat64 buf;

	if(stat64(file, &buf) == -1)
		return(-errno);

	if(S_ISDIR(buf.st_mode)) return(OS_TYPE_DIR);
	else if(S_ISLNK(buf.st_mode)) return(OS_TYPE_SYMLINK);
	else if(S_ISCHR(buf.st_mode)) return(OS_TYPE_CHARDEV);
	else if(S_ISBLK(buf.st_mode)) return(OS_TYPE_BLOCKDEV);
	else if(S_ISFIFO(buf.st_mode)) return(OS_TYPE_FIFO);
	else if(S_ISSOCK(buf.st_mode)) return(OS_TYPE_SOCK);
	else return(OS_TYPE_FILE);
}
int
VisItStat(const char *file_name, VisItStat_t *buf)
{
#if defined(_WIN32)
   return _stat(file_name, buf);
#else

#if SIZEOF_OFF64_T > 4
    return stat64(file_name, buf);
#else
    return stat(file_name, buf);
#endif

#endif
}
Exemplo n.º 6
0
/*
 *  Verify that a file exists or can be created.
 */
boolean_t
verify_file(
	const char *file,	/* file or directory name */
	boolean_t dir_is_suff)	/* if true only directory must exist */
{

	char *dupfile;
	char *path;
	struct stat64 buf;
	boolean_t rc = B_FALSE;

	/*
	 *	Must be a fully qualified path name.
	 */
	if (*file == '/') {
		/*
		 *	A file that already exists is good.
		 */
		if (stat64(file, &buf) == 0) {
			rc = B_TRUE;

		} else if (dir_is_suff) {
			/*
			 *	Check if valid directory.
			 */
			dupfile = strdup(file);
			path = dirname(dupfile);
			if (stat64(path, &buf) == 0) {
				rc = B_TRUE;
			}
			free(dupfile);
		}
	}

	return (rc);
}
Exemplo n.º 7
0
cFileInfo::cFileInfo(char *file)
{
  MYDEBUG("FileInfo: %s", file);
  File = (file && !isempty(file)) ? strdup(file) : NULL;

  if(File && File[strlen(File) - 1] == '/')
      File[strlen(File) - 1] = '\0';

  buffer = NULL;

  if(isExists())
    stat64(File, &Info);

  size = 0;
}
Exemplo n.º 8
0
// Returns true if file filename exists
bool exists(const std::string &filename) {
#ifdef _WIN32
    std::wstring wstr = ConvertUTF8ToWString(filename);
    return GetFileAttributes(wstr.c_str()) != 0xFFFFFFFF;
#else
    struct stat64 file_info;

    std::string copy(filename);
    stripTailDirSlashes(copy);

    int result = stat64(copy.c_str(), &file_info);

    return (result == 0);
#endif
}
Exemplo n.º 9
0
	Uint64 FileSize(const QString & url)
	{
		int ret = 0;
#ifdef HAVE_STAT64
		struct stat64 sb;
		ret = stat64(QFile::encodeName(url),&sb);
#else
		struct stat sb;
		ret = stat(QFile::encodeName(url),&sb);
#endif
		if (ret < 0)
			throw Error(i18n("Cannot calculate the filesize of %1: %2",url,strerror(errno)));

		return (Uint64)sb.st_size;
	}
Exemplo n.º 10
0
int List_files(void)
{

	int count,i;
	struct direct **files;
	struct stat64 finfo;
	struct tm *pTime;
	char	datebuff[30];
	char	timebuff[30];

	
	if (getcwd(pathname,sizeof(pathname)) == NULL )
	{ 
		printf("Error getting path \n");
		return -1;
	}
	printf("Current Working Directory = %s \n",pathname);
	
	count = scandir( pathname, &files, file_select, alphasort);
	/* If no files found, make a non-selectable menu item */
	if(count <= 0)
	{
		printf("No files in this directory \n");
		return -1;
	}

	
	printf("\n"); 
	for (i=0;i<count;i++)
	{
		
		if(!stat64(files[i]->d_name,&finfo))
		{
			pTime = localtime(&finfo.st_ctime);
			sprintf(datebuff,"%d/%02d/%02d",(1900+pTime->tm_year),( 1+pTime->tm_mon), pTime->tm_mday);
			sprintf(timebuff,"%02d:%02d:%02d",pTime->tm_hour, pTime->tm_min, pTime->tm_sec);
			printf("%s	%s	%s	%dK \n",files[i]->d_name,datebuff,timebuff,(int)(finfo.st_size/1024));
		}else{
			printf("%s  \n",files[i]->d_name);
		}

		
	}
	
	 
	return count;

}
Exemplo n.º 11
0
/**
 * Retrieve the size of a file from the file name.  If the
 * name is a device, it zero is returned.
 *
 * @param size   The returned size value.
 *
 * @return True if the size was retrievable, false otherwise.
 */
bool SysFile::getTimeStamp(const char *name, const char *&time)
{
    time = "";         // default return value
    // the handle is not active, use the name
    struct stat64 fileInfo;
    if (stat64(name, &fileInfo) == 0)
    {
        // regular file?  return the defined size
        if ((fileInfo.st_mode & (S_IFREG | S_IFDIR)) != 0)
        {
            time = ctime(&fileInfo.st_mtime);
        }
        return true;
    }
    return false;
}
Exemplo n.º 12
0
 void itemCreated(const std::string& file)
 {
     auto it = std::lower_bound(m_dirEntries.begin(), m_dirEntries.end(), file, Cmp());
     it = m_dirEntries.emplace(it, file);
     
     std::string filePatch = m_dir.path();
     if (!endsWith(filePatch, '/'))
         filePatch.push_back('/');
     filePatch.append(file);
     if (stat64(filePatch.c_str(), &it->info) == -1) {
         m_dirEntries.erase(it);
         return;
     }
     
     q->itemInserted(it - m_dirEntries.begin());
 }
Exemplo n.º 13
0
	FileType fileType(std::string const& filename)
	{
		struct stat64 file_stat;
		if (stat64(filename.c_str(), &file_stat) == 0)
		{
			if (file_stat.st_mode & S_IFDIR)
			{
				return FileDirectory;
			}
			else if (file_stat.st_mode & S_IFREG)
			{
				return FileRegular;
			}
		}
		return FileNotFound;
	}
Exemplo n.º 14
0
   /**
    *     Returns the time that the file denoted by this abstract pathname was last modified.
    *
    *     Returns:
    *       A long value representing the time the file was last modified, measured in milliseconds
    *       since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if
    *       an I/O error occurs
    */
   uint64_t File::lastModified() {
#ifdef __USE_LARGEFILE64
      struct stat64 attrib;			// create a file attribute structure
      if (stat64(myPathName.c_str(), &attrib) == 0) {		// get the attributes of myPathName
#else
      struct stat attrib;			// create a file attribute structure
      if (stat(myPathName.c_str(), &attrib) == 0) {		// get the attributes of myPathName
#endif
         return (static_cast<uint64_t>(1000))*attrib.st_mtime;
      } else  {
            perror(std::string("error in File::lastModified() while trying to stat ").append(myPathName).c_str());
            return 0;
         }
    }

} // namespace bestofjava
Exemplo n.º 15
0
bool Path::isDirectory() const
{
#if NORI_SYSTEM_WIN32
    struct _stati64 sb;

    if (_stati64(m_string.c_str(), &sb) != 0)
        return false;
#else
    struct stat64 sb;

    if (stat64(m_string.c_str(), &sb) != 0)
        return false;
#endif

    return S_ISDIR(sb.st_mode) ? true : false;
}
Exemplo n.º 16
0
static INT64_T chirp_fs_local_chmod(const char *path, INT64_T mode)
{
	PREAMBLE("chmod(`%s', 0o%" PRIo64 ")", path, mode);
	struct stat64 linfo;
	RESOLVE(path)
	mode &= S_IXUSR|S_IRWXG|S_IRWXO; /* users can only set owner execute and group/other bits */
	if (stat64(path, &linfo) == -1)
		return -1;
	if(S_ISDIR(linfo.st_mode)) {
		mode |= S_IRWXU; /* all owner bits must be set */
	} else {
		mode |= S_IRUSR|S_IWUSR; /* owner read/write must be set */
	}
	rc = chmod(path, mode);
	PROLOGUE
}
Exemplo n.º 17
0
int IsFileExists(const std::string& fname)
{
	struct stat64 buff64;

	int res = stat64(fname.c_str(), &buff64);
	if (-1 != res)
		return 0;

	// No assertion if the path path does not exist.
	if (ENOENT != errno) 
	{
		std::cout << "stat: " << fname << ": " << strerror(errno) << "[" << __FUNCTION__ << ":" << __LINE__ << "]" << std::endl;
	}

	return -1;
}
Exemplo n.º 18
0
	int load(string backfile, string filename, FileBuffer *p, bool async)
	{
		struct stat64 st;
		if (stat64(backfile.c_str() + 1, &st))
		{
			set_last_err_string("stat64 failure");
			return -1;
		}
		p->unmapfile();

		if (p->mapfile(backfile.substr(1), st.st_size))
			return -1;

		p->m_loaded = true;
		return 0;
	}
Exemplo n.º 19
0
bool Path::isFile() const
{
#if WENDY_SYSTEM_WIN32
  struct _stati64 sb;

  if (_stati64(path.c_str(), &sb) != 0)
    return false;
#else
  struct stat64 sb;

  if (stat64(path.c_str(), &sb) != 0)
    return false;
#endif

  return S_ISREG(sb.st_mode) ? true : false;
}
Exemplo n.º 20
0
static int
find_gwin(gwin_query_t *gqp, const lwpstatus_t *psp)
{
	gwindows_t gwin;
	struct stat64 st;
	char path[64];
	ssize_t n;
	int fd, i;
	int rv = 0; /* Return value for skip to next lwp */

	(void) snprintf(path, sizeof (path), "/proc/%d/lwp/%d/gwindows",
	    (int)gqp->gq_proc->pid, (int)psp->pr_lwpid);

	if (stat64(path, &st) == -1 || st.st_size == 0)
		return (0); /* Nothing doing; skip to next lwp */

	if ((fd = open64(path, O_RDONLY)) >= 0) {
		/*
		 * Zero out the gwindows_t because the gwindows file only has
		 * as much data as needed to represent the saved windows.
		 */
		(void) memset(&gwin, 0, sizeof (gwin));
		n = read(fd, &gwin, sizeof (gwin));

		if (n > 0) {
			/*
			 * If we actually found a non-zero gwindows file and
			 * were able to read it, iterate through the buffers
			 * looking for a stack pointer match; if one is found,
			 * copy out the corresponding register window.
			 */
			for (i = 0; i < gwin.wbcnt; i++) {
				if (gwin.spbuf[i] == (greg_t *)gqp->gq_addr) {
					(void) memcpy(gqp->gq_rwin,
					    &gwin.wbuf[i],
					    sizeof (struct rwindow));

					rv = 1; /* We're done */
					break;
				}
			}
		}
		(void) close(fd);
	}

	return (rv);
}
Exemplo n.º 21
0
/*
 * test the path/fname to see if is char special
 */
static int
test_if_raw(char *new_path, dev_t blk_dev)
{
	struct stat64	buf;

	/* check if we got a char special file */
	if (stat64(new_path, &buf) != 0)
		return (0);

	if (!S_ISCHR(buf.st_mode))
		return (0);

	if (blk_dev != buf.st_rdev)
		return (0);

	return (1);
}
Exemplo n.º 22
0
/*
 * This is not a host descriptor function, but is closely related to
 * fstat and should behave similarly.
 */
int NaClHostDescStat(char const       *host_os_pathname,
                     nacl_host_stat_t *nhsp) {

#if NACL_LINUX
  if (stat64(host_os_pathname, nhsp) == -1) {
    return -errno;
  }
#elif NACL_OSX
  if (stat(host_os_pathname, nhsp) == -1) {
    return -errno;
  }
#else
# error "What OS?"
#endif

  return 0;
}
Exemplo n.º 23
0
Arquivo: file.c Projeto: ljx0305/tbox
tb_bool_t tb_file_info(tb_char_t const* path, tb_file_info_t* info)
{
    // check
    tb_assert_and_check_return_val(path, tb_false);

    // the full path (need translate "~/")
    tb_char_t full[TB_PATH_MAXN];
    path = tb_path_absolute(path, full, TB_PATH_MAXN);
    tb_assert_and_check_return_val(path, tb_false);

    // exists?
    tb_check_return_val(!access(path, F_OK), tb_false);

    // get info
    if (info)
    {
        // init info
        tb_memset(info, 0, sizeof(tb_file_info_t));

        // get stat
#ifdef TB_CONFIG_POSIX_HAVE_STAT64
        struct stat64 st = {0};
        if (!stat64(path, &st))
#else
        struct stat st = {0};
        if (!stat(path, &st))
#endif
        {
            // file type
            if (S_ISDIR(st.st_mode)) info->type = TB_FILE_TYPE_DIRECTORY;
            else info->type = TB_FILE_TYPE_FILE;

            // file size
            info->size = st.st_size >= 0? (tb_hize_t)st.st_size : 0;

            // the last access time
            info->atime = (tb_time_t)st.st_atime;

            // the last modify time
            info->mtime = (tb_time_t)st.st_mtime;
        }
    }

    // ok
    return tb_true;
}
Exemplo n.º 24
0
/* obtain file info. return 0 if file is not accessible,
   file_size or file_attr can be NULL if either is not interested */
Ipp32s vm_file_getinfo(const vm_char *filename, Ipp64u *file_size, Ipp32u *file_attr) {
#if defined(OSX) || defined(LINUX64)
   struct stat buf;
   if (stat(filename,&buf) != 0) return 0;
#else
   struct stat64 buf;
   if (stat64(filename,&buf) != 0) return 0;
#endif
   if (file_size) *file_size=buf.st_size;
   if (file_attr) {
      *file_attr=0;
      if (buf.st_mode & S_IFREG) *file_attr|=VM_FILE_ATTR_FILE;
      if (buf.st_mode & S_IFDIR) *file_attr|=VM_FILE_ATTR_DIRECTORY;
      if (buf.st_mode & S_IFLNK) *file_attr|=VM_FILE_ATTR_LINK;
   }
   return 1;
}
Exemplo n.º 25
0
// Returns true if file filename exists. Will return true on directories.
bool Exists(const std::string &filename) {
	std::string fn = filename;
	StripTailDirSlashes(fn);

#if defined(_WIN32)
	std::wstring copy = ConvertUTF8ToWString(fn);

	// Make sure Windows will no longer handle critical errors, which means no annoying "No disk" dialog
	int OldMode = SetErrorMode(SEM_FAILCRITICALERRORS);
	bool success = GetFileAttributes(copy.c_str()) != INVALID_FILE_ATTRIBUTES;
	SetErrorMode(OldMode);
	return success;
#else
	struct stat64 file_info;
	return stat64(fn.c_str(), &file_info) == 0;
#endif
}
Exemplo n.º 26
0
int
statvfs (const char *file, struct statvfs *buf)
{
  struct statfs fsbuf;
  struct stat64 st;

  /* Get as much information as possible from the system.  */
  if (__statfs (file, &fsbuf) < 0)
    return -1;

  /* Convert the result.  */
  __internal_statvfs (file, buf, &fsbuf,
		      stat64 (file, &st) == -1 ? NULL : &st);

  /* We signal success if the statfs call succeeded.  */
  return 0;
}
Exemplo n.º 27
0
// Returns the size of filename (64bit)
u64 GetFileSize(const std::string &filename) {
    if (!FileExists(filename)) {
        LOG_WARNING(TCOMMON, "GetSize: failed %s: No such file", filename.c_str());
        return 0;
    }
    if (IsDirectory(filename)) {
        LOG_WARNING(TCOMMON, "GetSize: failed %s: is a directory", filename.c_str());
        return 0;
    }
    struct stat64 buf;
    if (stat64(filename.c_str(), &buf) == 0) {
        LOG_DEBUG(TCOMMON, "GetSize: %s: %lld", filename.c_str(), (long long)buf.st_size);
        return buf.st_size;
    }
    LOG_ERROR(TCOMMON, "GetSize: Stat failed %s", filename.c_str());
    return 0;
}
Exemplo n.º 28
0
/*
 * fs_volexist
 *
 * Check if the volume exists
 */
boolean_t
fs_volexist(char *path)
{
	struct stat64 st;
	char *p;

	if ((p = get_volname(path)) == NULL)
		return (FALSE);

	if (stat64(p, &st) != 0) {
		free(p);
		return (FALSE);
	}

	free(p);
	return (TRUE);
}
Exemplo n.º 29
0
Arquivo: fb.c Projeto: gettler/mvpmc
int quickdir_change(mvp_widget_t *widget,char *path )
{
	int rc;
	struct stat64 sb;
	rc = stat64(path, &sb);
	if (rc==0) {
		if (strstr(path,"/uPnP")!=NULL && strstr(cwd,"/uPnP")==NULL ){
			mount_djmount(path);
				
		} else if (strstr(path,"/uPnP")==NULL && strstr(cwd,"/uPnP")!=NULL ) { 
			unmount_djmount();
		}
		snprintf(cwd,1024,"%s",path);
		fb_update(widget);
	}
	return rc;
}
Exemplo n.º 30
0
char * select_file(char *input, int what_help)
{
	char **list = NULL, *isdir = NULL, *path = NULL;
	char *new_fname = NULL;
	struct stat64 statbuf;
	int list_n, index;
	int strbufsize = find_path_max();

	list_n = match_files(input, &path, &list, &isdir);
	if (list_n == 0)
	{
		myfree(path);
		flash();
		return NULL;
	}

	index = selection_box((void **)list, isdir, list_n, SEL_FILES, what_help, NULL);
	if (index != -1)
	{
		new_fname = (char *)mymalloc(strbufsize + 1);

		snprintf(new_fname, strbufsize, "%s%s", path, list[index]);

		if (stat64(new_fname, &statbuf) == -1)
		{
			myfree(new_fname);
			new_fname = NULL;
			flash();
		}
		else
		{
			if (S_ISDIR(statbuf.st_mode))
			{
				strncat(new_fname, "/", strbufsize);
			}
		}
	}

	delete_array(list, list_n);

	myfree(isdir);
	myfree(path);

	return new_fname;
}