cleaned up usage of MAX_PATH and related macros
This commit is contained in:
parent
2fd925a4ae
commit
3d9c8f1b2d
|
@ -1,4 +1,5 @@
|
|||
* added support for i2p torrents
|
||||
* cleaned up usage of MAX_PATH and related macros
|
||||
|
||||
0.15 release
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace libtorrent
|
|||
virtual char const* what() const { return "file completed"; }
|
||||
virtual std::string message() const
|
||||
{
|
||||
char msg[200];
|
||||
char msg[200 + TORRENT_MAX_PATH];
|
||||
snprintf(msg, sizeof(msg), "%s: file %d finished downloading"
|
||||
, torrent_alert::message().c_str(), index);
|
||||
return msg;
|
||||
|
@ -164,7 +164,7 @@ namespace libtorrent
|
|||
virtual char const* what() const { return "file renamed"; }
|
||||
virtual std::string message() const
|
||||
{
|
||||
char msg[200 + NAME_MAX];
|
||||
char msg[200 + TORRENT_MAX_PATH * 2];
|
||||
snprintf(msg, sizeof(msg), "%s: file %d renamed to %s", torrent_alert::message().c_str()
|
||||
, index, name.c_str());
|
||||
return msg;
|
||||
|
@ -190,7 +190,7 @@ namespace libtorrent
|
|||
virtual char const* what() const { return "file rename failed"; }
|
||||
virtual std::string message() const
|
||||
{
|
||||
char ret[200 + NAME_MAX];
|
||||
char ret[200 + TORRENT_MAX_PATH * 2];
|
||||
snprintf(ret, sizeof(ret), "%s: failed to rename file %d: %s"
|
||||
, torrent_alert::message().c_str(), index, error.message().c_str());
|
||||
return ret;
|
||||
|
|
|
@ -157,20 +157,36 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
// (disables some float-dependent APIs)
|
||||
#define TORRENT_NO_FPU 0
|
||||
|
||||
// make sure NAME_MAX is defined
|
||||
#ifndef NAME_MAX
|
||||
#ifdef MAXPATH
|
||||
#define NAME_MAX MAXPATH
|
||||
|
||||
// on windows, NAME_MAX refers to Unicode characters
|
||||
// on linux it refers to bytes (utf-8 encoded)
|
||||
// TODO: Make this count Unicode characters instead of bytes on windows
|
||||
|
||||
// windows
|
||||
#if defined FILENAME_MAX
|
||||
#define TORRENT_MAX_PATH FILENAME_MAX
|
||||
|
||||
// solaris
|
||||
#elif defined MAXPATH
|
||||
#define TORRENT_MAX_PATH MAXPATH
|
||||
|
||||
// posix
|
||||
#elif defined NAME_MAX
|
||||
#define TORRENT_MAX_PATH NAME_MAX
|
||||
|
||||
// none of the above
|
||||
#else
|
||||
// this is the maximum number of characters in a
|
||||
// path element / filename on windows
|
||||
#define NAME_MAX 255
|
||||
#endif // MAXPATH
|
||||
#endif // NAME_MAX
|
||||
#warning unknown platform, assuming the longest path is 255
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
|
||||
#pragma warning(disable:4251) // class X needs to have dll-interface to be used by clients of class Y
|
||||
// class X needs to have dll-interface to be used by clients of class Y
|
||||
#pragma warning(disable:4251)
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
|
@ -203,14 +203,7 @@ namespace libtorrent
|
|||
|
||||
void trim_path_element(std::string& path_element)
|
||||
{
|
||||
#ifdef FILENAME_MAX
|
||||
const int max_path_len = FILENAME_MAX;
|
||||
#else
|
||||
// on windows, NAME_MAX refers to Unicode characters
|
||||
// on linux it refers to bytes (utf-8 encoded)
|
||||
// TODO: Make this count Unicode characters instead of bytes on windows
|
||||
const int max_path_len = NAME_MAX;
|
||||
#endif
|
||||
const int max_path_len = TORRENT_MAX_PATH;
|
||||
if (path_element.size() > max_path_len)
|
||||
{
|
||||
// truncate filenames that are too long. But keep extensions!
|
||||
|
|
Loading…
Reference in New Issue