File.cpp (pymol-v1.8.6.0.tar.bz2) | : | File.cpp (pymol-v2.1.0.tar.bz2) | ||
---|---|---|---|---|
/* | /* | |||
* Copyright (c) Schrodinger, LLC. | * Copyright (c) Schrodinger, LLC. | |||
* | * | |||
* Basic file IO. | * Basic file IO. | |||
*/ | */ | |||
#ifdef _WIN32 | ||||
#include <vector> | ||||
#include <Windows.h> | ||||
#endif | ||||
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include "File.h" | #include "File.h" | |||
#include "MemoryDebug.h" | #include "MemoryDebug.h" | |||
/* | /* | |||
* Get the size from the current file pointer to the end of the file | * Get the size from the current file pointer to the end of the file | |||
*/ | */ | |||
static long fgetsize(FILE *fp) { | static long fgetsize(FILE *fp) { | |||
skipping to change at line 47 | skipping to change at line 52 | |||
return NULL; | return NULL; | |||
} | } | |||
if (size) | if (size) | |||
*size = filesize; | *size = filesize; | |||
contents[filesize] = '\0'; | contents[filesize] = '\0'; | |||
return contents; | return contents; | |||
} | } | |||
#ifdef _WIN32 | ||||
FILE * pymol_fopen(const char * filename, const char * mode) { | ||||
FILE *fp = fopen(filename, mode); | ||||
if (!fp) { | ||||
size_t len_filename = strlen(filename); | ||||
std::vector<wchar_t> wfilename(len_filename + 1); | ||||
std::vector<wchar_t> wmode(mode, mode + strlen(mode) + 1); | ||||
if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, | ||||
filename, len_filename, wfilename.data(), wfilename.size())) | ||||
return NULL; | ||||
fp = _wfopen(wfilename.data(), wmode.data()); | ||||
} | ||||
return fp; | ||||
} | ||||
#endif | ||||
/* | /* | |||
* Allocate memory and read the entire file for the given filename. | * Allocate memory and read the entire file for the given filename. | |||
* The file size is stored into the size pointer if not NULL. | * The file size is stored into the size pointer if not NULL. | |||
*/ | */ | |||
char * FileGetContents(const char *filename, long *size) { | char * FileGetContents(const char *filename, long *size) { | |||
char *contents; | char *contents; | |||
FILE *fp = fopen(filename, "rb"); | FILE *fp = pymol_fopen(filename, "rb"); | |||
if (!fp) | if (!fp) | |||
return NULL; | return NULL; | |||
contents = fgetcontents(fp, size); | contents = fgetcontents(fp, size); | |||
fclose(fp); | fclose(fp); | |||
return contents; | return contents; | |||
} | } | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 26 lines changed or added |