int chdir_cmd(int argc, char **argv) { UCHAR achDirName[256] = ""; /* Directory name for queries */ ULONG cbDirPathLen = 0; /* Length of directory path */ APIRET rc = NO_ERROR; /* Return code */ UCHAR chDisk; ULONG ulDriveNum = 0; /* Drive number (A=1, B=2, C=3, ...) */ ULONG ulDriveMap = 0; /* Mapping of valid drives */ ULONG i = 0; /* A loop index */ if (argc==1) { rc = DosQueryCurrentDisk (&ulDriveNum, &ulDriveMap); chDisk=(UCHAR)(ulDriveNum+'A'-1); cbDirPathLen = 0; rc = DosQueryCurrentDir(0, achDirName, &cbDirPathLen); rc = DosQueryCurrentDir(0, achDirName, &cbDirPathLen); VioWrtTTY(&chDisk, 1, 0); VioWrtTTY(":\\", 2, 0); VioWrtTTY(achDirName, cbDirPathLen-1, 0); VioWrtTTY("\n\r", 2, 0); } else { DosSetCurrentDir(argv[1]); }; return 0; }
char *__PHYSFS_platformCurrentDir(void) { char *retval; ULONG currentDisk; ULONG dummy; ULONG pathSize = 0; APIRET rc; BYTE byte; rc = DosQueryCurrentDisk(¤tDisk, &dummy); BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL); /* The first call just tells us how much space we need for the string. */ rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize); pathSize++; /* Add space for null terminator. */ retval = (char *) malloc(pathSize + 3); /* plus "x:\\" */ BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); /* Actually get the string this time. */ rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize); if (os2err(rc) != NO_ERROR) { free(retval); return(NULL); } /* if */ retval[0] = ('A' + (currentDisk - 1)); retval[1] = ':'; retval[2] = '\\'; return(retval); } /* __PHYSFS_platformCurrentDir */
/*@ XFile::GetCurrentDirectory(XString * buffer) @group directorys @remarks Query the current directory @parameters XString * buffer to hold the data */ void XFile::GetCurrentDirectory(XString * buffer) { ULONG r = 512; DosQueryCurrentDir(0, (PCH) buffer->GetBuffer(512), &r); buffer->ReleaseBuffer(); }
/* ** Turn a relative pathname into a full pathname. Write the full ** pathname into zFull[]. zFull[] will be at least pVfs->mxPathname ** bytes in size. */ static int os2FullPathname( sqlite3_vfs *pVfs, /* Pointer to vfs object */ const char *zRelative, /* Possibly relative input path */ int nFull, /* Size of output buffer in bytes */ char *zFull /* Output buffer */ ){ if( strchr(zRelative, ':') ){ sqlite3SetString( &zFull, zRelative, (char*)0 ); }else{ ULONG ulDriveNum = 0; ULONG ulDriveMap = 0; ULONG cbzBufLen = SQLITE_TEMPNAME_SIZE; char zDrive[2]; char *zBuff = (char*)malloc( cbzBufLen ); if( zBuff == 0 ){ return SQLITE_NOMEM; } DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap ); if( DosQueryCurrentDir( ulDriveNum, (PBYTE)zBuff, &cbzBufLen ) == NO_ERROR ){ sprintf( zDrive, "%c", (char)('A' + ulDriveNum - 1) ); sqlite3SetString( &zFull, zDrive, ":\\", zBuff, "\\", zRelative, (char*)0 ); } free( zBuff ); } return SQLITE_OK; }
APR_DECLARE(apr_status_t) apr_filepath_get(char **defpath, apr_int32_t flags, apr_pool_t *p) { char path[APR_PATH_MAX]; ULONG drive; ULONG drivemap; ULONG rv, pathlen = sizeof(path) - 3; char *pos; DosQueryCurrentDisk(&drive, &drivemap); path[0] = '@' + drive; strcpy(path+1, ":\\"); rv = DosQueryCurrentDir(drive, path+3, &pathlen); *defpath = apr_pstrdup(p, path); if (!(flags & APR_FILEPATH_NATIVE)) { for (pos=*defpath; *pos; pos++) { if (*pos == '\\') *pos = '/'; } } return APR_SUCCESS; }
apr_status_t filepath_drive_get(char **rootpath, char drive, apr_int32_t flags, apr_pool_t *p) { char path[APR_PATH_MAX]; char *pos; ULONG rc; ULONG bufsize = sizeof(path) - 3; path[0] = drive; path[1] = ':'; path[2] = '/'; rc = DosQueryCurrentDir(apr_toupper(drive) - 'A', path+3, &bufsize); if (rc) { return APR_FROM_OS_ERROR(rc); } if (!(flags & APR_FILEPATH_NATIVE)) { for (pos=path; *pos; pos++) { if (*pos == '\\') *pos = '/'; } } *rootpath = apr_pstrdup(p, path); return APR_SUCCESS; }
unsigned LocalGetCwd( int drive, char *where ) /****************************************/ { ULONG len; len = 256; return( StashErrCode( DosQueryCurrentDir( drive, (PBYTE)where, &len ), OP_LOCAL ) ); }
void showpath(void) { UCHAR chDisk; UCHAR achDirName[256] = ""; /* Directory name for queries */ ULONG cbDirPathLen = 0; /* Length of directory path */ APIRET rc = NO_ERROR; /* Return code */ ULONG ulDriveNum = 0; /* Drive number (A=1, B=2, C=3, ...) */ ULONG ulDriveMap = 0; /* Mapping of valid drives */ ULONG i = 0; /* A loop index */ rc = DosQueryCurrentDisk (&ulDriveNum, &ulDriveMap); chDisk=(UCHAR)(ulDriveNum+'A'-1); cbDirPathLen = 0; rc = DosQueryCurrentDir(0, achDirName, &cbDirPathLen); rc = DosQueryCurrentDir(0, achDirName, &cbDirPathLen); VioWrtTTY("[", 1, 0); VioWrtTTY(&chDisk, 1, 0); VioWrtTTY(":\\", 2, 0); VioWrtTTY(achDirName, cbDirPathLen-1, 0); VioWrtTTY("]", 1, 0); }
int QueryDriveReady( int drive ) { char curdir[255]; unsigned int maxpath = 254; int rval = 254; // turn off VIOPOPUP error window (void)DosError( 2 ); rval = ( DosQueryCurrentDir( (ULONG)drive, curdir, (PULONG)&maxpath ) == 0 ); // turn VIOPOPUP error window back on (void)DosError( 1 ); return rval; }
APIRET drvPath(UCHAR **pathbuf, ULONG *pathbuflen, ULONG drvno) { ULONG pathactlen; PUCHAR pchar; APIRET rc; pathactlen = *pathbuflen; rc = DosQueryCurrentDir( drvno, *pathbuf, &pathactlen ); if(rc==0) { if(PathSep!='\\') for(pchar=*pathbuf; *pchar; pchar++) if(*pchar=='\\') *pchar=PathSep; } else switch(rc) { case ERROR_NOT_READY: strncpy((char*)*pathbuf,"drive is not ready (no media?)",*pathbuflen); (*pathbuf)[*pathbuflen-1]='\000'; break; case ERROR_INVALID_DRIVE: strncpy((char*)*pathbuf,"invalid drive",*pathbuflen); (*pathbuf)[*pathbuflen-1]='\000'; break; case ERROR_NOT_DOS_DISK: strncpy((char*)*pathbuf,"unknown media or filesystem type",*pathbuflen); (*pathbuf)[*pathbuflen-1]='\000'; break; case ERROR_DRIVE_LOCKED: strncpy((char*)*pathbuf,"drive locked by other process",*pathbuflen); (*pathbuf)[*pathbuflen-1]='\000'; break; default: snprintf((char*)*pathbuf,*pathbuflen,"error: type helpmsg %li.",rc); // default: strncpy((char*)*pathbuf,"an unknown error occured.",*pathbuflen); (*pathbuf)[*pathbuflen-1]='\000'; break; } return rc; }
VOID FillDirListBox (HWND hwnd, CHAR *pcCurrentPath) { static CHAR szDrive [] = " :" ; FILEFINDBUF3 findbuf ; HDIR hDir = HDIR_CREATE ; SHORT sDrive ; ULONG ulDriveNum, ulDriveMap, ulCurPathLen, ulReturn, ulSearchCount = 1 ; DosQueryCurrentDisk (&ulDriveNum, &ulDriveMap) ; pcCurrentPath [0] = (CHAR) ulDriveNum + '@' ; pcCurrentPath [1] = ':' ; pcCurrentPath [2] = '\\' ; ulCurPathLen = CCHMAXPATH ; DosQueryCurrentDir (0, pcCurrentPath + 3, &ulCurPathLen) ; WinSetDlgItemText (hwnd, IDD_PATH, pcCurrentPath) ; WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_DELETEALL, NULL, NULL) ; for (sDrive = 0 ; sDrive < 26 ; sDrive++) if (ulDriveMap & 1L << sDrive) { szDrive [1] = (CHAR) sDrive + 'A' ; WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_INSERTITEM, MPFROM2SHORT (LIT_END, 0), MPFROMP (szDrive)) ; } ulReturn = DosFindFirst ("*.*", &hDir, FILE_DIRECTORY, &findbuf, sizeof findbuf, &ulSearchCount, FIL_STANDARD) ; while (!ulReturn) { if (findbuf.attrFile & 0x0010 && (findbuf.achName [0] != '.' || findbuf.achName [1])) WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_INSERTITEM, MPFROM2SHORT (LIT_SORTASCENDING, 0), MPFROMP (findbuf.achName)) ; ulReturn = DosFindNext (hDir, &findbuf, sizeof findbuf, &ulSearchCount) ; } DosFindClose (hDir) ; }
void Q_getwd (char *out, size_t size, qboolean trailing_dirsep) { ULONG l, drv; if (size < 8) COM_Error ("Too small buffer for getcwd"); l = size - 3; if (DosQueryCurrentDir(0, (PBYTE) out + 3, &l) != NO_ERROR) COM_Error ("Couldn't determine current directory"); DosQueryCurrentDisk(&drv, &l); out[0] = drv + 'A' - 1; out[1] = ':'; out[2] = '\\'; if (!trailing_dirsep) return; l = strlen(out); if (out[l - 1] == '\\' || out[l - 1] == '/') return; qerr_strlcat(__thisfunc__, __LINE__, out, "\\", size); }
int getcurdir(int __drive, char *buffer) { #define MAXPATHLEN MAXPATH long size=MAXPATHLEN; char tmp[MAXPATHLEN+1]; tmp[0]='\\'; #if 1 unsigned int old, dummy; _dos_getdrive(&old); _dos_setdrive(__drive,&dummy); if (getcwd(tmp, size) == 0) { // getcwd returns a leading backslash _dos_setdrive(old,&dummy); return 0; } _dos_setdrive(old,&dummy); strcpy(buffer,&tmp[3]); return 1; #endif // 1 #if 0 #if defined(__OS2__) size_t len; char *p; unsigned long l = MAXPATHLEN; if (DosQueryCurrentDir(__drive,tmp+1,&l)) return NULL; len = strlen(tmp) + 2; if (buffer == NULL) { if (size < len) size = len; buffer = new char[size]; } if (buffer == NULL) { errno = ENOMEM; return (0); } for (p = tmp; *p != 0; ++p) // no forward slashes please. if (*p == '/') *p = '\\'; strcpy(buffer, tmp+1); return 1; #endif // __OS2__ #endif // 0 }
const CString queryCurrentDir(char drive) { char tmp[256]; if (drive == 0) drive = queryCurrentDisk(); else drive = toupper(drive); ULONG size = sizeof(tmp); ULONG driveNo; driveNo = (drive - 'A')+1; *tmp = '\0'; if (DosQueryCurrentDir(driveNo, (PSZ)tmp, &size) != 0) { return ""; } return nativePathName(CString(drive) + ":" + pathSeparator() + tmp); }
VOID StartInstallerThread( ULONG Action ) { // Если поток уже работает - возврат. if( Installer_Thread.Processing ) return; // Запоминаем, что надо сделать. bzero( &Installer_Thread, sizeof( Installer_Thread ) ); if( Action == NIA_INSTALL ) { Installer_Thread.Install_Enhancer = 1; } else { Installer_Thread.Uninstall_Enhancer = 1; } // Узнаем рабочий каталог. { ULONG Current_drive = 0; ULONG Drive_map = 0; ULONG Length = SIZE_OF_PATH - 3; DosQueryCurrentDisk( &Current_drive, &Drive_map ); Installer_Thread.Current_directory[ 0 ] = (CHAR) Current_drive + 64; Installer_Thread.Current_directory[ 1 ] = ':'; Installer_Thread.Current_directory[ 2 ] = '\\'; DosQueryCurrentDir( 0, &Installer_Thread.Current_directory[ 3 ], &Length ); } // Создаем поток. DosCreateThread( &Installer_Thread.Installer, (PFNTHREAD) Installer_InstallerThread, 0, 0, 32768 ); // Запоминаем, что он работает. Installer_Thread.Processing = 1; // Возврат. return; }
long LocalGetFreeSpace( int drv ) /*******************************/ { struct _FSALLOCATE usage; #ifdef _M_I86 if( DosQFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) { #else if( DosQueryFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) { #endif return( -1L ); } return( usage.cbSector * usage.cSectorUnit * usage.cUnitAvail ); } error_handle LocalDateTime( sys_handle fh, int *time, int *date, int set ) /************************************************************************/ { struct _FILESTATUS fstatus; struct _FDATE *pdate; struct _FTIME *ptime; unsigned rc; pdate = (struct _FDATE *)date; ptime = (struct _FTIME *)time; if( set ) { #ifdef _M_I86 rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); #else rc = DosQueryFileInfo( fh, FIL_STANDARD, (PBYTE)&fstatus, sizeof( fstatus ) ); #endif if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); fstatus.ftimeLastWrite = *ptime; fstatus.fdateLastWrite = *pdate; rc = DosSetFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); if( rc != 0 ) { return( StashErrCode( rc, OP_LOCAL ) ); } } else { #ifdef _M_I86 rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); #else rc = DosQueryFileInfo( fh, FIL_STANDARD, (PBYTE)&fstatus, sizeof( fstatus ) ); #endif if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); *ptime = fstatus.ftimeLastWrite; *pdate = fstatus.fdateLastWrite; } return( 0 ); } error_handle LocalGetCwd( int drive, char *where ) /************************************************/ { APIRET len; len = 256; #ifdef _M_I86 return( StashErrCode( DosQCurDir( drive, (PBYTE)where, &len ), OP_LOCAL ) ); #else return( StashErrCode( DosQueryCurrentDir( drive, (PBYTE)where, &len ), OP_LOCAL ) ); #endif }
void RNG_SystemInfoForRNG(void) { unsigned long *plong = 0; PTIB ptib; PPIB ppib; APIRET rc = NO_ERROR; DATETIME dt; COUNTRYCODE cc = {0}; COUNTRYINFO ci = {0}; unsigned long actual = 0; char path[_MAX_PATH]=""; char fullpath[_MAX_PATH]=""; unsigned long pathlength = sizeof(path); FSALLOCATE fsallocate; FILESTATUS3 fstatus; unsigned long defaultdrive = 0; unsigned long logicaldrives = 0; unsigned long sysInfo[QSV_MAX] = {0}; char buffer[20]; int nBytes = 0; nBytes = RNG_GetNoise(buffer, sizeof(buffer)); RNG_RandomUpdate(buffer, nBytes); /* allocate memory and use address and memory */ plong = (unsigned long *)malloc(sizeof(*plong)); RNG_RandomUpdate(&plong, sizeof(plong)); RNG_RandomUpdate(plong, sizeof(*plong)); free(plong); /* process info */ rc = DosGetInfoBlocks(&ptib, &ppib); if (rc == NO_ERROR) { RNG_RandomUpdate(ptib, sizeof(*ptib)); RNG_RandomUpdate(ppib, sizeof(*ppib)); } /* time */ rc = DosGetDateTime(&dt); if (rc == NO_ERROR) { RNG_RandomUpdate(&dt, sizeof(dt)); } /* country */ rc = DosQueryCtryInfo(sizeof(ci), &cc, &ci, &actual); if (rc == NO_ERROR) { RNG_RandomUpdate(&cc, sizeof(cc)); RNG_RandomUpdate(&ci, sizeof(ci)); RNG_RandomUpdate(&actual, sizeof(actual)); } /* current directory */ rc = DosQueryCurrentDir(0, path, &pathlength); strcat(fullpath, "\\"); strcat(fullpath, path); if (rc == NO_ERROR) { RNG_RandomUpdate(fullpath, strlen(fullpath)); // path info rc = DosQueryPathInfo(fullpath, FIL_STANDARD, &fstatus, sizeof(fstatus)); if (rc == NO_ERROR) { RNG_RandomUpdate(&fstatus, sizeof(fstatus)); } } /* file system info */ rc = DosQueryFSInfo(0, FSIL_ALLOC, &fsallocate, sizeof(fsallocate)); if (rc == NO_ERROR) { RNG_RandomUpdate(&fsallocate, sizeof(fsallocate)); } /* drive info */ rc = DosQueryCurrentDisk(&defaultdrive, &logicaldrives); if (rc == NO_ERROR) { RNG_RandomUpdate(&defaultdrive, sizeof(defaultdrive)); RNG_RandomUpdate(&logicaldrives, sizeof(logicaldrives)); } /* system info */ rc = DosQuerySysInfo(1L, QSV_MAX, (PVOID)&sysInfo, sizeof(ULONG)*QSV_MAX); if (rc == NO_ERROR) { RNG_RandomUpdate(&sysInfo, sizeof(sysInfo)); } // now let's do some files ReadSystemFiles(); /* more noise */ nBytes = RNG_GetNoise(buffer, sizeof(buffer)); RNG_RandomUpdate(buffer, nBytes); }
INT ParseFileName (CHAR *pcOut, CHAR *pcIn) { /*---------------------------------------------------------------- Input: pcOut -- Pointer to parsed file specification. pcIn -- Pointer to raw file specification. Returns: 0 -- pcIn had invalid drive or directory. 1 -- pcIn was empty or had no filename. 2 -- pcOut points to drive, full dir, and file name. Changes current drive and directory per pcIn string. ----------------------------------------------------------------*/ CHAR *pcLastSlash, *pcFileOnly ; ULONG ulDriveNum, ulDriveMap, ulDirLen = CCHMAXPATH ; strupr (pcIn) ; // If input string is empty, return 1 if (pcIn [0] == '\0') return 1 ; // Get drive from input string or current drive if (pcIn [1] == ':') { if (DosSetDefaultDisk (pcIn [0] - '@')) return 0 ; pcIn += 2 ; } DosQueryCurrentDisk (&ulDriveNum, &ulDriveMap) ; *pcOut++ = (CHAR) ulDriveNum + '@' ; *pcOut++ = ':' ; *pcOut++ = '\\' ; // If rest of string is empty, return 1 if (pcIn [0] == '\0') return 1 ; // Search for last backslash. If none, could be directory. if (NULL == (pcLastSlash = strrchr (pcIn, '\\'))) { if (!DosSetCurrentDir (pcIn)) return 1 ; // Otherwise, get current dir & attach input filename DosQueryCurrentDir (0, pcOut, &ulDirLen) ; if (strlen (pcIn) > 12) return 0 ; if (*(pcOut + strlen (pcOut) - 1) != '\\') strcat (pcOut++, "\\") ; strcat (pcOut, pcIn) ; return 2 ; } // If the only backslash is at beginning, change to root if (pcIn == pcLastSlash) { DosSetCurrentDir ("\\") ; if (pcIn [1] == '\0') return 1 ; strcpy (pcOut, pcIn + 1) ; return 2 ; } // Attempt to change directory -- Get current dir if OK *pcLastSlash = '\0' ; if (DosSetCurrentDir (pcIn)) return 0 ; DosQueryCurrentDir (0, pcOut, &ulDirLen) ; // Append input filename, if any pcFileOnly = pcLastSlash + 1 ; if (*pcFileOnly == '\0') return 1 ; if (*(pcOut + strlen (pcOut) - 1) != '\\') strcat (pcOut++, "\\") ; strcat (pcOut, pcFileOnly) ; return 2 ; }