Ejemplo n.º 1
0
static void TalkPoll()
{
    if(!rainin)
    {
        rainin=_fsopen(raincmdname,"rt",SH_DENYNO);
        if(rainin) setbuf(rainin,NULL);
    }
    if(rainin)
    {
        ParseString("0"); //just 50 or more Hz polling with no command
        a:
        fgets(input+inputlen,MAX_LINE_LENGTH-inputlen,rainin);
        inputlen+=strlen(input+inputlen);
        if ((inputlen && input[inputlen-1]=='\n') || inputlen>=MAX_LINE_LENGTH-1)
        {
            ParseString(input); //parse real command
            inputlen=0;
            input[0]=0;
            goto a;  //parse all commands until end of file
        }
    }
    {
        char *err;
        while (err=errGet())
        {
            fprintf(rainout,"%s\n",err);
            free(err);
        }
    }
}
Ejemplo n.º 2
0
FILE *
Fopen(const char *name, const char *mode)
{
  FILE *fd;

  if (db2) printf(">>> Fopen '%s', mode '%s'\n", name, mode);

#if defined(_WIN32)
  fd = _fsopen(name, mode, _SH_DENYNO);
#else
  fd = fopen(name, mode);
#endif

  if (fd == NULL) {
    printf("<<< Fopen failed on '%s', mode '%s'\n", name, mode);
    return ((FILE*) NULL);
  }

  if (strncmp(mode, "a", 1) == 0) {
    if (db3) printf("* Append mode, seeking to end.\n");
    fseek(fd, 0L, SEEK_SET);
  }

  if (db2) printf("<<< Fopen: '%s'\n", name);

  return(fd);
}
Ejemplo n.º 3
0
void Log(const char szFormat[], ...)
	{
	if (0 == g_strListFileName[0])
		return;

	static FILE *f = NULL;
	const char *mode;
	if (g_bListFileAppend)
		mode = "a";
	else
		mode = "w";
	if (NULL == f)
		f = _fsopen(g_strListFileName, mode, _SH_DENYNO);
	if (NULL == f)
		{
		perror(g_strListFileName);
		exit(EXIT_NotStarted);
		}

	char szStr[4096];
	va_list ArgList;
	va_start(ArgList, szFormat);
	vsprintf(szStr, szFormat, ArgList);
	fprintf(f, "%s", szStr);
	fflush(f);
	}
Ejemplo n.º 4
0
void Log(char* szFormat, ...)
{
	va_list vaArgs;

	va_start(vaArgs, szFormat);
	int len = _vscprintf(szFormat, vaArgs);
	char* szString = new char[len+1];
	vsprintf_s(szString, len+1, szFormat, vaArgs);
	va_end(vaArgs);

	time_t tTime;
	time(&tTime);
	char szTime[128] = "";
	struct tm time;
	localtime_s(&time, &tTime);
	strftime(szTime, sizeof(szTime), "%x %X", &time);

	char path[_MAX_PATH+_MAX_FNAME] = "";
	sprintf_s(path, sizeof(path), "%sd2bs.log", Vars.szPath);

#ifdef DEBUG
	FILE* log = stderr;
#else
	FILE* log = _fsopen(path, "a+", _SH_DENYNO);
#endif
	fprintf(log, "[%s] D2BS %d: %s\n", szTime, GetProcessId(GetCurrentProcess()), szString);
#ifndef DEBUG
	fflush(log);
	fclose(log);
#endif
	delete[] szString;
}
Ejemplo n.º 5
0
int EsifLogFile_Open(EsifLogType type, const char *filename, int append)
{
	int rc=0;
	char fullpath[MAX_PATH]={0};
	char mode[3] = {(append ? 'a' : 'w'), 0, 0};

	esif_ccb_write_lock(&g_EsifLogFile[type].lock);
	if (g_EsifLogFile[type].handle != NULL)
		esif_ccb_fclose(g_EsifLogFile[type].handle);

	EsifLogFile_GetFullPath(fullpath, sizeof(fullpath), filename);
#ifdef ESIF_ATTR_OS_WINDOWS
	mode[1] = 'c';
	g_EsifLogFile[type].handle = _fsopen(fullpath, mode, _SH_DENYWR);
	if (g_EsifLogFile[type].handle == NULL)
		rc = errno;
#else
	rc = esif_ccb_fopen(&g_EsifLogFile[type].handle, fullpath, mode);
#endif
	if (rc == 0) {
		esif_ccb_free(g_EsifLogFile[type].filename);
		g_EsifLogFile[type].filename = esif_ccb_strdup((char *)fullpath);
	}
	esif_ccb_write_unlock(&g_EsifLogFile[type].lock);
	return rc;
}
Ejemplo n.º 6
0
void start_log(void) {
	if (log_fp!=NULL)
		return;

	CSLock lock(log_critsec);

	CString fn = p_filenames->LogFilename();
	// Check, if file exists and size is too large
	struct stat file_stats = { 0 };
	if (stat(fn.GetString(), &file_stats) == 0)
	{
		unsigned long int max_file_size = 1E06 * preferences.log_max_logsize();
		size_t file_size = file_stats.st_size;
		if (file_size > max_file_size)
		{
			remove(fn.GetString());
		}
	}

	// Append (or create) log
	if ((log_fp = _fsopen(fn.GetString(), "a", _SH_DENYWR)) != 0) {
		write_log_separator(k_always_log_basic_information, "LOG FILE OPEN");
		fflush(log_fp);
	}

}
Ejemplo n.º 7
0
bool OpenLog()
{
	// open
	sLogFileName = C4CFN_Log; int iLog = 2;
#ifdef _WIN32
	while (!(C4LogFile = _fsopen(Config.AtUserDataPath(sLogFileName.getData()), "wt", _SH_DENYWR)))
#elif defined(HAVE_SYS_FILE_H)
	int fd = 0;
	while (!(fd = open(Config.AtUserDataPath(sLogFileName.getData()), O_WRONLY | O_CREAT, 0644)) || flock(fd, LOCK_EX|LOCK_NB))
#else
	while (!(C4LogFile = fopen(Config.AtUserDataPath(sLogFileName.getData()), "wb")))
#endif
	{
		// Already locked by another instance?
#if !defined(_WIN32) && defined(HAVE_SYS_FILE_H)
		if (fd) close(fd);
#else
		if (C4LogFile) fclose(C4LogFile);
#endif
		// If the file does not yet exist, the directory is r/o
		// don't go on then, or we have an infinite loop
		if (access(Config.AtUserDataPath(sLogFileName.getData()), 0))
			return false;
		// try different name
		sLogFileName.Format(C4CFN_LogEx, iLog++);
	}
#if !defined(_WIN32) && defined(HAVE_SYS_FILE_H)
	ftruncate(fd, 0);
	C4LogFile = fdopen(fd, "wb");
#endif
	// save start time
	time(&C4LogStartTime);
	return true;
}
Ejemplo n.º 8
0
// which music was playing on last quitting
static void recored_list_log(int curidx)
{
    FILE* pf = _fsopen("list.record", "wb+", _SH_DENYNO);
    fwrite(&curidx, sizeof(curidx), 1, pf);
    fclose(pf);
    pf = NULL;
}
Ejemplo n.º 9
0
static void init_dbgfp()
{
#if _DBG
	if (!dbgfp) {
#if (!HIME_IME || 1) && !CONSOLE_OFF
		AllocConsole();
		fclose(stdout);
		fclose(stderr);
		int fh = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), 0);
		_dup2(fh, 1);
		_dup2(fh, 2);
		_fdopen(1, "wt");
		_fdopen(2, "wt");
		fflush(stdout);
#endif
		char tt[512];
#if HIME_IME
		sprintf(tt, "C:\\dbg\\ime%x", GetCurrentProcessId());
#elif HIME_SVR
		sprintf(tt, "C:\\dbg\\svr%x", GetCurrentProcessId());
#else
		sprintf(tt, "C:\\dbg\\other%x", GetCurrentProcessId());
#endif
		dbgfp=_fsopen(tt, "wt",  _SH_DENYWR);
		setbuf(dbgfp, NULL);

		char exe[MAX_PATH];
		GetModuleFileNameA(NULL, exe, sizeof(exe));
		dbg("started %s\n", exe);
	}
#endif
}
Ejemplo n.º 10
0
// ----------------------------------------------------------------------------
//
bool SpotifyEngine::_readCredentials( CString& username, CString& credentials )
{
    CString filename;
    filename.Format( "%s\\DMXStudio\\SpotifyCredentials", getUserDocumentDirectory() );

    username.Empty();
    credentials.Empty();

    if ( GetFileAttributes( filename ) == INVALID_FILE_ATTRIBUTES )
        return false;

    FILE* hFile = _fsopen( filename, "rt", _SH_DENYWR );
    if ( hFile == NULL )
        return false;

    LPSTR lpUsername = username.GetBufferSetLength( 256 );
    LPSTR lpCredentials = credentials.GetBufferSetLength( 2048 );

    size_t read = fscanf_s( hFile, "%s %s", lpUsername, 256, lpCredentials, 256 );

    username.ReleaseBuffer();
    credentials.ReleaseBuffer();
    fclose( hFile );

    return read == 2;
}
Ejemplo n.º 11
0
void start_log(void) 
{
	if (log_fp!=NULL)
		return;

	CSLock lock(log_critsec);

	CString fn = p_filenames->LogFilename();
	// Check, if file exists and size is too large
	struct stat file_stats = { 0 };
	if (stat(fn.GetString(), &file_stats) == 0)
	{
		unsigned long int max_file_size = 1E06 * prefs.log_max_logsize();
		size_t file_size = file_stats.st_size;
		if (file_size > max_file_size)
		{
			remove(fn.GetString());
		}
	}

	// Append (or create) log
	if ((log_fp = _fsopen(fn.GetString(), "a", _SH_DENYWR)) != 0)
	{
		write_log(k_always_log_basic_information, "! log file open\n");
		fprintf(log_fp, "yyyy.mm.dd hh:mm:ss -  # hand commoncard rank poker  win  los  tie  P      nit bestaction - play*      call       bet       pot   balance - FCKRA FCKRA swag\n"); //!! nit		fprintf(log_fp, "----------------------------------------------------------------------------------------------------------------------------------------------------------\n");
		fflush(log_fp);
	}

}
Ejemplo n.º 12
0
FILE *sh_fopen (char *filename, char *access, int shmode)
{
   FILE *fp;
#if !defined(__LINUX__)
   long t1, t2;
#endif

#if defined(__LINUX__)
   fp = fopen (filename, access);
   shmode = shmode;
#else
   t1 = time (NULL);

   while (time (NULL) < t1 + 20) {
      if ((fp = _fsopen (filename, access, shmode)) != NULL)
         break;
#if !defined(__LINUX__)
      if (errno != EACCES)
         break;
#endif
      t2 = time (NULL);
      while (time (NULL) < t2 + 1)
         ;
   }
#endif

   return (fp);
}
Ejemplo n.º 13
0
FILE *openLog(const char *func, const char *file, int line) {
	char timestamp[TIMESTAMP_BUFFER_LEN];
#ifdef _WIN32
	char delimiter = '\\';
	SYSTEMTIME now;
	FILE *log;
	GetLocalTime(&now);
	sprintf_s(timestamp, TIMESTAMP_BUFFER_LEN, "%d-%02d-%02d %02d:%02d:%02d.%03d", now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond, now.wMilliseconds);
#else
	char delimiter = '/';
	struct timeval tv;
	time_t curtime;
	gettimeofday(&tv, NULL);
	curtime = tv.tv_sec;
	strftime(timestamp, 30, "%Y-%m-%d %T", localtime(&curtime));
#ifdef __APPLE__
	sprintf(timestamp + strlen(timestamp), ".%03i ", tv.tv_usec / 1000);
#else
	sprintf(timestamp + strlen(timestamp), ".%03li ", tv.tv_usec / 1000);
#endif
#endif
#ifndef _WIN32
	FILE *log = fopen(getLogFilename(), "a");
#else
	log = _fsopen(getLogFilename(), "a", _SH_DENYNO);
#endif
	fprintf(log, "%s ", timestamp);
	if (file) {
		char *f = strrchr((char *)file, delimiter);
		if (!f) f = (char *)file;
		else f++;
		fprintf(log, "%s() [%s:%i] ", func, f, line);
	}
	return log;
}
Ejemplo n.º 14
0
void write_log_pokertracker(int level, char* fmt, ...) 
{
    char		buff[10000] ;
    va_list		ap;
    char		nowtime[26];
	FILE		*fp=NULL;

	if (level>prefs.log_level_pt())
		return;

    CString fn;
    fn.Format("%s\\oh_pt_%lu.log", _startup_path, p_sessioncounter->session_id());

	if ((fp = _fsopen(fn.GetString(), "a", _SH_DENYWR)) != 0)
	{
        va_start(ap, fmt);
        vsprintf_s(buff, 10000, fmt, ap);
		get_time(nowtime);
        fprintf(fp, "%s - %s", nowtime, buff);

        va_end(ap);

        fflush(fp);
		fclose(fp);
    }
}
Ejemplo n.º 15
0
nfsstat3 CNFS3Prog::ProcedureWRITE(void)
{
    char *path;
    offset3 offset;
    count3 count;
    stable_how stable;
    opaque data;
    wcc_data file_wcc;
    writeverf3 verf;
    nfsstat3 stat;
    FILE *pFile;

    PrintLog("WRITE");
    path = GetPath();
    Read(&offset);
    Read(&count);
    Read(&stable);
    Read(&data);
    stat = CheckFile(path);

    file_wcc.before.attributes_follow = GetFileAttributesForNFS(path, &file_wcc.before.attributes);

    if (stat == NFS3_OK) {       
        pFile = _fsopen(path, "r+b", _SH_DENYWR);

        if (pFile != NULL) {
            _fseeki64(pFile, offset, SEEK_SET) ;
            count = fwrite(data.contents, sizeof(char), data.length, pFile);
            fclose(pFile);
        } else {
            char buffer[BUFFER_SIZE];
            errno_t errorNumber = errno;
            strerror_s(buffer, BUFFER_SIZE, errorNumber);
            PrintLog(buffer);

            if (errorNumber == 13) {
                stat = NFS3ERR_ACCES;
            } else {
                stat = NFS3ERR_IO;
            }
        }

        stable = FILE_SYNC;
        verf = 0;
    }

    file_wcc.after.attributes_follow = GetFileAttributesForNFS(path, &file_wcc.after.attributes);

    Write(&stat);
    Write(&file_wcc);

    if (stat == NFS3_OK) {
        Write(&count);
        Write(&stable);
        Write(&verf);
    }

    return stat;
}
Ejemplo n.º 16
0
void start_log(void) 
{
	if (prefs.log_level()==0)
		return;
	
	if (log_fp!=NULL)
		return;

    CString fn;
	CSLock lock(log_critsec);

    fn.Format("%s\\oh_%lu.log", _startup_path, p_sessioncounter->session_id());
	
	// Check, if file exists and size is too large
	if ((log_fp = _fsopen(fn.GetString(), "r", _SH_DENYWR)) != 0)
	{
		LARGE_INTEGER file_size;
		unsigned long int max_file_size = 1E06 * prefs.log_max_logsize();
		if (GetFileSizeEx(log_fp, &file_size))
		{
			if ((file_size.HighPart > 0) || (file_size.LowPart > max_file_size ))
			{
				fclose(log_fp);
				remove(fn.GetString());
			}
		}
		else
		{
			fclose(log_fp);
		}
	}

#ifdef DEBUG
	OpenDebuggingConsole();
#endif

	// Append (or create) log
	if ((log_fp = _fsopen(fn.GetString(), "a", _SH_DENYWR)) != 0)
	{
		write_log(1, "! log file open\n");
		fprintf(log_fp, "yyyy.mm.dd hh:mm:ss -  # hand commoncard rank poker  win  los  tie  P      nit bestaction - play*      call       bet       pot   balance - FCKRA FCKRA swag\n");
		fprintf(log_fp, "----------------------------------------------------------------------------------------------------------------------------------------------------------\n");
		fflush(log_fp);
	}

}
Ejemplo n.º 17
0
bool cFile::Open(const AString & iFileName, eMode iMode)
{
	ASSERT(!IsOpen());  // You should close the file before opening another one

	if (IsOpen())
	{
		Close();
	}

	const char * Mode = nullptr;
	switch (iMode)
	{
		case fmRead:      Mode = "rb";  break;
		case fmWrite:     Mode = "wb";  break;
		case fmReadWrite: Mode = "rb+"; break;
		case fmAppend:    Mode = "a+";  break;
	}
	if (Mode == nullptr)
	{
		ASSERT(!"Unhandled file mode");
		return false;
	}

	#ifdef _WIN32
		m_File = _fsopen((FILE_IO_PREFIX + iFileName).c_str(), Mode, _SH_DENYWR);
	#else
		m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), Mode);
	#endif  // _WIN32

	if ((m_File == nullptr) && (iMode == fmReadWrite))
	{
		// Fix for MS not following C spec, opening "a" mode files for writing at the end only
		// The file open operation has been tried with "read update", fails if file not found
		// So now we know either the file doesn't exist or we don't have rights, no need to worry about file contents.
		// Simply re-open for read-writing, erasing existing contents:

		#ifdef _WIN32
			m_File = _fsopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+", _SH_DENYWR);
		#else
			m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+");
		#endif  // _WIN32

	}
	return (m_File != nullptr);
}
Ejemplo n.º 18
0
/*-------------------------------------------------------------------------*/
APIRET OpenFile( CHAR *netfile )
{
    ReadOnly = FALSE;

    if(( PktFile = _fsopen( netfile, "rb+", SH_DENYWR )) == NULL )
    {
        if(( PktFile = _fsopen( netfile, "rb", SH_DENYWR )) == NULL )
        {
            ShowError( "Can't open file '%s'", ShowPath( netfile, 50 ));
            return( ERROR_OPEN_FAILED );
        }
        ReadOnly = TRUE;
    }
    
    setvbuf( PktFile, iobuf, _IOFBF, SIZEIOBUF );
    
    return( NO_ERROR );
}
Ejemplo n.º 19
0
// ----------------------------------------------------------------------------
//
void SpotifyEngine::_writeCredentials( LPCSTR username, LPCSTR credentials )
{
    CString filename;
    filename.Format( "%s\\DMXStudio\\SpotifyCredentials", getUserDocumentDirectory() );

    FILE* hFile = _fsopen( filename, "wt", _SH_DENYWR );
    fprintf( hFile, "%s %s", username, credentials );
    fclose( hFile );
}
Ejemplo n.º 20
0
nfsstat3 CNFS3Prog::ProcedureCREATE(void)
{
    char *path;
    createhow3 how;
    post_op_fh3 obj;
    post_op_attr obj_attributes;
    wcc_data dir_wcc;
    nfsstat3 stat;
    FILE *pFile;

    PrintLog("CREATE");
    std::string dirName;
    std::string fileName;
    ReadDirectory(dirName, fileName);
    path = GetFullPath(dirName, fileName);
    Read(&how);

    dir_wcc.before.attributes_follow = GetFileAttributesForNFS((char*)dirName.c_str(), &dir_wcc.before.attributes);

    pFile = _fsopen(path, "wb", _SH_DENYWR);
       
    if (pFile != NULL) {
        fclose(pFile);
        stat = NFS3_OK;
    } else {
        char buffer[BUFFER_SIZE];
        errno_t errorNumber = errno;
        strerror_s(buffer, BUFFER_SIZE, errorNumber);
        PrintLog(buffer);

        if (errorNumber == 2) {
            stat = NFS3ERR_STALE;
        } else if (errorNumber == 13) {
            stat = NFS3ERR_ACCES;
        } else {
            stat = NFS3ERR_IO;
        }
    }

    if (stat == NFS3_OK) {
        obj.handle_follows = GetFileHandle(path, &obj.handle);
        obj_attributes.attributes_follow = GetFileAttributesForNFS(path, &obj_attributes.attributes);
    }
    
    dir_wcc.after.attributes_follow = GetFileAttributesForNFS((char*)dirName.c_str(), &dir_wcc.after.attributes);

    Write(&stat);

    if (stat == NFS3_OK) {
        Write(&obj);
        Write(&obj_attributes);
    }

    Write(&dir_wcc);

    return stat;
}
Ejemplo n.º 21
0
CBGLog::CBGLog(DWORD dwFileNumber)
{
    const std::string strLogName = "BGLog" + std::to_string(dwFileNumber) + ".txt";
    std::string strCurrentDir;
    GetCurrentPath(strCurrentDir);

    m_stLogInfo.strFilePath = strCurrentDir + "\\" + strLogName;
    m_stLogInfo.pFile = _fsopen(m_stLogInfo.strFilePath.c_str(), "a+", _SH_DENYNO);
}
Ejemplo n.º 22
0
// ----------------------------------------------------------------------------
//
AnalyzeInfo* SpotifyEngine::loadTrackAnalysis( LPCSTR spotify_id )
{
    TrackAnalysisCache::iterator it = m_track_analysis_cache.find( spotify_id );
    if ( it != m_track_analysis_cache.end() )
        return (it)->second;

    // See if it existing on disk - if available, load into the cache and return
    CString filename = makeTrackAnalysisFileName( m_trackAnalysisContainer, spotify_id );

    if ( GetFileAttributes( filename ) == INVALID_FILE_ATTRIBUTES )
        return NULL;

    FILE* hFile = _fsopen( filename, "rt", _SH_DENYWR );
    if ( hFile == NULL ) {
        log( "Unable to read track analysis from %s", filename );
        return NULL;
    }

    // Get file size
    fseek( hFile, 0L, SEEK_END );
    size_t size = ftell( hFile );
    rewind( hFile );

    CString data;
    fread( data.GetBufferSetLength(size), 1, size, hFile );
    fclose( hFile );
        
    SimpleJsonParser parser;

    try {
        parser.parse( data );

        CString spotify_id = parser.get<CString>( "link" );

        SimpleJsonParser amplitute_parser = parser.get<SimpleJsonParser>( "amplitude" );

        size_t data_count = amplitute_parser.get<size_t>( "data_count" );
        UINT duration_ms = amplitute_parser.get<size_t>( "duration_ms" );
        std::vector<uint16_t> amplitude_data = amplitute_parser.getArray<uint16_t>( "data" );

        AnalyzeInfo* info = (AnalyzeInfo*)calloc( sizeof(AnalyzeInfo) + (sizeof(uint16_t) * data_count), 1 );
        for ( size_t i=0; i < data_count; i++ )
            info->data[i] = amplitude_data[i];

        strncpy_s( info->link, spotify_id, sizeof(info->link) );
        info->data_count = data_count;
        info->duration_ms = duration_ms;
        m_track_analysis_cache[info->link] = info;

        return info;
    }
    catch ( std::exception& e ) {
        log( StudioException( "JSON parser error (%s) data (%s)", e.what(), data ) );
        return NULL;
    }
}
Ejemplo n.º 23
0
void yazici_dosyasi_yarat(char *dosya_adi)
{
	FILE *fp;

	if ((fp = _fsopen(dosya_adi, "wb", SH_DENYNO)) == NULL) {
		msj_kutu(NULL, "Disk kay�t hatas�", HATA);
		exit(1);
	}
	fclose(fp);
}
Ejemplo n.º 24
0
void IDebugLog::Open(const char * path)
{
	logFile = _fsopen(path, "w", _SH_DENYWR);

	if(!logFile)
	{
		UInt32	id = 0;
		char	name[1024];

		do
		{
			sprintf_s(name, sizeof(name), "%s%d", path, id);
			id++;

			logFile = NULL;
			logFile = _fsopen(name, "w", _SH_DENYWR);
		}
		while(!logFile && (id < 5));
	}
}
Ejemplo n.º 25
0
void dizayn_yukle(char *dosya_adi, char *yazdirma_alani)
{
	FILE *fp;

	if ((fp = _fsopen(dosya_adi, "rb", SH_DENYNO)) == NULL) {
		msj_kutu(dosya_adi_ayir(dosya_adi), HATA_DOSYA_BULUNAMADI, HATA);
		exit(1);
	}
	fseek(fp, 0, SEEK_SET);
	fread(yazdirma_alani, 1, 4920, fp);
	fclose(fp);
}
Ejemplo n.º 26
0
void OpenLog( const char *name )
{
#ifdef __UNIX__
    LogFile = fopen( name, "w" );
#else
    LogFile = _fsopen( name, "w", SH_DENYWR );
#endif
    if( LogFile == NULL ) {
        Fatal( "Can not open '%s': %s\n", name, strerror( errno ) );
    }
    setvbuf( LogFile, NULL, _IOLBF, BUFSIZ );
}
Ejemplo n.º 27
0
nfsstat3 CNFS3Prog::ProcedureREAD(void)
{
    char *path;
    offset3 offset;
    count3 count;
    post_op_attr file_attributes;
    bool eof;
    opaque data;
    nfsstat3 stat;
    FILE *pFile;

    PrintLog("READ");
    path = GetPath();
    Read(&offset);
    Read(&count);
    stat = CheckFile(path);

    if (stat == NFS3_OK) {
        data.SetSize(count);
        pFile = _fsopen(path, "rb", _SH_DENYWR);

        if (pFile != NULL) {
            _fseeki64(pFile, offset, SEEK_SET) ;
            count = fread(data.contents, sizeof(char), count, pFile);
            eof = fgetc(pFile) == EOF;
            fclose(pFile);
        } else {
            char buffer[BUFFER_SIZE];
            errno_t errorNumber = errno;
            strerror_s(buffer, BUFFER_SIZE, errorNumber);
            PrintLog(buffer);

            if (errorNumber == 13) {
                stat = NFS3ERR_ACCES;
            } else {
                stat = NFS3ERR_IO;
            }
        }
    }

    file_attributes.attributes_follow = GetFileAttributesForNFS(path, &file_attributes.attributes);

    Write(&stat);
    Write(&file_attributes);

    if (stat == NFS3_OK) {
        Write(&count);
        Write(&eof);
        Write(&data);
    }

    return stat;
}
Ejemplo n.º 28
0
void Extension::AppendReceivedBinaryToFile(int Position, int Size, char * Filename)
{
    if (Position < 0)
        CreateError("Cannot append received binary; Position less than 0.");
    else if (Size <= 0)
        CreateError("Cannot append received binary; Size equal or less than 0.");
    else if (!Filename || Filename[0] == '\0')
        CreateError("Cannot append received binary; filename is invalid.");
    else if (ThreadData.ReceivedMsg.Size - Size <= 0)
        CreateError("Cannot append received binary; Message is too small.");
    else
    {
        // Open while denying write of other programs
        FILE * File = _fsopen(Filename, "ab", SH_DENYWR);
        if (!File)
        {
            char errorval[20];
            SaveExtInfo &S = AddEvent(0);
            std::string Error = "Cannot append received binary to file, error ";
            if (_itoa_s(*_errno(), &errorval[0], 20, 10))
            {
                Error += " with opening the file, and with converting error number.";
            }
            else
            {
                Error += "number [";
                Error += &errorval[0];
                Error += "] occured with opening the file.";
            }
            Error += "\r\nThe message has not been modified.";
            S.Error.Text = _strdup(Error.c_str());
            return;
        }
        long l;
        if ((l = fwrite(ThreadData.ReceivedMsg.Content + Position, 1, Size, File)) != Size)
        {
            char sizeastext[20];
            SaveExtInfo &S = AddEvent(0);
            std::string Error = "Couldn't append the received binary to file, ";
            if (_itoa_s(errno, &sizeastext[0], 20, 10))
            {
                Error += " and error copying size.";
            }
            else
            {
                Error += &sizeastext[0];
                Error += " bytes managed to be append.";
            }
            S.Error.Text = _strdup(Error.c_str());
        }
        fclose(File);
    }
}
Ejemplo n.º 29
0
bool FileStream::Open(const char* szFileName, const char* szMode, bool sharedHandle)
{
	// must not already have a handle open
	ASSERT(fs_pfh == nullptr);

#if WINDOWS
	// open file on Windows
	FILE* pfh = nullptr;
#ifndef SCRATCH_NO_UTF8
	size_t sizeFileName = strlen(szFileName) + 1;
	wchar_t* wszFileName = (wchar_t*)malloc(sizeof(wchar_t) * sizeFileName);
	mbstowcs(wszFileName, szFileName, sizeFileName);

	size_t sizeMode = strlen(szMode) + 1;
	wchar_t* wszMode = (wchar_t*)malloc(sizeof(wchar_t) * sizeMode);
	mbstowcs(wszMode, szMode, sizeMode);
#endif
	if (sharedHandle) {
#ifdef SCRATCH_NO_UTF8
		pfh = _fsopen(szFileName, szMode, _SH_DENYWR);
#else
		pfh = _wfsopen(wszFileName, wszMode, _SH_DENYWR);
#endif
	} else {
#ifdef SCRATCH_NO_UTF8
		fopen_s(&pfh, szFileName, szMode);
#else
		_wfopen_s(&pfh, wszFileName, wszMode);
#endif
	}
#ifndef SCRATCH_NO_UTF8
	free(wszFileName);
	free(wszMode);
#endif

#else
	// open file on linux
	FILE* pfh = fopen(szFileName, szMode);
#endif

	// it might not exist
	if (pfh == nullptr) {
		return false;
	}

	// remember info
	fs_strFileName = szFileName;
	fs_pfh = pfh;

	// success
	return true;
}
Ejemplo n.º 30
0
void dosyala(char *dosya_adi, char *alan)
{
	FILE *fp;

	if ((fp = _fsopen(dosya_adi, "rb+", SH_DENYNO)) == NULL) {
		msj_kutu(NULL, "Disk kay�t hatas�", HATA);
		exit(1);
	}

	fseek(fp, 0, SEEK_END);
	fwrite(alan, 1, 4920, fp);
	fclose(fp);
}