コード例 #1
1
void AllocRegistry::dump(const char *path) {
#ifdef WIN32
	FILE* f= _wfopen(utf8_decode(path).c_str(), L"wt");
#else
	FILE *f= fopen(path, "wt");
#endif
	int leakCount=0;
	size_t leakBytes=0;

	time_t debugTime = time(NULL);
    struct tm *loctime = localtime (&debugTime);
    char szBuf2[100]="";
    strftime(szBuf2,100,"%Y-%m-%d %H:%M:%S",loctime);

	fprintf(f, "Memory leak dump at: %s\n\n",szBuf2);

	for(int i=0; i<maxAllocs; ++i){
		AllocInfo &info = allocs[i];
		if(info.freetouse == false && info.inuse == true) {

			if(info.line > 0) {
				leakBytes += info.bytes;

				//allocs[i].stack = AllocInfo::getStackTrace();
				fprintf(f, "Leak #%d.\tfile: %s, line: %d, ptr [%p], bytes: " MG_SIZE_T_SPECIFIER ", array: %d, inuse: %d\n%s\n", ++leakCount, info.file, info.line, info.ptr, info.bytes, info.array,info.inuse,info.stack.c_str());
			}
		}
	}

	fprintf(f, "\nTotal leaks: %d, " MG_SIZE_T_SPECIFIER " bytes\n", leakCount, leakBytes);
	fprintf(f, "Total allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", allocCount, allocBytes);
	fprintf(f, "Not monitored allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", nonMonitoredCount, nonMonitoredBytes);

	fclose(f);

	printf("Memory leak dump summary at: %s\n",szBuf2);
	printf("Total leaks: %d, " MG_SIZE_T_SPECIFIER " bytes\n", leakCount, leakBytes);
	printf("Total allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", allocCount, allocBytes);
	printf("Not monitored allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", nonMonitoredCount, nonMonitoredBytes);
}
コード例 #2
0
ファイル: SaveLoadData.cpp プロジェクト: Andrew90/thick
void LoadData::Do(HWND h)
{
	OpenData o(h);
	if(o())
	{
		FILE *f = _wfopen(o.sFile, L"rb");
		close_file c_f(f);
		if(NULL != f)
		{
			HeadStoredData head;
			if(1 == fread(&head, sizeof(head), 1, f))
			{
				primaryData.countZones = head.countZones;
				fread(primaryData.realOffsetTime, sizeof(primaryData.realOffsetTime), 1, f);
				int count = fread(primaryData.indexOffsetZone, sizeof(primaryData.indexOffsetZone), 1, f);
				primaryData.frameStartTime = head.frameStartTime;
				char buf[1024 * 16];
				int k = 0;
				for(;;)
				{
					int count = fread(buf, 1, sizeof(buf), f);
					if(0 == count) break;
					{
						for(int i = 0; i < count; ++i)
						{
							primaryData.buffer[k++] = buf[i];
						}
					}
				}
				primaryData.SetCurrentOffset(k);
				if(k)
				{					
					Recalculation::Do(NULL);
					return;
				}
			}
		}
		MessageBox(0, L"‘айл не загружен", L"ќшибка !!!", MB_ICONERROR);
	}	
}
コード例 #3
0
//----------------------------------------------------------------------------//
void DefaultResourceProvider::loadRawDataContainer(const String& filename,
                                                   RawDataContainer& output,
                                                   const String& resourceGroup)
{
    if (filename.empty())
        CEGUI_THROW(InvalidRequestException("DefaultResourceProvider::load: "
            "Filename supplied for data loading must be valid"));

    const String final_filename(getFinalFilename(filename, resourceGroup));

#if defined(__WIN32__) || defined(_WIN32)
    FILE* file = _wfopen(Utf8ToUtf16(final_filename.c_str()).c_str(), L"rb");
#else
    FILE* file = fopen(final_filename.c_str(), "rb");
#endif

    if (file == 0)
        CEGUI_THROW(InvalidRequestException("DefaultResourceProvider::load: " +
            final_filename + " does not exist"));

    fseek(file, 0, SEEK_END);
    const long size = ftell(file);
    fseek(file, 0, SEEK_SET);

    unsigned char* const buffer = new unsigned char[size];

    const size_t size_read = fread(buffer, sizeof(char), size, file);
    fclose(file);

    if (size_read != size)
    {
        delete[] buffer;
        CEGUI_THROW(GenericException(
            "DefaultResourceProvider::loadRawDataContainer: "
            "A problem occurred while reading file: " + final_filename));
    }

    output.setData(buffer);
    output.setSize(size);
}
コード例 #4
0
/**
 * Common initialization function for RpFile's constructors.
 * Filename must be set in m_filename.
 */
void RpFile::init(void)
{
	const mode_str_t *mode_str = mode_to_str(m_mode);
	if (!mode_str) {
		m_lastError = EINVAL;
		return;
	}

	// TODO: On Windows, prepend "\\\\?\\" for super-long filenames?

#if defined(_WIN32)
	// Windows: Use RP2W_s() to convert the filename to wchar_t.

	// If this is an absolute path, make sure it starts with
	// "\\?\" in order to support filenames longer than MAX_PATH.
	wstring filenameW;
	if (m_filename.size() > 3 &&
	    isascii(m_filename[0]) && isalpha(m_filename[0]) &&
	    m_filename[1] == ':' && m_filename[2] == '\\')
	{
		// Absolute path. Prepend "\\?\" to the path.
		filenameW = L"\\\\?\\";
		filenameW += RP2W_s(m_filename);
	} else {
		// Not an absolute path, or "\\?\" is already
		// prepended. Use it as-is.
		filenameW = RP2W_s(m_filename);
	}

	m_file.reset(_wfopen(filenameW.c_str(), mode_str), myFile_deleter());
#else /* !_WIN32 */
	// Linux: Use UTF-8 filenames directly.
	m_file.reset(fopen(m_filename.c_str(), mode_str), myFile_deleter());
#endif /* _WIN32 */

	if (!m_file) {
		// An error occurred while opening the file.
		m_lastError = errno;
	}
}
コード例 #5
0
ファイル: LoginMng.cpp プロジェクト: takke/MZ3
/**
 * ファイルからログイン情報を出力
 */
void Login::Write()
{
	// 実行ファイルのパスからデータファイル名を作成
	CString fileName = theApp.GetAppDirPath() + _T("\\user.dat");

	// ----------------------------------------
	// エンコード処理
	// ----------------------------------------
	FILE* fp = _wfopen(fileName, _T("wb"));
	if (fp == NULL) {
		return;
	}

	// mixi
	WriteItem( fp, GetMixiEmail() );
	WriteItem( fp, GetMixiPassword() );
	CString dummyId;
	WriteItem( fp, dummyId );

	// Twitter
	WriteItem( fp, GetTwitterId() );
	WriteItem( fp, GetTwitterPassword() );

	// Wassr
	WriteItem( fp, GetWassrId() );
	WriteItem( fp, GetWassrPassword() );

	// gooホーム
	WriteItem( fp, GetGooId() );
	WriteItem( fp, GetGoohomeQuoteMailAddress() );

	//--- 以上の9項目は旧バージョンとの互換用データ。
	//--- v1.0.0 以降は下記の汎用データ構造を正する。

	// その他の汎用ID
	CString serializedId = SerializeId();
	WriteItem( fp, serializedId, true );

	fclose(fp);
}
コード例 #6
0
ファイル: File.cpp プロジェクト: HaxeFoundation/hxcpp
/**
	file_contents : f:string -> string
	<doc>Read the content of the file [f] and return it.</doc>
**/
static value file_contents( value name ) {
	buffer s=0;
	int len;
	int p;
	val_check(name,string);
	fio f(val_filename(name));
	#ifdef NEKO_WINDOWS
	const wchar_t *fname = val_wstring(name);
	gc_enter_blocking();
	f.io = _wfopen(fname,L"rb");
	#else
	const char *fname = val_string(name);
	gc_enter_blocking();
	f.io = fopen(fname,"rb");
	#endif
	if( f.io == NULL )
		file_error("file_contents",&f);
	fseek(f.io,0,SEEK_END);
	len = ftell(f.io);
	fseek(f.io,0,SEEK_SET);
	gc_exit_blocking();
	s = alloc_buffer_len(len);
	p = 0;
	gc_enter_blocking();
	while( len > 0 ) {
		int d;
		POSIX_LABEL(file_contents);
		d = (int)fread((char*)buffer_data(s)+p,1,len,f.io);
		if( d <= 0 ) {
			HANDLE_FINTR(f.io,file_contents);
			fclose(f.io);
			file_error("file_contents",&f);
		}
		p += d;
		len -= d;
	}	
	fclose(f.io);
	gc_exit_blocking();
	return buffer_val(s);
}
コード例 #7
0
FileIO::Pointer FileIO::Open(
        boost::filesystem::path path,
        const std::string& open_mode,
        std::error_code * error
    )
{
    if (error)
        error->clear();

#if _WIN32
    std::wstring wide_open_mode = bytes_to_wide(open_mode);
    FILE* file_handle = _wfopen(
            path.wstring().c_str(),
            wide_open_mode.c_str()
        );
#else
    FILE* file_handle = fopen(
        path.string().c_str(),
        open_mode.c_str());
#endif

    if (file_handle != nullptr)
    {
        boost::system::error_code bec;
        uint64_t size_hint = boost::filesystem::file_size(path, bec);
        if (bec || size_hint == 0)
            size_hint = skDefaultBlockSize;

        return FileIO::Pointer(new FileIO(
                file_handle,
                size_hint
        ));
    }
    else
    {
        if ( error != nullptr )
            *error = std::error_code(errno, std::system_category());
        return FileIO::Pointer();
    }
}
コード例 #8
0
ファイル: deck_manager.cpp プロジェクト: Bruke/Dev_ygopro
bool DeckManager::LoadDeck(const wchar_t* file) {
	int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
	wchar_t deck[64];
	myswprintf(deck, L"./deck/%ls.ydk", file);
	int cardlist[128];
	bool is_side = false;
#ifdef WIN32
	FILE* fp = _wfopen(deck, L"r");
#else
	char deckfn[256];
	BufferIO::EncodeUTF8(deck, deckfn);
	FILE* fp = fopen(deckfn, "r");
#endif
	if(!fp)
		return false;
	char linebuf[256];
	fseek(fp, 0, SEEK_END);
	int fsize = ftell(fp);
	fseek(fp, 0, SEEK_SET);
	fgets(linebuf, 256, fp);
	while(ftell(fp) < fsize && ct < 128) {
		fgets(linebuf, 256, fp);
		if(linebuf[0] == '!') {
			is_side = true;
			continue;
		}
		if(linebuf[0] < '0' || linebuf[0] > '9')
			continue;
		sp = 0;
		while(linebuf[sp] >= '0' && linebuf[sp] <= '9') sp++;
		linebuf[sp] = 0;
		code = atoi(linebuf);
		cardlist[ct++] = code;
		if(is_side) sidec++;
		else mainc++;
	}
	fclose(fp);
	LoadDeck(current_deck, cardlist, mainc, sidec);
	return true;
}
コード例 #9
0
bool readFile(const char* path, char **message, size_t *len, bool binary)
{
    bool ret = false;
    FILE *f;
    size_t msglen=0;
    char *msg=0;

    // Convert to wide-char to be compatible with international chars.
    // If using char and UTF-8, fopen() is not working correctly and
    // will fail with special chars. (with UTF-8... why?)
    // So we use _wfopen() and a wide-char path.
    const WCHAR* mode = binary ? TEXT("rb") : TEXT("r");
    WCHAR* wpath = toWideChar(path);

    f = _wfopen(wpath, mode);
    if ( !f ) {
        goto finally;
    }
    msglen = fgetsize(f);
    msg = new char[msglen+1];

    *len=fread(msg, sizeof(char), msglen, f);
    if(ferror(f)) {
        delete [] msg;
        goto finally;
    }
    fclose(f);

    // Terminate the read msg
    msg[*len] = 0;

    // Set return parameters
    *message= msg ;
    //*len=msglen;
    ret = true;

finally:
    delete [] wpath;
    return ret;
}
コード例 #10
0
ファイル: gstdio.c プロジェクト: endlessm/glib
/**
 * g_fopen:
 * @filename: (type filename): a pathname in the GLib file name encoding
 *     (UTF-8 on Windows)
 * @mode: a string describing the mode in which the file should be opened
 *
 * A wrapper for the stdio fopen() function. The fopen() function
 * opens a file and associates a new stream with it.
 * 
 * Because file descriptors are specific to the C library on Windows,
 * and a file descriptor is part of the FILE struct, the FILE* returned
 * by this function makes sense only to functions in the same C library.
 * Thus if the GLib-using code uses a different C library than GLib does,
 * the FILE* returned by this function cannot be passed to C library
 * functions like fprintf() or fread().
 *
 * See your C library manual for more details about fopen().
 *
 * Returns: A FILE* if the file was successfully opened, or %NULL if
 *     an error occurred
 * 
 * Since: 2.6
 */
FILE *
g_fopen (const gchar *filename,
	 const gchar *mode)
{
#ifdef G_OS_WIN32
  wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
  wchar_t *wmode;
  gchar   *mode2;
  FILE *retval;
  int save_errno;

  if (wfilename == NULL)
    {
      errno = EINVAL;
      return NULL;
    }

  mode2 = _g_win32_get_mode_alias (mode);
  wmode = g_utf8_to_utf16 (mode2, -1, NULL, NULL, NULL);
  g_free (mode2);

  if (wmode == NULL)
    {
      g_free (wfilename);
      errno = EINVAL;
      return NULL;
    }

  retval = _wfopen (wfilename, wmode);
  save_errno = errno;

  g_free (wfilename);
  g_free (wmode);

  errno = save_errno;
  return retval;
#else
  return fopen (filename, mode);
#endif
}
コード例 #11
0
static FILE* blargg_fopen( const char path [], const char mode [] )
{
	FILE* file = NULL;
	wchar_t* wmode = NULL;
	wchar_t* wpath = NULL;
	
	wpath = blargg_to_wide( path );
	if ( wpath )
	{
		wmode = blargg_to_wide( mode );
		if ( wmode )
			file = _wfopen( wpath, wmode );
	}
	
	// Save and restore errno in case free() clears it
	int saved_errno = errno;
	free( wmode );
	free( wpath );
	errno = saved_errno;
	
	return file;
}
コード例 #12
0
ファイル: main.cpp プロジェクト: SeanLiangYoung/nocnnic
int firefoxVersionIncorrect(const TCHAR* profilePath)
{
  TCHAR path[1024];
  char line[256];
  char ver[5];
  wcscpy(path, profilePath);
  wcscat(path, L"\\compatibility.ini");
  FILE* pini = _wfopen(path, L"r");
  while (fgets(line, 256, pini)!=NULL)
    {
      if (strstr(line, "LastVersion=")==line)
        {
          strncpy(ver, line+12, 4);
          ver[4]='\0';
          break;
        }
    }
  fclose(pini);
  if (strcmp(ver, "3.6_")!=0)
    return 1;
  return 0;
}
コード例 #13
0
FILE *os_wfopen(const wchar_t *path, const char *mode)
{
	FILE *file = NULL;

	if (path) {
#ifdef _MSC_VER
		wchar_t *wcs_mode;

		os_utf8_to_wcs_ptr(mode, 0, &wcs_mode);
		file = _wfopen(path, wcs_mode);
		bfree(wcs_mode);
#else
		char *mbs_path;

		os_wcs_to_utf8_ptr(path, 0, &mbs_path);
		file = fopen(mbs_path, mode);
		bfree(mbs_path);
#endif
	}

	return file;
}
コード例 #14
0
ファイル: file_posix.c プロジェクト: pingflood/libbluray
static BD_FILE_H *file_open_linux(const char* filename, const char *mode)
{
    FILE *fp = NULL;
    BD_FILE_H *file = malloc(sizeof(BD_FILE_H));

    BD_DEBUG(DBG_FILE, "Opening LINUX file %s... (%p)\n", filename, (void*)file);
    file->close = file_close_linux;
    file->seek = file_seek_linux;
    file->read = file_read_linux;
    file->write = file_write_linux;
    file->tell = file_tell_linux;
    file->eof = file_eof_linux;

#ifdef WIN32
    wchar_t wfilename[MAX_PATH], wmode[8];
    if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, wfilename, MAX_PATH) &&
        MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, wmode, 8) &&
        (fp = _wfopen(wfilename, wmode))) {
#else
    if ((fp = fopen(filename, mode))) {
#endif
        file->internal = fp;

        return file;
    }

    BD_DEBUG(DBG_FILE, "Error opening file! (%p)\n", (void*)file);

    X_FREE(file);

    return NULL;
}

BD_FILE_H* (*file_open)(const char* filename, const char *mode) = file_open_linux;

BD_FILE_OPEN file_open_default(void)
{
    return file_open_linux;
}
コード例 #15
0
ファイル: core.hpp プロジェクト: vgmtool/vgmtool
bool string::readfile(const string &filename) {
    assign("");

#if !defined(_WIN32)
    FILE *fp = fopen(filename, "rb");
#else
    FILE *fp = _wfopen(utf16_t(filename), L"rb");
#endif
    if(!fp) return false;

    fseek(fp, 0, SEEK_END);
    unsigned size = ftell(fp);
    rewind(fp);
    char *fdata = new char[size + 1];
    unsigned unused = fread(fdata, 1, size, fp);
    fclose(fp);
    fdata[size] = 0;
    assign(fdata);
    delete[] fdata;

    return true;
}
コード例 #16
0
ファイル: util.c プロジェクト: juntalis/cygwin-virtualenv
/** Allocate a buffer for the contents of a file and read the file into it. */
static inline byte* file_to_buffer(wchar_t* sPath, size_t* size)
{
	FILE* fp;
	byte* buffer = NULL;
	fp = _wfopen((const wchar_t*)sPath, L"rb");
	if (fp == NULL) {
		fatal(1, L"Could not read file: %s", sPath);
	}
	
	*size = get_file_length(fp);
	if(*size == -1) {
		fatal(1, L"Could not get size of file: %s", sPath);
	}
	
	if(!(buffer = (byte*)xalloc(*size, 1))) {
		fatal(1, L"Could not allocate %d bytes of memory for the contents of file: %s", *size, sPath);
	}
	ZeroMemory(buffer, *size);
	fread(buffer, 1, *size, fp);
	fclose(fp);
	return buffer;
}
コード例 #17
0
ファイル: simple_api.cpp プロジェクト: kevinw/hlsl2glslfork
static bool ReadStringFromFile (const char* pathName, std::string& output)
{
#	ifdef _MSC_VER
	wchar_t widePath[MAX_PATH];
	int res = ::MultiByteToWideChar (CP_UTF8, 0, pathName, -1, widePath, MAX_PATH);
	if (res == 0)
		widePath[0] = 0;
	FILE* file = _wfopen(widePath, L"rb");
#	else // ifdef _MSC_VER
	FILE* file = fopen(pathName, "rb");
#	endif // !ifdef _MSC_VER

	if (file == NULL)
		return false;
	
	fseek(file, 0, SEEK_END);
	long length = ftell(file);
	fseek(file, 0, SEEK_SET);
	if (length < 0)
	{
		fclose( file );
		return false;
	}
	
	output.resize(length);
	size_t readLength = fread(&*output.begin(), 1, length, file);
	
	fclose(file);
	
	if (readLength != length)
	{
		output.clear();
		return false;
	}

	replace_string(output, "\r\n", "\n", 0);
	
	return true;
}
コード例 #18
0
FILE*
_Py_fopen(PyObject *path, const char *mode)
{
#ifdef MS_WINDOWS
    wchar_t wmode[10];
    int usize;

    usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode));
    if (usize == 0)
        return NULL;

    return _wfopen(PyUnicode_AS_UNICODE(path), wmode);
#else
    FILE *f;
    PyObject *bytes = PyUnicode_EncodeFSDefault(path);
    if (bytes == NULL)
        return NULL;
    f = fopen(PyBytes_AS_STRING(bytes), mode);
    Py_DECREF(bytes);
    return f;
#endif
}
コード例 #19
0
ファイル: fileutils.c プロジェクト: CIBC-Internal/python
/* Open a file. Call _wfopen() on Windows, or encode the path to the filesystem
   encoding and call fopen() otherwise. The file descriptor is created
   non-inheritable.

   Return the new file object on success, or NULL if the file cannot be open or
   (if PyErr_Occurred()) on unicode error. */
FILE*
_Py_fopen_obj(PyObject *path, const char *mode)
{
    FILE *f;
#ifdef MS_WINDOWS
    wchar_t *wpath;
    wchar_t wmode[10];
    int usize;

    if (!PyUnicode_Check(path)) {
        PyErr_Format(PyExc_TypeError,
                     "str file path expected under Windows, got %R",
                     Py_TYPE(path));
        return NULL;
    }
    wpath = PyUnicode_AsUnicode(path);
    if (wpath == NULL)
        return NULL;

    usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode));
    if (usize == 0)
        return NULL;

    f = _wfopen(wpath, wmode);
#else
    PyObject *bytes;
    if (!PyUnicode_FSConverter(path, &bytes))
        return NULL;
    f = fopen(PyBytes_AS_STRING(bytes), mode);
    Py_DECREF(bytes);
#endif
    if (f == NULL)
        return NULL;
    if (make_non_inheritable(fileno(f)) < 0) {
        fclose(f);
        return NULL;
    }
    return f;
}
コード例 #20
0
bool StrangeNNGene::loadFromFile( std::wstring const& filename )
{
    // =@!540!~!258!-123!~@!240!~!~!~!566=@!540!~@!~!566@!-800!12=@!540!12!~@!-800!~!566
    FILE* pFile = _wfopen( filename.c_str(), L"rb" );
    if ( NULL == pFile )
    {
        return false;
    }

    // Validate that this is indeed a StrangeWorld 4 gene file.
    char header[] = GENEFILE_HEADER;
    // Read the header
    fread( (void*)header, strlen(header), sizeof(char), pFile );
    if ( strcmp( header, GENEFILE_HEADER ) != 0 )
    {
        fclose( pFile );
        return false;
    }

    const int BUFFER_SIZE = 80;
    char buff[BUFFER_SIZE];

    // Read all bytes in the file.
    std::string geneStr;
    size_t bytesRead = fread( (void*)buff, 1, BUFFER_SIZE, pFile );
    while ( bytesRead > 0 )
    {
        geneStr.append( buff, bytesRead );
        bytesRead = fread( (void*)buff, 1, BUFFER_SIZE, pFile );
    }
    fclose( pFile );

    if ( ! createGeneData( geneStr ) )
    {
        data_.clear();
        return false;
    }
    return true;
}
コード例 #21
0
bool StrangeNNGene::saveGene( std::wstring const& filename )
{
    FILE* pFile = _wfopen( filename.c_str(), L"wb" );
    if ( NULL == pFile )
        return false;

    // Write the file header
    fwrite( GENEFILE_HEADER, 1, strlen( GENEFILE_HEADER ), pFile );

    // Write the generation count
    {
        char buff[80];
        itoa( geneGeneration_, buff, 10 );
        fwrite( buff, 1, strlen( buff ), pFile );
    }

    // For every layer
    GeneData::iterator neuronIt = data_.begin();
    for ( ; neuronIt != data_.end(); ++neuronIt )
    {
        fwrite( GENEFILE_TOKEN_NEURON, 1, 1, pFile );
        // For every dendrite
        Neuron::iterator dendriteIt = neuronIt->begin();
        for ( ; dendriteIt != neuronIt->end(); ++dendriteIt )
        {
            fwrite( GENEFILE_TOKEN_DENDRITE, 1, 1, pFile );
            char buff[80];
            itoa( dendriteIt->first, buff, 10 );
            fwrite( buff, 1, strlen( buff ), pFile );
            fwrite( GENEFILE_TOKEN_COMMA, 1, 1, pFile );
            itoa( dendriteIt->second, buff, 10 );
            fwrite( buff, 1, strlen( buff ), pFile );
        }
    }

    fclose( pFile );
    return true;
}
コード例 #22
0
ファイル: gstdio.c プロジェクト: north0808/haina
//scott wince port
int
g_open (const gchar *filename,
	int          flags,
	int          mode)
{

	  wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
      int retval;
	FILE *fp ;
	  wchar_t  modstr[12];
      
      if (wfilename == NULL)
	{
	  return -1;
	}

      
	  if( flags & O_CREAT  || flags & O_RDWR){
		  wcscat(modstr,L"w");
	  }
	  if( flags & O_RDONLY ){
		  wcscat(modstr,L"r");
	  }
	  if( flags & O_APPEND ){
		  wcscat(modstr,L"a");
	  }
	  if( flags & O_BINARY){
		  wcscat(modstr,L"b");

	  }
	  fp =_wfopen (wfilename, modstr);
	  if( !fp )
		  return -1;
	  retval =  _fileno( fp );
      g_free (wfilename);
      return retval;
   
}
コード例 #23
0
ファイル: DigiDocLib.c プロジェクト: Krabi/idkaart_public
//--------------------------------------------------
// Checks if this file exists
// szFileName - file name
// returns 1 if exists
// AA 2004/05/20 debuggeri all viga, kui null pikkus
//--------------------------------------------------
EXP_OPTION int checkFileExists(const char* szFileName)
{
    FILE* hFile = 0;
    int exists = 0;
#ifdef WIN32
    int i = 0, err = ERR_OK;
    wchar_t *convFileName = 0;
#endif
    if(szFileName && strlen(szFileName) > 0) {
#ifdef WIN32
        err = utf82unicode((const char*)szFileName, (char**)&convFileName, &i);
        if((hFile = _wfopen(convFileName, L"r")) != NULL) {
#else
        if((hFile = fopen(szFileName, "r")) != NULL) {
#endif
            exists = 1;
            fclose(hFile);
        }
    }
#ifdef WIN32
    if(convFileName) free(convFileName);
#endif
    return exists;
}


//================< certficate info functions> =================================

//--------------------------------------------------
// Returns the user signatures certificate data
// pSignInfo - signature object
// returns cert data. This is actually X509*. Obsolete function
//--------------------------------------------------
EXP_OPTION X509* getSignCertData(const SignatureInfo* pSignInfo)
{
    RETURN_OBJ_IF_NULL(pSignInfo, 0);
    return ddocSigInfo_GetSignersCert(pSignInfo);
}
コード例 #24
0
ファイル: os_file.c プロジェクト: gorinje/Access
GF_EXPORT
FILE *gf_temp_file_new()
{
	FILE *res=NULL;
#if defined(_WIN32_WCE)
	TCHAR pPath[MAX_PATH+1];
	TCHAR pTemp[MAX_PATH+1];
	if (!GetTempPath(MAX_PATH, pPath)) {
		pPath[0] = '.';
		pPath[1] = '.';
	}
	if (GetTempFileName(pPath, TEXT("git"), 0, pTemp))
		res = _wfopen(pTemp, TEXT("w+b"));
#elif defined(WIN32)
	char tmp[MAX_PATH];
	res = tmpfile();
	if (!res) {
		GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("[Win32] system failure for tmpfile(): 0x%08x\n", GetLastError()));

		/*tmpfile() may fail under vista ...*/
		if (GetEnvironmentVariable("TEMP",tmp,MAX_PATH)) {
			char tmp2[MAX_PATH], *t_file;
			gf_rand_init(GF_FALSE);
			sprintf(tmp2, "gpac_%08x_", gf_rand());
			t_file = tempnam(tmp, tmp2);
			res = gf_fopen(t_file, "w+b");
			free(t_file);
		}
	}
#else
	res = tmpfile();
#endif

	if (res) {
		gpac_file_handles++;
	}
	return res;
}
コード例 #25
0
ファイル: main.cpp プロジェクト: bugoodby/rmchar
//--------------------------------------------------------------
// main
//--------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
	OPTION opt = {0};
	int retval = 0;
	FILE *console = stderr;
	FILE *infp = stdin;
	FILE *outfp = stdout;

	setlocale(LC_CTYPE, "japanese");

	/* parse */
	if ( !parse_cmdline(argc, argv, opt) ) {
		goto EXIT;
	}

	if ( opt.num > 0 ) {
		/* open file */
		infp = _wfopen(*opt.argv, L"r");
		if ( !infp ) {
			fwprintf(console, L"[ERROR] cannot open %s.\n", *opt.argv);
			GET_ERROR_VAL(retval);
			goto EXIT;
		}
	}

	retval = rmchar(infp, outfp, opt);
	if ( retval < 0 ) {
		fwprintf(console, L"[ERROR] fail in main routine.\n");
	}

EXIT:
	/* close file */
	if ( infp && infp != stdin ) {
		fclose(infp);
	}

	return retval;
}
コード例 #26
0
ファイル: CWriteFile.cpp プロジェクト: 344717871/STK_android
//! opens the file
void CWriteFile::openFile(bool append)
{
	if (Filename.size() == 0)
	{
		File = 0;
		return;
	}

#if defined(_IRR_WCHAR_FILESYSTEM)
	File = _wfopen(Filename.c_str(), append ? L"ab" : L"wb");
#else
	File = fopen(Filename.c_str(), append ? "ab" : "wb");
#endif

	if (File)
	{
		// get FileSize

		fseek(File, 0, SEEK_END);
		FileSize = ftell(File);
		fseek(File, 0, SEEK_SET);
	}
}
コード例 #27
0
ファイル: CReadFile.cpp プロジェクト: Badcreature/sagcg
//! opens the file
void CReadFile::openFile()
{
	if (Filename.size() == 0) // bugfix posted by rt
	{
		File = 0;
		return;
	}

#if defined ( _IRR_WCHAR_FILESYSTEM )
	File = _wfopen(Filename.c_str(), L"rb");
#else
	File = fopen(Filename.c_str(), "rb");
#endif

	if (File)
	{
		// get FileSize

		fseek(File, 0, SEEK_END);
		FileSize = getPos();
		fseek(File, 0, SEEK_SET);
	}
}
コード例 #28
0
ファイル: pexport.cpp プロジェクト: useada/polyml
// Import a file in the portable format and return a pointer to the root object.
PolyObject *ImportPortable(const TCHAR *fileName)
{
    PImport pImport;
#if (defined(_WIN32) && defined(UNICODE))
    pImport.f = _wfopen(fileName, L"r");
    if (pImport.f == 0)
    {
        fprintf(stderr, "Unable to open file: %S\n", fileName);
        return 0;
    }
#else
    pImport.f = fopen(fileName, "r");
    if (pImport.f == 0)
    {
        fprintf(stderr, "Unable to open file: %s\n", fileName);
        return 0;
    }
#endif
    if (pImport.DoImport())
        return pImport.Root();
    else
        return 0;
}
コード例 #29
0
//---------------------------------------------------------------------------
bool __fastcall DumpResourceToFile(const UnicodeString ResName,
  const UnicodeString FileName)
{
  void * Content;
  unsigned long Size;
  bool Result = GetResource(ResName, Content, Size);

  if (Result)
  {
    FILE * f = _wfopen(FileName.c_str(), L"wb");
    if (!f)
    {
      throw Exception(FORMAT(L"Cannot create file %s", (FileName)));
    }
    if (fwrite(Content, 1, Size, f) != Size)
    {
      throw Exception(FORMAT(L"Cannot write to file %s", (FileName)));
    }
    fclose(f);
  }

  return Result;
}
コード例 #30
0
bool StdFileManager::GetFileBuffer(const str_type::string &fileName, FileBuffer &out)
{
	#if _MSC_VER >= 1500
		FILE *f = 0;
		_wfopen_s(&f, fileName.c_str(), GS_L("rb"));
	#else
		FILE *f = _wfopen(fileName.c_str(), GS_L("rb"));
	#endif

	if (!f)
	{
		return false;
	}
	
	fseek(f, 0, SEEK_END);
	const std::size_t len = ftell(f);
	fseek(f, 0, SEEK_SET);

	out = FileBuffer(new _FileBuffer<unsigned char>(len));
	fread(out->GetAddress(), len, 1, f);
	fclose(f);
	return true;
}