void hb_fsFindClose( PHB_FFIND ffind ) { if( ffind ) { if( ffind->pszFree ) hb_xfree( ffind->pszFree ); /* Do platform dependant cleanup */ if( ffind->info ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; if( ! ffind->bFirst ) { hb_vmUnlock(); #if defined( HB_OS_DOS ) # if defined( __WATCOMC__ ) _dos_findclose( &info->entry ); # elif ! defined( __DJGPP__ ) && ! defined( __BORLANDC__ ) findclose( &info->entry ); # endif #elif defined( HB_OS_OS2 ) if( info->hFindFile != HDIR_CREATE ) DosFindClose( info->hFindFile ); if( info->entry ) DosFreeMem( info->entry ); #elif defined( HB_OS_WIN ) if( info->hFindFile != INVALID_HANDLE_VALUE ) FindClose( info->hFindFile ); #elif defined( HB_OS_UNIX ) if( info->dir ) closedir( info->dir ); #else { /* Intentionally do nothing */ int iTODO; /* TODO: for given platform */ } #endif hb_vmLock(); } hb_xfree( info ); } hb_xfree( ffind ); } }
int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t* glob) { struct find_t ff; size_t found=0; char path[MAX_PATH+1]; char* p; char** new_pathv; if(!(flags&GLOB_APPEND)) { glob->gl_pathc=0; glob->gl_pathv=NULL; } if(_dos_findfirst((char*)pattern,(flags&GLOB_PERIOD) ? _A_HIDDEN : _A_NORMAL,&ff)!=0) return(GLOB_NOMATCH); do { if((flags&GLOB_PERIOD || ff.name[0]!='.') && (!(flags&GLOB_ONLYDIR) || ff.attrib&_A_SUBDIR)) { if((new_pathv=realloc(glob->gl_pathv ,(glob->gl_pathc+1)*sizeof(char*)))==NULL) { globfree(glob); return(GLOB_NOSPACE); } glob->gl_pathv=new_pathv; /* build the full pathname */ SAFECOPY(path,pattern); p=getfname(path); *p=0; strcat(path,ff.name); if((glob->gl_pathv[glob->gl_pathc]=malloc(strlen(path)+2))==NULL) { globfree(glob); return(GLOB_NOSPACE); } strcpy(glob->gl_pathv[glob->gl_pathc],path); if(flags&GLOB_MARK && ff.attrib&_A_SUBDIR) strcat(glob->gl_pathv[glob->gl_pathc],"/"); glob->gl_pathc++; found++; } } while(_dos_findnext(&ff)==0); _dos_findclose(&ff); if(found==0) return(GLOB_NOMATCH); if(!(flags&GLOB_NOSORT)) { qsort(glob->gl_pathv,found,sizeof(char*),glob_compare); } return(0); /* success */ }
_WCRTLINK int closedir( DIR_TYPE *dirp ) { if( dirp == NULL || dirp->d_first == _DIR_CLOSED ) { return( __set_errno_dos( E_ihandle ) ); } _dos_findclose( (struct _find_t *)dirp->d_dta ); dirp->d_first = _DIR_CLOSED; if( dirp->d_openpath != NULL ) free( dirp->d_openpath ); lib_free( dirp ); return( 0 ); }
static DIR_TYPE *___opendir( const char *dirname, DIR_TYPE *dirp ) /****************************************************************/ { if( dirp->d_first != _DIR_CLOSED ) { _dos_findclose( (struct _find_t *)dirp->d_dta ); dirp->d_first = _DIR_CLOSED; } if( _dos_findfirst( dirname, SEEK_ATTRIB, (struct _find_t *)dirp->d_dta ) ) { return( NULL ); } dirp->d_first = _DIR_ISFIRST; return( dirp ); }
unsigned LocalFindNext( void *info, unsigned info_len ) /*****************************************************/ { unsigned rc; rc = _dos_findnext( &Findbuf ); if( !rc ) { makeDOSDTA( &Findbuf, info ); return( 0 ); } else { _dos_findclose( &Findbuf ); return( -1 ); } }
bool WEXPORT WFileName::attribs( char* attribs ) const { struct find_t fileinfo; #define FIND_STYLE _A_NORMAL int rc = _dos_findfirst( *this, FIND_STYLE, &fileinfo ); if( rc == 0 ) { if( attribs != NULL ) { *attribs = fileinfo.attrib; } } #undef FIND_STYLE #ifndef __WINDOWS__ _dos_findclose( &fileinfo ); #endif return( rc == 0 ); }
_WCRTLINK int __F_NAME(closedir,_wclosedir)( DIR_TYPE *dirp ) { unsigned rc; if( dirp == NULL || dirp->d_first == _DIR_CLOSED ) { return( __set_errno_dos( E_ihandle ) ); } rc = _dos_findclose( (struct _find_t *)dirp->d_dta ); if( rc ) { return( rc ); } dirp->d_first = _DIR_CLOSED; if( dirp->d_openpath != NULL ) free( dirp->d_openpath ); lib_free( dirp ); return( 0 ); }
static DIR_TYPE *__F_NAME(__opendir,__wopendir)( const CHAR_TYPE *dirname ) /*************************************************************************/ { DIR_TYPE tmp; DIR_TYPE *dirp; int i; CHAR_TYPE pathname[ _MAX_PATH + 6 ]; tmp.d_attr = _A_SUBDIR; tmp.d_first = _DIR_CLOSED; i = is_directory( dirname ); if( i <= 0 ) { /* it is file or may be file or no dirname */ if( __F_NAME(___opendir,___wopendir)( dirname, &tmp ) == NULL ) { return( NULL ); } } if( i >= 0 && (tmp.d_attr & _A_SUBDIR) ) { size_t len; /* directory, add wildcards */ len = __F_NAME(strlen,wcslen)( dirname ); memcpy( pathname, dirname, len * sizeof( CHAR_TYPE ) ); if( i < 2 ) { pathname[len++] = DIR_SEP; } __F_NAME(strcpy,wcscpy)( &pathname[len], STRING( "*.*" ) ); if( __F_NAME(___opendir,___wopendir)( pathname, &tmp ) == NULL ) { return( NULL ); } dirname = pathname; } dirp = lib_malloc( sizeof( *dirp ) ); if( dirp == NULL ) { _dos_findclose( (struct _find_t *)tmp.d_dta ); __set_errno_dos( E_nomem ); return( NULL ); } tmp.d_openpath = __F_NAME(__clib_strdup,__clib_wcsdup)( dirname ); *dirp = tmp; return( dirp ); }
static DIR_TYPE *__opendir( const char *dirname ) /***********************************************/ { DIR_TYPE tmp; DIR_TYPE *dirp; int i; char pathname[_MAX_PATH + 6]; tmp.d_attr = _A_SUBDIR; tmp.d_first = _DIR_CLOSED; i = is_directory( dirname ); if( i <= 0 ) { /* it is file or may be file or no dirname */ if( ___opendir( dirname, &tmp ) == NULL ) { return( NULL ); } } if( i >= 0 && (tmp.d_attr & _A_SUBDIR) ) { size_t len; /* directory, add wildcards */ len = strlen( dirname ); memcpy( pathname, dirname, len ); if( i < 2 ) { pathname[len++] = '\\'; } strcpy( &pathname[len], "*.*" ); if( ___opendir( pathname, &tmp ) == NULL ) { return( NULL ); } dirname = pathname; } dirp = lib_malloc( sizeof( DIR_TYPE ) ); if( dirp == NULL ) { _dos_findclose( (struct _find_t *)tmp.d_dta ); __set_errno_dos( E_nomem ); return( NULL ); } tmp.d_openpath = __clib_strdup( dirname ); *dirp = tmp; return( dirp ); }
static DIR_TYPE *__F_NAME(___opendir,___wopendir)( const CHAR_TYPE *dirname, DIR_TYPE *dirp ) /*******************************************************************************************/ { #ifdef __WIDECHAR__ char mbcsName[MB_CUR_MAX * _MAX_PATH]; #endif if( dirp->d_first != _DIR_CLOSED ) { _dos_findclose( (struct _find_t *)dirp->d_dta ); dirp->d_first = _DIR_CLOSED; } /*** Convert a wide char string to a multibyte string ***/ #ifdef __WIDECHAR__ if( wcstombs( mbcsName, dirname, sizeof( mbcsName ) ) == (size_t)-1 ) { return( NULL ); } #endif if( _dos_findfirst( __F_NAME(dirname,mbcsName), SEEK_ATTRIB, (struct _find_t *)dirp->d_dta ) ) { return( NULL ); } dirp->d_first = _DIR_ISFIRST; return( dirp ); }
DIR_TYPE *__F_NAME(__opendir,__wopendir)( const CHAR_TYPE *dirname, unsigned attr, DIR_TYPE *dirp ) /**************************************************************************/ { DIR_TYPE tmp; int i; CHAR_TYPE pathname[ _MAX_PATH + 6 ]; const CHAR_TYPE *p; UINT_WC_TYPE curr_ch; UINT_WC_TYPE prev_ch; int flag_opendir = ( dirp == NULL ); int opened; /*** Convert a wide char string to a multibyte string ***/ #ifdef __WIDECHAR__ char mbcsName[ MB_CUR_MAX * _MAX_PATH ]; if( wcstombs( mbcsName, dirname, sizeof( mbcsName ) ) == (size_t)-1 ) { return( NULL ); } #endif tmp.d_attr = _A_SUBDIR; opened = 0; if( !is_directory( dirname ) ) { if( _dos_findfirst( __F_NAME(dirname,mbcsName), attr, (struct _find_t *)tmp.d_dta ) ) { return( NULL ); } opened = 1; } if( tmp.d_attr & _A_SUBDIR ) { prev_ch = NULLCHAR; p = dirname; for( i = 0; i < _MAX_PATH; i++ ) { pathname[i] = *p; #if defined( __WIDECHAR__ ) || defined( __UNIX__ ) curr_ch = *p; #else curr_ch = _mbsnextc( p ); if( curr_ch > 256 ) { ++i; ++p; pathname[i] = *p; /* copy second byte */ } #endif if( curr_ch == NULLCHAR ) { if( i != 0 && prev_ch != '\\' && prev_ch != '/' ) { pathname[i++] = '\\'; } __F_NAME(strcpy,wcscpy)( &pathname[i], STRING( "*.*" ) ); #ifdef __WIDECHAR__ if( wcstombs( mbcsName, pathname, sizeof( mbcsName ) ) == (size_t)-1 ) return( NULL ); #endif if( opened ) { _dos_findclose( (struct _find_t *)tmp.d_dta ); } if( _dos_findfirst( __F_NAME(pathname,mbcsName), attr, (struct _find_t *)tmp.d_dta ) ) { return( NULL ); } opened = 1; break; } if( curr_ch == '*' ) break; if( curr_ch == '?' ) break; ++p; prev_ch = curr_ch; } } if( flag_opendir ) { dirp = lib_malloc( sizeof( *dirp ) ); if( dirp == NULL ) { if( opened ) { _dos_findclose( (struct _find_t *)tmp.d_dta ); } __set_errno_dos( E_nomem ); return( NULL ); } tmp.d_openpath = __F_NAME(__clib_strdup,__clib_wcsdup)( dirname ); } else { _dos_findclose( (struct _find_t *)dirp->d_dta ); tmp.d_openpath = dirp->d_openpath; } tmp.d_first = _DIR_ISFIRST; *dirp = tmp; return( dirp ); }
DWORD LoadKeys(DWORD appID, const char* path, DWORD* level, BOOL* valid, CPtrArray* array) { DWORD ret=0; struct find_t ffblk; char string[0x200]; char* namePtr=NULL; if(!DATA_Init_Library((void*(*)(unsigned int))Malloc,Free)) return ret; *string=0; //GetFullPathName(path,0x200,string,&namePtr); strncpy(string,path,0x200); namePtr=strrchr(string,'\\'); if(namePtr) namePtr++; else namePtr=string; if(namePtr==NULL)namePtr=string+strlen(string); // strcpy(namePtr,"*.key"); if(_dos_findfirst(string,_A_ARCH|_A_SYSTEM|_A_HIDDEN|_A_RDONLY,&ffblk)==0) { do { if((ffblk.attrib&0x10)==0) //if(0==(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { strcpy(namePtr,ffblk.name);//FindData.cFileName); // if(!strlen(FindData.cFileName)||(DWORD)-1==GetFileAttributes(string)) // { // strcpy(namePtr,FindData.cAlternateFileName); // if(!strlen(FindData.cAlternateFileName)||(DWORD)-1==GetFileAttributes(string)) // continue; // } // ret|=LoadKey(string, array, appID); //#ifdef OLD_KEY_SUPPORT // if(!ret) ret|=LoadOldKey(string,array,appID); //#endif HDATA hRootData=0; BOOL r=LoadKey(appID, string, level, valid, hRootData); #ifdef OLD_KEY_SUPPORT if(!r)r=LoadOldKey(appID, string, level, valid, hRootData); #endif ret|=r; if(hRootData) { int i=0; if(array) { AVP_dword dseq[5]; char key1[0x80]; DATA_Get_Val(hRootData,DATA_Sequence(dseq,AVP_PID_KEYINFO,PID_SERIALSTR,0), 0, key1, 0x80); for(i=array->GetUpperBound();i>=0;i--) { char key2[0x80]; HDATA hKey=(HDATA)array->GetAt(i); if(DATA_Get_Val(hKey, dseq, 0, key2, 0x80)) if(!strcmp(key1,key2)) break; } if(i==-1) array->Add(hRootData); } if(i!=-1) DATA_Remove( hRootData, 0 ); } } }while(_dos_findnext(&ffblk)==0);// FindNextFile(hFind, &FindData)); _dos_findclose(&ffblk); } return ret; }
APIRET CreateMsgList( CHAR *path ) { INT i, done, line; INT attr = _A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH; static CHAR File[_MAX_PATH]; CHAR *string, last; struct find_t find; INDEXPKT *top, *index, **inew; InitMem(); mode = FILE_TYPE_MSG; string = malloc( MAX_BUFFER ); if( string == NULL ) return( ERROR_NOT_ENOUGH_MEMORY ); _splitpath( path, drive, dir, NULL, NULL ); strcpy( File, drive ); strcat( File, dir ); StrAddSlash( File ); strcat( File, "*.msg" ); WActive( wscan ); for( done=_dos_findfirst(File,attr,&find); !done; done=_dos_findnext(&find)) { _splitpath( find.name, NULL, NULL, fname, NULL ); strcpy( File, path ); StrAddSlash( File ); strcat( File, find.name ); if( OpenFile( File )) continue; if( !( pktcount % 5 )) { WSetXY ( wscan, 19, 2 ); if( pktcount == 0 ) WPrintf( wscan, "%4u", 1 ); else WPrintf( wscan, "%4u", pktcount ); } fread( &msg, sizeof( msg ), 1, PktFile ); AddNextStruct( pktIndex, top ); if( top == NULL ) { free( string ); return( ERROR_NOT_ENOUGH_MEMORY ); } top -> size = filelength( fileno( PktFile )); strcpy( string, msg.to ); string[ MAX_TO ] = 0; top -> to = strdup( string ); strcpy( string, msg.from ); string[ MAX_FROM ] = 0; top -> from = strdup( string ); strcpy( string, msg.subj ); string[ MAX_SUBJ ] = 0; top -> subj = strdup( string ); strcpy( string, msg.date ); string[ MAX_DATE ] = 0; top -> date = strdup( string ); top -> AddrFrom.Zone = 0; top -> AddrFrom.Net = msg.orig_net; top -> AddrFrom.Node = msg.orig_node; top -> AddrFrom.Point = 0; top -> AddrFrom.Domain[0] = 0; top -> AddrTo.Zone = 0; top -> AddrTo.Net = msg.dest_net; top -> AddrTo.Node = msg.dest_node; top -> AddrTo.Point = 0; top -> AddrTo.Domain[0] = 0; top -> attr = msg.attrib; top -> number = atol( fname ); top -> name = strdup( find.name ); top -> area = NULL; top -> sel = ' '; top -> change = 0; FidoMsgGetStrSeek( PktFile, 0, SEEK_CUR ); i = line = 0; while( FidoMsgGetStr( string, MAX_BUFFER - 1, PktFile, &last ) != NULL ) { CheckString( string, i, top ); if( !Quick ) break; if( i && strncmp( string, "AREA:", 5 )) { if( line < MAX_LINE && string[0] != '\001' && StrSkipSpace( string )) { top -> quick[line] = strdup( string ); top -> color[line] = GetLineColor( i, string ); line++; } } if( last == 0 || line >= MAX_LINE ) break; i++; } CloseFile(); CheckString( NULL, 0, top ); pktcount++; } _dos_findclose( &find ); free( string ); if( pktcount == 0 ) { WDeactive( wscan ); return( 0 ); } if( cfgCurrent.sort ) { inew = calloc( pktcount, sizeof( *inew )); if( inew == NULL ) return( ERROR_NOT_ENOUGH_MEMORY ); for( i = 0, index = pktIndex; index; index = index -> next, i++ ) inew[i] = index; MShellSort( inew, pktcount, sizeof( *inew ), SortNumber ); pktIndex = inew[0]; for( i = 1; i < pktcount; i++ ) inew[i-1] -> next = inew[i]; inew[i-1] -> next = NULL; free( inew ); pktOrigin = malloc( pktcount * sizeof( *pktOrigin )); if( pktOrigin == NULL ) return( ERROR_NOT_ENOUGH_MEMORY ); for( i = 0, index = pktIndex; index; index = index -> next, i++ ) pktOrigin[i] = index; } WDeactive( wscan ); return( NO_ERROR ); }