b_file *Openf( char *f, f_attrs attrs ) { // Open a file. int retc; long int fpos; #if defined( __WATCOMC__ ) || !defined( __UNIX__ ) int share; share = SH_COMPAT; if( attrs & S_DENYRW ) { share = SH_DENYRW; } else if( attrs & S_DENYWR ) { share = SH_DENYWR; } else if( attrs & S_DENYRD ) { share = SH_DENYRD; } else if( attrs & S_DENYNO ) { share = SH_DENYNO; } #endif if( attrs & WRONLY ) { attrs |= WRITE_ONLY; if( attrs & APPEND ) { retc = sopen4( f, O_WRONLY | O_BINARY | O_CREAT, share, PMODE_RW ); } else { retc = sopen4( f, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, share, PMODE_RW ); } } else if( attrs & RDONLY ) { retc = sopen3( f, O_RDONLY | O_BINARY, share ); } else { // if( attrs & RDWR ) { retc = sopen4( f, O_RDWR | O_BINARY | O_CREAT, share, PMODE_RW ); } if( retc < 0 ) { FSetSysErr( NULL ); return( NULL ); } fpos = 0; if( attrs & APPEND ) { fpos = lseek( retc, 0, SEEK_END ); if( fpos < 0 ) { FSetSysErr( NULL ); close( retc ); return( NULL ); } } return( _AllocFile( retc, attrs, fpos ) ); }
/* * DIPCliOpen */ dig_fhandle DIGCLIENT DIGCliOpen( const char *path, dig_open mode ) { dig_fhandle ret; int flags; flags = O_BINARY; if( mode & DIG_READ ) flags |= O_RDONLY; if( mode & DIG_WRITE ) flags |= O_WRONLY; if( mode & DIG_TRUNC ) flags |= O_TRUNC; if( mode & DIG_CREATE ) { flags |= O_CREAT; ret = (dig_fhandle)sopen4( path, flags, SH_DENYWR, S_IRWXU | S_IRWXG | S_IRWXO ); } else { ret = (dig_fhandle)sopen3( path, flags, SH_DENYWR ); } return( ret ); }
/* * AutoSaveInit - initialize for auto-save */ void AutoSaveInit( void ) { char path[FILENAME_MAX]; char path2[FILENAME_MAX]; char as_path[FILENAME_MAX]; char asl_path[FILENAME_MAX]; int len; int cnt; FILE *f; int pid; int ch; int handle; int off; // int old_len; int i; /* * initialize tmpname */ #ifdef __UNIX__ strcpy( currTmpName,"aaaaaaaaaaaa.tmp" ); #else strcpy( currTmpName,"aaaaaaaa.tmp" ); #endif pid = getpid(); itoa( pid, path, 36 ); len = strlen( path ); memcpy( &currTmpName[TMP_FNAME_LEN - len], path, len ); #ifdef __QNX__ { int len2, len3; int nid, uid; nid = getnid(); itoa( nid, path, 36 ); len2 = strlen( path ); memcpy( &currTmpName[TMP_FNAME_LEN - len - len2], path, len2 ); uid = getuid(); itoa( uid, path, 36 ); len3 = strlen( path ); memcpy( &currTmpName[TMP_FNAME_LEN - len - len2 - len3], path, len3 ); memcpy( &checkFileName[EXTRA_EXT_OFF], path, len3 ); memcpy( &checkFileTmpName[EXTRA_EXT_OFF], path, len3 ); memcpy( &lockFileName[EXTRA_EXT_OFF], path, len3 ); } #endif /* * check if we need to recover lost files */ if( EditFlags.RecoverLostFiles ) { cnt = 0; MakeTmpPath( as_path, checkFileName ); MakeTmpPath( asl_path, lockFileName ); off = strlen( as_path ) - 5; for( ch = START_CHAR; ch <= END_CHAR; ch++ ) { as_path[off] = ch; asl_path[off] = ch; handle = sopen3( as_path, O_RDONLY | O_TEXT, SH_DENYRW ); if( handle < 0 ) { continue; } f = fdopen( handle, "r" ); if( f != NULL ) { while( fgets( path2, FILENAME_MAX, f ) != NULL ) { for( i = strlen( path2 ); i && isWSorCtrlZ( path2[i - 1] ); --i ) { path2[i - 1] = '\0'; } NextWord1( path2, path ); RemoveLeadingSpaces( path2 ); NewFile( path, FALSE ); AddString2( &(CurrentFile->name), path2 ); SetFileWindowTitle( CurrentWindow, CurrentInfo, TRUE ); FileSPVAR(); CurrentFile->modified = TRUE; CurrentFile->check_readonly = TRUE; FTSRunCmds( path2 ); cnt++; } fclose( f ); remove( as_path ); } else { close( handle ); } remove( asl_path ); } if( cnt == 0 ) { MyPrintf( "No files recovered!\n" ); ExitEditor( -1 ); } Message1( "%d files recovered", cnt ); } if( EditVars.AutoSaveInterval == 0 ) { return; } // old_len = strlen( lockFileName ); MakeTmpPath( path, lockFileName ); len = strlen( path ) - strlen( lockFileName ); off = len + CHAR_OFF; for( ch = START_CHAR; ch <= END_CHAR; ch++ ) { path[off] = ch; lockFileHandle = sopen4( path, O_CREAT | O_TRUNC | O_RDWR | O_TEXT, SH_DENYRW, PMODE_RW ); if( lockFileHandle > 0 ) { break; } } if( lockFileHandle < 0 ) { // MyPrintf( "Too many editors running!\n" ); MyPrintf( "Error opening temp file - '%s'\n", strerror( errno ) ); ExitEditor( -1 ); } lockFileName[CHAR_OFF] = ch; checkFileName[CHAR_OFF] = ch; checkFileTmpName[CHAR_OFF] = ch; } /* AutoSaveInit */
void PCHeaderCreate( char *include_file ) /***************************************/ { char * volatile pch_fname; // must be preserved by setjmp() int status; auto jmp_buf restore_state; #ifndef NDEBUG clock_t start; clock_t stop; start = clock(); #endif if( ErrCount != 0 ) { return; } if( CompFlags.fhr_switch_used ) { // treat any .PCH as read-only (do not create one) return; } pch_fname = PCHFileName(); pchFile = sopen4( pch_fname, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, SH_DENYRW, PMODE_RW ); if( pchFile == -1 ) { CErr2p( ERR_PCH_CREATE_ERROR, pch_fname ); return; } bufferPosition = 0; ioBuffer = CMemAlloc( IO_BUFFER_SIZE ); bufferCursor = ioBuffer; amountLeft = IO_BUFFER_SIZE; abortData = &restore_state; status = setjmp( restore_state ); if( status == 0 ) { unsigned long brinf_posn; if( CompFlags.pch_debug_info_opt ) { pchDebugInfoName = CppPCHDebugInfoName( include_file ); } dumpHeader(); dumpCheckData( include_file ); execInitFunctions( true ); execControlFunctions( true, writeFunctions ); execFiniFunctions( true ); brinf_posn = BrinfPch( pchFile ); PCHFlushBuffer(); // keep this PCH file pch_fname = NULL; setOKHeader( brinf_posn ); } else { CErr1( ERR_PCH_WRITE_ERROR ); } abortData = NULL; CMemFreePtr( &ioBuffer ); close( pchFile ); if( pch_fname != NULL ) { // write error occurred; delete PCH file remove( pch_fname ); } else { if( CompFlags.pch_debug_info_opt ) { CompFlags.pch_debug_info_write = true; CompFlags.all_debug_type_names = true; } } #ifndef NDEBUG stop = clock(); printf( "%u ticks to parse header\n", (unsigned)( start - start_parse ) ); printf( "%u ticks to save pre-compiled header\n", (unsigned)( stop - start ) ); #endif }