Ejemplo n.º 1
0
LONG DiskType(CHAR *dst)
 {
  ULONG type=NO_DRIVE;
  SHORT disk;
  unsigned ulCurDisk,totaldrives;
  //UCHAR j,len,*vol_ptr;
  //struct ffblk ffblk;

  //CountHDD=peekb(0x0040,0x0075);
//  type
//IDI_FLOPPY_12
//IDI_FLOPPY_144;
//IDI_LOCAL1;
//IDI_CD
//IDI_NET_ON
  ulCurDisk=_getdrive();
  if((dst[1]==':')&&(strlen(dst)<=3)&&((dst[2]==0)||(dst[2]=='\\')))
   {
    disk=(CHAR)(toupper(dst[0])-'A');
    if((disk==0)||(disk==1)) //a или б
     {
      if(GetDriveType((BYTE)disk))
       //if(CheckForRemote((BYTE)disk))
         type=IDI_FLOPPY_144;//Disk[i]|=DISK_REMOTE;
     }
    else
     {
      _dos_setdrive(disk+1,&totaldrives);
      if(_getdrive()==(disk+1))
       {
        type=IDI_LOCAL1;//DISK_HDD;
        if(CheckForRemote((BYTE)disk))
         type=IDI_NET_ON;//DISK_REMOTE;
       }
      //if(Disk[i]&DISK_HDD&&!findfirst("*.*",&ffblk,FA_LABEL))
      // {
      //  vol_ptr=VolumeLabel[i-2];
      //  len=strlen(ffblk.ff_name);
      //  for(j=0;j<=len;j++)
      //  if(*(ffblk.ff_name+j)!='.')
      //   {
      //    *vol_ptr=*(ffblk.ff_name+j);
      //    vol_ptr++;
      //   }
      // }
      //else *VolumeLabel[i-2]=0;
     }
   }
  else type=IDI_FOLD_CLOSE;

  _dos_setdrive(ulCurDisk,&totaldrives);
  return type;
 }
Ejemplo n.º 2
0
int main(int argc, char **argv)		//argv = {gameDrive:gameDir, gameCommand}
{
	int i;
	char currentDrive, newDrive;
	int driveVal;
	char *path;
	char **cmdargv = argv+2;

	if(argc < 3) {
		fprintf(stderr, "Usage: %s drive:dir cmd [args]\n", argv[0]);
		fprintf(stderr, "Args not supported yet.\n");
		exit(1);
	}
	newDrive = argv[1][0];
	path = argv[1]+2;
	driveVal = toupper(newDrive) - 'A' + 1;

	currentDrive = _getdrive();					//	get current drive;
	if(driveVal != currentDrive) {
		if(_chdrive(driveVal)) {				// change to game drive
			fprintf(stderr, "Error: exec: chdrive(%d) failed.\n", driveVal);
			fprintf(stderr, "path %s, drive %c, driveVal %d\n", path, newDrive, driveVal);
			exit(2);
		}
	}
	if(_chdir(path)) {						// change to game directory
		fprintf(stderr, "Error: exec: chdir %s failed.\n", path);
		fprintf(stderr, "path %s, drive %c, driveVal %d\n", path, newDrive, driveVal);
		exit(2);
	}
	_execl(cmdargv[0], cmdargv[0], NULL);		// start game.  No args yet.
	fprintf(stderr, "Error: exec(%s...) failed.\n", cmdargv[0]);
	fprintf(stderr, "path %s, drive %c, driveVal %d\n", path, newDrive, driveVal);
	exit(2);
}
Ejemplo n.º 3
0
// reads a Calibration File and resets instance variables
int FTWrapper::LoadCalFile(CString filename)
{
	// only allow *.cal files
	CString filter = "ATI DAQ F/T Calibration Files (*.cal)|*.cal||";
	CFileDialog fileMenu(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter, NULL);
	if (filename == "") {
		// using a GUI, go get the file
		char workingDirectory[200]; /*the working directory*/
		_getdcwd( _getdrive(), workingDirectory, 200 );
		fileMenu.m_ofn.lpstrInitialDir = workingDirectory;
		fileMenu.DoModal();
		filename = fileMenu.GetPathName();
	}
//	if (fileMenu.GetFileExt() != "cal") {
//		// bad cal file
//	}
	if (filename == "") {
		return -1;
	}
	mFTSensor.SetCalFilePath(filename);
	// default to the first calibration listed in the file
	ActiveCalibration = 1;
	// set the bit that indicates the calibration file has been successfully loaded
	status = (FTWrapper::DAQFT_STATUS)(status | CALFILE_LOADED);
	setupMinMax();
	return 0;
}
Ejemplo n.º 4
0
/*********************************************************************
 *		_wgetdcwd (MSVCRT.@)
 *
 * Unicode version of _wgetdcwd.
 */
MSVCRT_wchar_t* CDECL _wgetdcwd(int drive, MSVCRT_wchar_t * buf, int size)
{
  static MSVCRT_wchar_t* dummy;

  TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);

  if (!drive || drive == _getdrive())
    return _wgetcwd(buf,size); /* current */
  else
  {
    MSVCRT_wchar_t dir[MAX_PATH];
    MSVCRT_wchar_t drivespec[4] = {'A', ':', '\\', 0};
    int dir_len;

    drivespec[0] += drive - 1;
    if (GetDriveTypeW(drivespec) < DRIVE_REMOVABLE)
    {
      *MSVCRT__errno() = MSVCRT_EACCES;
      return NULL;
    }

    dir_len = GetFullPathNameW(drivespec,MAX_PATH,dir,&dummy);
    if (dir_len >= size || dir_len < 1)
    {
      *MSVCRT__errno() = MSVCRT_ERANGE;
      return NULL; /* buf too small */
    }

    TRACE(":returning %s\n", debugstr_w(dir));
    if (!buf)
      return _wcsdup(dir); /* allocate */
    strcpyW(buf,dir);
  }
  return buf;
}
Ejemplo n.º 5
0
bool CheckStorage(const uint64 diskSpaceNeeded)
{
	//Creamos variables temporales
	const int32 drive = _getdrive();	//Indice del disco actual
	_diskfree_t diskfree;				//Estructura de información de espacio libre

	//Obtenemos la información de espacio libre en el disco actual
	if( _getdiskfree(drive, &diskfree) != 0 )
	{//Si falló al obtener el espacio libre del disco
		//Mandamos un error
		GEE_ERROR(TEXT("CheckStorage() - Fallo al obtener el tamaño de espacio libre del disco duro"));
	}

	//Calculamos el número de clusters requeridos de acuerdo a la cantidad de espacio pedido
	const uint64 neededClusters = diskSpaceNeeded / (diskfree.sectors_per_cluster * diskfree.bytes_per_sector);

	//Revisamos si el espacio libre es suficiente de acuerdo al espacio necesitado
	if(diskfree.avail_clusters < neededClusters)
	{//Si no hay suficiente espacio libre en el disco duro
		//Informamos el error
		GEE_ERROR(TEXT("CheckStorage: No hay suficiente espacio libre en el disco duro"));
		return false;
	}
	return true;
}
Ejemplo n.º 6
0
/** Returns if a given drive exists.
 *
 * @param drive
 * @return
 */
int LbDriveExists(const unsigned int drive)
{
  int result;
#if defined(WIN32)||defined(DOS)||defined(GO32)
  unsigned int lastdrive=_getdrive();
  if ( _chdrive(drive) )
  {
    result = -1;
  } else
  {
    result = 1;
    _chdrive(lastdrive);
  }
#else
  //Let's assume we have only 'C' drive on Unix
  if ( drive!=3 )
  {
    result = -1;
  } else
  {
    result = 1;
  }
#endif
  return result;
}
Ejemplo n.º 7
0
bool mmOperatingSystem::IsExistingDir(mmString p_sDirName)
{
	bool v_bRes = false;

	// pobieram aktywny dysk i œcie¿kê
	int v_iDriveNo = _getdrive();
	wchar_t* v_pcCurDir = _wgetcwd(NULL,_MAX_PATH);
	if(v_pcCurDir == NULL)
	{
		throw mmError(mmeBadAlloc);
	};

	// prubujê przejœæ do œcie¿ki p_sDirName
	if(_wchdir(p_sDirName.c_str()) == 0)
	{
		v_bRes = true;
	};

	// przywracam poprzedni dysk i œcie¿kê
	_chdrive(v_iDriveNo);
	if(_wchdir(v_pcCurDir) != 0)
	{
		throw mmError(mmeUnknownError);
	};

	// zwalniam pamiêæ przydzielon¹ przez getcwd
	free(v_pcCurDir);

	return v_bRes;
}
Ejemplo n.º 8
0
Archivo: swnd.c Proyecto: goriy/sif
void populate_dir (void)
{
  char buf[MAX_PATH];
  char mask[MAX_MASK_LEN];
  GetWindowText(GetDlgItem(hMainWindow, IDC_MANPATH), buf, sizeof(buf));
  GetWindowText(GetDlgItem(hMainWindow, IDC_MASK), mask, sizeof(mask));
  if (!DirectoryExists(buf))  {
    current_path_to_edit ();
    strcpy (buf, CurrentPath);
  }
  else  {
    size_t off;
    off = strlen(buf);
    if ((off) && (buf[off-1] != '\\') && (buf[off-1] != '/')) {
      buf[off] = '\\';
      buf[off+1] = 0;
    }
    strcpy (CurrentPath, buf);
    current_path_to_edit ();
  }
  DlgDirListComboBox(hMainWindow, buf, IDC_DRIVES, 0, DDL_DRIVES);
  DlgDirList (hMainWindow, buf, IDC_DIRS, 0, DDL_DIRECTORY + DDL_EXCLUSIVE);
  /* if you want to show only files that match mask - uncomment next line */
  //strcat (buf, mask);
  DlgDirList (hMainWindow, buf, IDC_FILES, IDC_REALPATH, 0x27);

  snprintf (mask, sizeof(mask), "[-%c-]", 'a' +_getdrive() - 1);
  ComboBox_SelectString (GetDlgItem(hMainWindow, IDC_DRIVES), 0, mask);
}
Ejemplo n.º 9
0
Archivo: commons.c Proyecto: hh/emacs
void initCwd() {
	char *rr;
	char nid[MAX_FILE_NAME_SIZE];
	rr = getcwd(s_cwd, MAX_FILE_NAME_SIZE);
	if (rr==NULL) {
		// try also with getenv, on some linuxes the statically linked
		// getcwd does not work.
		rr = getenv("PWD");
		if (rr==NULL) {
			error(ERR_ST, "can't get current working directory");
			sprintf(s_cwd, ".");
		} else {
			InternalCheck(strlen(rr) < MAX_FILE_NAME_SIZE);
			strcpy(s_cwd, rr);
		}
	}
#if defined (__WIN32__) || defined (__OS2__)	/*SBD*/
	if (strlen(s_cwd)<=2 || s_cwd[1]!=':') {
		// starting by drive specification
#if defined (__OS2__)							/*SBD*/
		sprintf(nid,"%c:",_getdrive());
#else											/*SBD*/
		sprintf(nid,"%c:",tolower('c'));
#endif											/*SBD*/
		if (strlen(nid)+strlen(s_cwd) < MAX_FILE_NAME_SIZE-1) {
			strcpy(nid+strlen(nid),s_cwd);
			strcpy(s_cwd,nid);
		}
	}
	strcpy(s_cwd, normalizeFileName(s_cwd, "c:\\"));
#else					/*SBD*/
	strcpy(s_cwd, normalizeFileName(s_cwd, "/"));
#endif					/*SBD*/
}
Ejemplo n.º 10
0
QString QFSFileEngine::currentPath(const QString &fileName)
{
#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
    QString ret;
    //if filename is a drive: then get the pwd of that drive
    if (fileName.length() >= 2 &&
        fileName.at(0).isLetter() && fileName.at(1) == QLatin1Char(':')) {
        int drv = fileName.toUpper().at(0).toLatin1() - 'A' + 1;
        if (_getdrive() != drv) {
            wchar_t buf[PATH_MAX];
            ::_wgetdcwd(drv, buf, PATH_MAX);
            ret = QString::fromWCharArray(buf);
        }
    }
    if (ret.isEmpty()) {
        //just the pwd
        ret = QFileSystemEngine::currentPath().filePath();
    }
    if (ret.length() >= 2 && ret[1] == QLatin1Char(':'))
        ret[0] = ret.at(0).toUpper(); // Force uppercase drive letters.
    return ret;
#else // !Q_OS_WINCE && !Q_OS_WINRT
    Q_UNUSED(fileName);
    return QFileSystemEngine::currentPath().filePath();
#endif // Q_OS_WINCE || Q_OS_WINRT
}
Ejemplo n.º 11
0
/*----------------------------------------------------------------------
       Expand the ~ in a file ala the csh (as home directory)

   Args: buf --  The filename to expand (nothing happens unless begins with ~)
         len --  The length of the buffer passed in (expansion is in place)

 Result: Expanded string is returned using same storage as passed in.
         If expansion fails, NULL is returned
 ----*/
char *
fnexpand(char *buf, int len)
{
#ifdef	_WINDOWS
    /* We used to use ps_global->home_dir, now we have to build it */
    if(*buf == '~' && *(buf+1) == '\\'){
	char temp_path[_MAX_PATH], home_buf[_MAX_PATH], *temp_home_str;

	if(getenv("HOME") != NULL)
	  temp_home_str = getenv("HOME");
	else{
	    /* should eventually strip this out of get_user_info */
	    char *p, *q;

	    if((p = (char *) getenv("HOMEDRIVE"))
	       && (q = (char *) getenv("HOMEPATH")))
	      snprintf(home_buf, sizeof(home_buf), "%s%s", p, q);
	    else
	      snprintf(home_buf, sizeof(home_buf), "%c:\\", '@' + _getdrive());

	    temp_home_str = home_buf;
	}
	snprintf(temp_path, sizeof(temp_path), "%s", buf+1);
	snprintf(buf, sizeof(buf), "%s%s", temp_path, fname_to_utf8(temp_home_str));
    }
    return(buf);
#else	/* UNIX */
    struct passwd *pw;
    register char *x,*y;
    char name[20], *tbuf;
    
    if(*buf == '~') {
        for(x = buf+1, y = name;
	    *x != '/' && *x != '\0' && y < name + sizeof(name)-1;
	    *y++ = *x++)
	  ;

        *y = '\0';
        if(x == buf + 1) 
          pw = getpwuid(getuid());
        else
          pw = getpwnam(name);

        if(pw == NULL)
          return((char *)NULL);
        if(strlen(pw->pw_dir) + strlen(buf) > len) {
          return((char *)NULL);
        }

	if((tbuf = (char *) malloc((len+1)*sizeof(char))) != NULL){
	    snprintf(tbuf, len, "%s%s", pw->pw_dir, x);
	    snprintf(buf, len, "%s", tbuf);
	    free((void *)tbuf);
	}
    }

    return(len ? buf : (char *)NULL);
#endif	/* UNIX */
}
Ejemplo n.º 12
0
static char* import_conv(char* dst_begin, char* dst_end, const char* begin, const char* end)
{
	adv_bool need_slash;

	if (end - begin == 2 && begin[1]==':') {
		/* only drive spec */
		memcpy(dst_begin, "/dos/", 5);
		dst_begin += 5;
		*dst_begin++ = tolower(begin[0]);
		begin += 2;
		need_slash = 1;
	} else if (end - begin >= 3 && begin[1]==':' && (begin[2]=='\\' || begin[2]=='/')) {
		/* absolute path */
		memcpy(dst_begin, "/dos/", 5);
		dst_begin += 5;
		*dst_begin++ = tolower(begin[0]);
		begin += 3;
		need_slash = 1;
	} else if (end - begin >= 3 && begin[1]==':') {
		/* drive + relative path, assume it's an absolute path */
		memcpy(dst_begin, "/dos/", 5);
		dst_begin += 5;
		*dst_begin++ = tolower(begin[0]);
		begin += 2;
		need_slash = 1;
	} else if (end - begin >= 1 && (begin[0]=='\\' || begin[0]=='/')) {
		/* absolute path on the current drive */
		memcpy(dst_begin, "/dos/", 5);
		dst_begin += 5;
#ifdef __MSDOS__
		*dst_begin++ = getdisk() + 'a';
#else
		*dst_begin++ = _getdrive() + 'a';
#endif
		begin += 1;
		need_slash = 1;
	} else {
		/* relative path, keep it relative */
		need_slash = 0;
	}

	/* add a slash if something other is specified */
	if (need_slash && begin != end) {
		*dst_begin++ = '/';
	}

	/* copy the remaining path */
	while (begin != end) {
		if (*begin=='\\')
			*dst_begin++ = '/';
		else
			*dst_begin++ = tolower(*begin);
		++begin;
	}

	return dst_begin;
}
Ejemplo n.º 13
0
int LbDriveCurrent(unsigned int *drive)
{
#if defined(WIN32)||defined(DOS)||defined(GO32)
  *drive=_getdrive();
#else
  //Let's assume we're on 'C' drive on Unix ;)
  *drive=3;
#endif
  return 1;
}
Ejemplo n.º 14
0
void makefullpath(TCHAR* pdbname)
{
	TCHAR* pdbstart = pdbname;
	TCHAR fullname[260];
	TCHAR* pfullname = fullname;

	int drive = 0;
	if (pdbname[0] && pdbname[1] == ':')
	{
		if (pdbname[2] == '\\' || pdbname[2] == '/')
			return;
		drive = T_toupper (pdbname[0]);
		pdbname += 2;
	}
	else
	{
		drive = _getdrive();
	}

	if (*pdbname != '\\' && *pdbname != '/')
	{
		T_getdcwd(drive, pfullname, sizeof(fullname)/sizeof(fullname[0]) - 2);
		pfullname += T_strlen(pfullname);
		if (pfullname[-1] != '\\')
			*pfullname++ = '\\';
	}
	else
	{
		*pfullname++ = 'a' - 1 + drive;
		*pfullname++ = ':';
	}
	T_strcpy(pfullname, pdbname);
	T_strcpy(pdbstart, fullname);

	for(TCHAR*p = pdbstart; *p; p++)
		if (*p == '/')
			*p = '\\';

	// remove relative parts "./" and "../"
	while (TCHAR* p = T_strstr (pdbstart, TEXT("\\.\\")))
		T_strcpy(p, p + 2);

	while (TCHAR* p = T_strstr (pdbstart, TEXT("\\..\\")))
	{
		for (TCHAR* q = p - 1; q >= pdbstart; q--)
			if (*q == '\\')
			{
				T_strcpy(q, p + 3);
				break;
			}
	}
}
Ejemplo n.º 15
0
// Changes to a drive if valid.. 1=A, 2=B, etc
// If flag, then changes to it.
// Returns 0 if not-valid, 1 if valid.
int cfile_chdrive( int DriveNum, int flag )
{
	int Valid = 0;
	int n, org;

	org = -1;
	if (!flag)
		org = _getdrive();

	_chdrive( DriveNum );
	n = _getdrive();


	if (n == DriveNum )
		Valid = 1;

	if ( (!flag) && (n != org) )
		_chdrive( org );

	return Valid;

}
Ejemplo n.º 16
0
static int do_lstat(const char *file_name, struct stat *buf)
{
	WIN32_FILE_ATTRIBUTE_DATA fdata;
	wchar_t* fbuf = gitwin_to_utf16(file_name);

	if (GetFileAttributesExW(fbuf, GetFileExInfoStandard, &fdata)) {
		int fMode = S_IREAD;

		if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			fMode |= S_IFDIR;
		else
			fMode |= S_IFREG;

		if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
			fMode |= S_IWRITE;

		if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
			fMode |= S_IFLNK;

		buf->st_ino = 0;
		buf->st_gid = 0;
		buf->st_uid = 0;
		buf->st_nlink = 1;
		buf->st_mode = (mode_t)fMode;
		buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
		buf->st_dev = buf->st_rdev = (_getdrive() - 1);
		buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
		buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
		buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));

		git__free(fbuf);
		return GIT_SUCCESS;
	}

	git__free(fbuf);

	switch (GetLastError()) {
		case ERROR_ACCESS_DENIED:
		case ERROR_SHARING_VIOLATION:
		case ERROR_LOCK_VIOLATION:
		case ERROR_SHARING_BUFFER_EXCEEDED:
			return GIT_EOSERR;

		case ERROR_BUFFER_OVERFLOW:
		case ERROR_NOT_ENOUGH_MEMORY:
			return GIT_ENOMEM;

		default:
			return GIT_EINVALIDPATH;
	}
}
Ejemplo n.º 17
0
Archivo: mingw.c Proyecto: Pistos/git
int mingw_fstat(int fd, struct mingw_stat *buf)
{
	HANDLE fh = (HANDLE)_get_osfhandle(fd);
	BY_HANDLE_FILE_INFORMATION fdata;

	if (fh == INVALID_HANDLE_VALUE) {
		errno = EBADF;
		return -1;
	}
	/* direct non-file handles to MS's fstat() */
	if (GetFileType(fh) != FILE_TYPE_DISK) {
		struct stat st;
		if (fstat(fd, &st))
			return -1;
		buf->st_ino = st.st_ino;
		buf->st_gid = st.st_gid;
		buf->st_uid = st.st_uid;
		buf->st_mode = st.st_mode;
		buf->st_size = st.st_size;
		buf->st_blocks = size_to_blocks(buf->st_size);
		buf->st_dev = st.st_dev;
		buf->st_atime = st.st_atime;
		buf->st_mtime = st.st_mtime;
		buf->st_ctime = st.st_ctime;
		return 0;
	}

	if (GetFileInformationByHandle(fh, &fdata)) {
		int fMode = S_IREAD;
		if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			fMode |= S_IFDIR;
		else
			fMode |= S_IFREG;
		if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
			fMode |= S_IWRITE;

		buf->st_ino = 0;
		buf->st_gid = 0;
		buf->st_uid = 0;
		buf->st_mode = fMode;
		buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
		buf->st_blocks = size_to_blocks(buf->st_size);
		buf->st_dev = _getdrive() - 1;
		buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
		buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
		buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
		return 0;
	}
	errno = EBADF;
	return -1;
}
Ejemplo n.º 18
0
void get_dir( char *s, bool be )
{
	SEH_PUSH("get_dir()");
    strcpy(s, "X:\\");
    s[0] = ( char ) ( 'A' + ( char ) (_getdrive() - 1) );
    _getdcwd(0, &s[0], 161);
    if ( be ) 
    {
        if ( s[strlen(s) - 1] != '\\' )
        {
            strcat(s, "\\");
        }
    }
}
Ejemplo n.º 19
0
void CheckHardDisk(const DWORDLONG space_needed)
{
  //check for enough free space on currect disk
  const int drive = _getdrive();
  struct _diskfree_t diskfree;

  _getdiskfree(drive, &diskfree);
  unsigned __int64 const need_clusters = space_needed / (diskfree.sectors_per_cluster*diskfree.bytes_per_sector);
  if(diskfree.avail_clusters < need_clusters)
  {
    //if you get here you do not have enough disk space
    throw KhaosError(ERR_INIT_NOT_ENOUGH_DISK_SPACE);
  }
}
Ejemplo n.º 20
0
bool chk_hdd(unsigned __int64 spaceNeeded)
{
    //	get the system drive
    const int drive = _getdrive();
    struct _diskfree_t diskfree;
    //	get the amount of free space
    _getdiskfree(drive, &diskfree);

    //	calculate how many clusters are needed
    const unsigned __int64 neededClusters = spaceNeeded / (diskfree.sectors_per_cluster * diskfree.bytes_per_sector);

    //	check if there are enough free clusters
    if(diskfree.avail_clusters < neededClusters)
        return false;
    return true;
}
Ejemplo n.º 21
0
struct DiskPartition64 *
FindCurrentPartition(void)
{
    int dr = _getdrive();
    struct DiskPartition64 *dp;

    dr--;
    for (dp = DiskPartitionList; dp; dp = dp->next) {
	if (*dp->devName - 'A' == dr)
	    break;
    }
    if (!dp) {
	printf("Current drive is not a valid vice partition.\n");
    }
    return dp;
}
Ejemplo n.º 22
0
Archivo: mingw.c Proyecto: Pistos/git
/* We keep the do_lstat code in a separate function to avoid recursion.
 * When a path ends with a slash, the stat will fail with ENOENT. In
 * this case, we strip the trailing slashes and stat again.
 */
static int do_lstat(const char *file_name, struct stat *buf)
{
	WIN32_FILE_ATTRIBUTE_DATA fdata;

	if (GetFileAttributesExA(file_name, GetFileExInfoStandard, &fdata)) {
		int fMode = S_IREAD;
		if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			fMode |= S_IFDIR;
		else
			fMode |= S_IFREG;
		if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
			fMode |= S_IWRITE;

		buf->st_ino = 0;
		buf->st_gid = 0;
		buf->st_uid = 0;
		buf->st_mode = fMode;
		buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
		buf->st_blocks = size_to_blocks(buf->st_size);
		buf->st_dev = _getdrive() - 1;
		buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
		buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
		buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
		errno = 0;
		return 0;
	}

	switch (GetLastError()) {
	case ERROR_ACCESS_DENIED:
	case ERROR_SHARING_VIOLATION:
	case ERROR_LOCK_VIOLATION:
	case ERROR_SHARING_BUFFER_EXCEEDED:
		errno = EACCES;
		break;
	case ERROR_BUFFER_OVERFLOW:
		errno = ENAMETOOLONG;
		break;
	case ERROR_NOT_ENOUGH_MEMORY:
		errno = ENOMEM;
		break;
	default:
		errno = ENOENT;
		break;
	}
	return -1;
}
Ejemplo n.º 23
0
static int do_lstat(const char *file_name, struct stat *buf)
{
	WIN32_FILE_ATTRIBUTE_DATA fdata;
	DWORD last_error;
	wchar_t* fbuf = gitwin_to_utf16(file_name);
	if (!fbuf)
		return -1;

	if (GetFileAttributesExW(fbuf, GetFileExInfoStandard, &fdata)) {
		int fMode = S_IREAD;

		if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			fMode |= S_IFDIR;
		else
			fMode |= S_IFREG;

		if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
			fMode |= S_IWRITE;

		if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
			fMode |= S_IFLNK;

		buf->st_ino = 0;
		buf->st_gid = 0;
		buf->st_uid = 0;
		buf->st_nlink = 1;
		buf->st_mode = (mode_t)fMode;
		buf->st_size = ((git_off_t)fdata.nFileSizeHigh << 32) + fdata.nFileSizeLow;
		buf->st_dev = buf->st_rdev = (_getdrive() - 1);
		buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
		buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
		buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));

		git__free(fbuf);
		return 0;
	}

	last_error = GetLastError();
	if (last_error == ERROR_FILE_NOT_FOUND)
		errno = ENOENT;
	else if (last_error == ERROR_PATH_NOT_FOUND)
		errno = ENOTDIR;

	git__free(fbuf);
	return -1;
}
Ejemplo n.º 24
0
mmString mmOperatingSystem::GetCurrentWorkingDir(void)
{
	wchar_t v_ctDirectory[_MAX_PATH];

	wchar_t v_cLetter[2];
	v_cLetter[0] = 'A'+_getdrive()-1;
	v_cLetter[1] = 0;
	if(_wgetcwd(v_ctDirectory,_MAX_PATH) == NULL)
	{
		throw mmError(mmeUnknownError);
	};

	mmString v_sWorkingDir = mmString(v_cLetter) +
													 mmString(L":\\") +
													 mmString(v_ctDirectory);

	return v_sWorkingDir;
}
Ejemplo n.º 25
0
    bool PlatformManager::check_for_free_space(const u64 space_required) const
    {
        bool result = false;

        const s32 drive = _getdrive();
        _diskfree_t disk_free = {};
        _getdiskfree(drive, &disk_free);

        const u64 clusters_required = space_required / (disk_free.sectors_per_cluster * disk_free.bytes_per_sector);
        XE_PRINT("Disk space: %lu MBs", disk_free.avail_clusters * disk_free.sectors_per_cluster * disk_free.bytes_per_sector / 1024 / 1024);

        result = disk_free.avail_clusters > clusters_required;
        if (!result)
        {
            XE_ERROR(false, "You don't have enough free storage. Please, free up some space.");
        }

        return result;
    }
Ejemplo n.º 26
0
/*
 * @implemented
 */
char* _getdcwd(int nDrive, char* caBuffer, int nBufLen)
{
    int i =0;
    int dr = _getdrive();

    if (nDrive < 1 || nDrive > 26)
        return NULL;
    if (dr != nDrive) {
        if ( _chdrive(nDrive) != 0 )
        	return NULL;
	}
    i = GetCurrentDirectoryA(nBufLen, caBuffer);
    if (i == nBufLen)
        return NULL;
    if (dr != nDrive) {
        if ( _chdrive(dr) != 0 )
        	return NULL;
	}
    return caBuffer;
}
Ejemplo n.º 27
0
bool wxIsDriveAvailable(const wxString& WXUNUSED_IN_WINCE(dirName))
{
#ifdef __WXWINCE__
    return false;
#else
#ifdef __WIN32__
    UINT errorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
#endif
    bool success = true;

    // Check if this is a root directory and if so,
    // whether the drive is available.
    if (dirName.length() == 3 && dirName[(size_t)1] == wxT(':'))
    {
        wxString dirNameLower(dirName.Lower());
#if defined(__GNUWIN32__) && !(defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
        success = wxDirExists(dirNameLower);
#else
        #if defined(__OS2__)
        // Avoid changing to drive since no media may be inserted.
        if (dirNameLower[(size_t)0] == 'a' || dirNameLower[(size_t)0] == 'b')
            return success;
        #endif
        int currentDrive = _getdrive();
        int thisDrive = (int) (dirNameLower[(size_t)0] - 'a' + 1) ;
        int err = setdrive( thisDrive ) ;
        setdrive( currentDrive );

        if (err == -1)
        {
            success = false;
        }
#endif
    }
#ifdef __WIN32__
    (void) SetErrorMode(errorMode);
#endif

    return success;
#endif
}
Ejemplo n.º 28
0
char *
DCirfile::PathRight(void)
{
	if (SecFound)
		return SecFile->PathRight();
	if (CurrRight == NULL)
		return NULL;

	char *chp = strncpy(NewName(RightLen + 1), CurrRight, RightLen);
	chp[RightLen] = '\0';

	char *currdir = _getcwd(NewName(1024), 1024);
	char *inidir = this->getBasePath();
	int currdrive = _getdrive();
	int inidrive = 0;

	if (stricmp(currdir, inidir)
	 && !PathIsURL(chp)
	 && PathIsRelative(chp)) { // fix rel path
		if (*(inidir + 1) == ':')
			inidrive = (toupper(*inidir) - 'A') + 1;
		if (inidrive
		 && (currdrive != inidrive))
			_chdrive(inidrive);
		_chdir(inidir);
		char *nref = NewName(MAX_PATH);
		if (_fullpath(nref, chp, MAX_PATH)) {
			DeleteName(chp);
			chp = NewName(nref);
		}
		DeleteName(nref);
		if (inidrive
		 && (currdrive != inidrive))
			_chdrive(currdrive);
		_chdir(currdir);
	}
	DeleteName(currdir);

	return chp;
}
Ejemplo n.º 29
0
	// /////////////////////////////////////////////////////////////////
	// 
	// /////////////////////////////////////////////////////////////////
	bool SystemCheck::CheckHardDiskSpace(const I64 minFreeSpace)
	{
        bool result = false;						// Result of method.
#ifdef _WINDOWS
		I32 const drive = _getdrive();			// HD drive ID/number.
		struct _diskfree_t diskfree;			// Disk check struct.

		memset((void *)&diskfree, 0, sizeof(diskfree));

		_getdiskfree(drive, &diskfree);

		unsigned __int64 const neededClusters = 
			minFreeSpace /(diskfree.sectors_per_cluster*diskfree.bytes_per_sector);

		if(diskfree.avail_clusters < neededClusters)
		{
			result = false;
		}
#endif

		return (result);
	}
Ejemplo n.º 30
0
/*
 * @implemented
 *
 *    _getdcwd (MSVCRT.@)
 *
 * Get the current working directory on a given disk.
 *
 * PARAMS
 *  drive [I] Drive letter to get the current working directory from.
 *  buf   [O] Destination for the current working directory.
 *  size  [I] Length of drive in characters.
 *
 * RETURNS
 *  Success: If drive is NULL, returns an allocated string containing the path.
 *           Otherwise populates drive with the path and returns it.
 *  Failure: NULL. errno indicates the error.
 */
_TCHAR* _tgetdcwd(int drive, _TCHAR * buf, int size)
{
  static _TCHAR* dummy;

  TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);

  if (!drive || drive == _getdrive())
    return _tgetcwd(buf,size); /* current */
  else
  {
    _TCHAR dir[MAX_PATH];
    _TCHAR drivespec[] = _T("A:");
    int dir_len;

    drivespec[0] += drive - 1;
    if (GetDriveType(drivespec) < DRIVE_REMOVABLE)
    {
      __set_errno(EACCES);
      return NULL;
    }

    /* GetFullPathName for X: means "get working directory on drive X",
     * just like passing X: to SetCurrentDirectory means "switch to working
     * directory on drive X". -Gunnar */
    dir_len = GetFullPathName(drivespec,MAX_PATH,dir,&dummy);
    if (dir_len >= size || dir_len < 1)
    {
      __set_errno(ERANGE);
      return NULL; /* buf too small */
    }

    TRACE(":returning '%s'\n", dir);
    if (!buf)
      return _tcsdup(dir); /* allocate */

    _tcscpy(buf,dir);
  }
  return buf;
}