mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 08:29:32 -05:00
Added function "ops_open" to openpgpsdk to open files with utf8 characters on Windows.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5934 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7339af3a21
commit
b85bccbbe6
@ -67,9 +67,10 @@ HEADERS += openpgpsdk/writer.h \
|
||||
openpgpsdk/accumulate.h \
|
||||
openpgpsdk/armour.h \
|
||||
openpgpsdk/parse_local.h \
|
||||
openpgpsdk/keyring_local.h
|
||||
openpgpsdk/keyring_local.h \
|
||||
util/opsdir.h \
|
||||
util/opsstring.h
|
||||
|
||||
|
||||
SOURCES += openpgpsdk/accumulate.c \
|
||||
openpgpsdk/compress.c \
|
||||
openpgpsdk/create.c \
|
||||
@ -106,4 +107,6 @@ SOURCES += openpgpsdk/accumulate.c \
|
||||
openpgpsdk/writer_fd.c \
|
||||
openpgpsdk/writer_memory.c \
|
||||
openpgpsdk/writer_skey_checksum.c \
|
||||
openpgpsdk/writer_stream_encrypt_se_ip.c
|
||||
openpgpsdk/writer_stream_encrypt_se_ip.c \
|
||||
util/opsdir.c \
|
||||
util/opsstring.c
|
||||
|
@ -40,6 +40,7 @@
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <util/opsdir.h>
|
||||
|
||||
#include <openpgpsdk/writer.h>
|
||||
#include <openpgpsdk/final.h>
|
||||
@ -1197,7 +1198,7 @@ ops_write_literal_data_from_file(const char *filename,
|
||||
ops_memory_t* mem=NULL;
|
||||
size_t len=0;
|
||||
|
||||
fd=open(filename,O_RDONLY | O_BINARY);
|
||||
fd=ops_open(filename,O_RDONLY | O_BINARY, 0);
|
||||
|
||||
if (fd < 0)
|
||||
return ops_false;
|
||||
@ -1251,7 +1252,7 @@ ops_memory_t* ops_write_mem_from_file(const char *filename, int* errnum)
|
||||
|
||||
*errnum=0;
|
||||
|
||||
fd=open(filename,O_RDONLY | O_BINARY);
|
||||
fd=ops_open(filename,O_RDONLY | O_BINARY, 0);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
@ -1305,7 +1306,7 @@ int ops_write_file_from_buf(const char *filename, const char* buf,
|
||||
|
||||
flags |= O_BINARY;
|
||||
|
||||
fd=open(filename,flags, 0600);
|
||||
fd=ops_open(filename,flags, 0600);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror(NULL);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <openpgpsdk/final.h>
|
||||
#include <util/opsdir.h>
|
||||
|
||||
/**
|
||||
\ingroup Core_MPI
|
||||
@ -180,9 +181,9 @@ ops_boolean_t ops_encrypt_file(const char* input_filename,
|
||||
|
||||
ops_create_info_t *cinfo;
|
||||
#ifdef WINDOWS_SYS
|
||||
fd_in=open(input_filename, O_RDONLY | O_BINARY);
|
||||
fd_in=ops_open(input_filename, O_RDONLY | O_BINARY);
|
||||
#else
|
||||
fd_in=open(input_filename, O_RDONLY );
|
||||
fd_in=ops_open(input_filename, O_RDONLY, 0);
|
||||
#endif
|
||||
if(fd_in < 0)
|
||||
{
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include <openpgpsdk/final.h>
|
||||
#include <util/opsdir.h>
|
||||
|
||||
/**
|
||||
\ingroup HighLevel_Keyring
|
||||
@ -738,7 +739,7 @@ ops_boolean_t ops_keyring_read_from_file(ops_keyring_t *keyring, const ops_boole
|
||||
// ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_RAW);
|
||||
ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED);
|
||||
|
||||
fd=open(filename,O_RDONLY | O_BINARY);
|
||||
fd=ops_open(filename,O_RDONLY | O_BINARY, 0);
|
||||
|
||||
if(fd < 0)
|
||||
{
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#include <openpgpsdk/readerwriter.h>
|
||||
#include <openpgpsdk/callback.h>
|
||||
#include <util/opsdir.h>
|
||||
|
||||
#include "parse_local.h"
|
||||
|
||||
@ -183,7 +184,7 @@ int ops_setup_file_write(ops_create_info_t **cinfo, const char* filename, ops_bo
|
||||
flags |= O_EXCL;
|
||||
flags |= O_BINARY;
|
||||
|
||||
fd=open(filename, flags, 0600);
|
||||
fd=ops_open(filename, flags, 0600);
|
||||
if(fd < 0)
|
||||
{
|
||||
perror(filename);
|
||||
@ -221,7 +222,7 @@ int ops_setup_file_append(ops_create_info_t **cinfo, const char* filename)
|
||||
* initialise needed structures for writing to file
|
||||
*/
|
||||
|
||||
fd=open(filename,O_WRONLY | O_APPEND | O_BINARY | O_CREAT, 0600);
|
||||
fd=ops_open(filename,O_WRONLY | O_APPEND | O_BINARY | O_CREAT, 0600);
|
||||
|
||||
if(fd < 0)
|
||||
{
|
||||
@ -267,7 +268,7 @@ int ops_setup_file_read(ops_parse_info_t **pinfo, const char *filename,
|
||||
* initialise needed structures for reading
|
||||
*/
|
||||
|
||||
fd=open(filename,O_RDONLY | O_BINARY);
|
||||
fd=ops_open(filename,O_RDONLY | O_BINARY, 0);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <openpgpsdk/final.h>
|
||||
#include <util/opsdir.h>
|
||||
|
||||
#include <openssl/dsa.h>
|
||||
|
||||
@ -1001,7 +1002,7 @@ ops_boolean_t ops_sign_file_as_cleartext(const char* input_filename,
|
||||
|
||||
// open file to sign
|
||||
|
||||
fd_in=open(input_filename, O_RDONLY | O_BINARY);
|
||||
fd_in=ops_open(input_filename, O_RDONLY | O_BINARY, 0);
|
||||
|
||||
if(fd_in < 0)
|
||||
{
|
||||
|
22
openpgpsdk/src/util/opsdir.c
Normal file
22
openpgpsdk/src/util/opsdir.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include "opsdir.h"
|
||||
#include "opsstring.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
int ops_open(const char* filename, int flag, int pmode)
|
||||
{
|
||||
#ifdef WIN32
|
||||
wchar_t *wfilename = ConvertUtf8ToUtf16(filename);
|
||||
if (!wfilename)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = _wopen(wfilename, flag, pmode);
|
||||
free(wfilename);
|
||||
|
||||
return result;
|
||||
#else
|
||||
return open(filename, flag, pmode);
|
||||
#endif
|
||||
}
|
6
openpgpsdk/src/util/opsdir.h
Normal file
6
openpgpsdk/src/util/opsdir.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef OPUTIL_H
|
||||
#define OPUTIL_H
|
||||
|
||||
int ops_open(const char* filename, int flag, int pmode);
|
||||
|
||||
#endif
|
55
openpgpsdk/src/util/opsstring.c
Normal file
55
openpgpsdk/src/util/opsstring.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include "opsstring.h"
|
||||
|
||||
#ifdef WIN32
|
||||
wchar_t *ConvertUtf8ToUtf16(const char* source)
|
||||
{
|
||||
if (!source) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int nbChars = MultiByteToWideChar(CP_UTF8, 0, source, -1, 0, 0);
|
||||
if (nbChars == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wchar_t* utf16Name = (wchar_t*) malloc(nbChars * sizeof(wchar_t));
|
||||
if (MultiByteToWideChar(CP_UTF8, 0, source, -1, utf16Name, nbChars) == 0) {
|
||||
free(utf16Name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return utf16Name;
|
||||
#else
|
||||
// currently only for WIN32
|
||||
// convert code from rsstring.cc
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
char* ConvertUtf16ToUtf8(const wchar_t *source)
|
||||
{
|
||||
if (!source) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int nbChars = WideCharToMultiByte(CP_UTF8, 0, source, -1, 0, 0, 0, 0);
|
||||
if (nbChars == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* utf8Name = (char*) malloc(nbChars * sizeof(char));
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, source, -1, utf8Name, nbChars, 0, 0) == 0) {
|
||||
free(utf8Name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return utf8Name;
|
||||
#else
|
||||
// currently only for WIN32
|
||||
// convert code from rsstring.cc
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
#endif
|
17
openpgpsdk/src/util/opsstring.h
Normal file
17
openpgpsdk/src/util/opsstring.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef OPSSTRING_H
|
||||
#define OPSSTRING_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include <wtypes.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
// currently only for WIN32
|
||||
|
||||
// Convert strings between UTF8 and UTF16
|
||||
// Don't forget to free the returned string.
|
||||
wchar_t* ConvertUtf8ToUtf16(const char *source);
|
||||
char* ConvertUtf16ToUtf8(const wchar_t* source);
|
||||
#endif
|
||||
|
||||
#endif // OPSSTRING_H
|
Loading…
Reference in New Issue
Block a user