mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-24 06:14:25 -04:00
Removed some std::ostringstream.
To be continued. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5111 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a9e496f845
commit
4e26884646
14 changed files with 190 additions and 131 deletions
|
@ -24,9 +24,9 @@
|
|||
*/
|
||||
|
||||
#include "util/bdbloom.h"
|
||||
#include "util/bdstring.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
|
@ -131,7 +131,6 @@ int bloomFilter::setFilterBits(const std::string &hex)
|
|||
std::string bloomFilter::getFilter()
|
||||
{
|
||||
/* extract filter as a hex string */
|
||||
std::string output;
|
||||
int bytes = (mFilterBits / BITS_PER_BYTE);
|
||||
if (mFilterBits % BITS_PER_BYTE)
|
||||
{
|
||||
|
@ -155,15 +154,15 @@ std::string bloomFilter::getFilter()
|
|||
}
|
||||
}
|
||||
|
||||
std::ostringstream out;
|
||||
std::string out;
|
||||
for(int i = 0; i < bytes; i++)
|
||||
{
|
||||
out << std::setw(2) << std::setfill('0') << std::hex << (uint32_t) (tmparray)[i];
|
||||
bd_sprintf_append(out, "%02lx", (uint32_t) (tmparray)[i]);
|
||||
}
|
||||
|
||||
free(tmparray);
|
||||
|
||||
return out.str();
|
||||
return out;
|
||||
}
|
||||
|
||||
void bloomFilter::setBit(int bit)
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
*/
|
||||
|
||||
#include "bdnet.h"
|
||||
#include "bdstring.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -361,11 +361,8 @@ void bdsockaddr_clear(struct sockaddr_in *addr)
|
|||
|
||||
std::string bdnet_inet_ntoa(struct in_addr in)
|
||||
{
|
||||
std::ostringstream str;
|
||||
std::string str;
|
||||
uint8_t *bytes = (uint8_t *) &(in.s_addr);
|
||||
str << (int) bytes[0] << ".";
|
||||
str << (int) bytes[1] << ".";
|
||||
str << (int) bytes[2] << ".";
|
||||
str << (int) bytes[3];
|
||||
return str.str();
|
||||
bd_sprintf(str, "%u.%u.%u.%u", (int) bytes[0], (int) bytes[1], (int) bytes[2], (int) bytes[3]);
|
||||
return str;
|
||||
}
|
||||
|
|
83
libbitdht/src/util/bdstring.cc
Normal file
83
libbitdht/src/util/bdstring.cc
Normal file
|
@ -0,0 +1,83 @@
|
|||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2012, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include "bdstring.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
// asprintf() and vasprintf() are missing in Win32
|
||||
static int vasprintf(char **sptr, const char *fmt, va_list argv)
|
||||
{
|
||||
int wanted = __mingw_vsnprintf(*sptr = NULL, 0, fmt, argv);
|
||||
if ((wanted > 0) && ((*sptr = (char*) malloc(wanted + 1)) != NULL)) {
|
||||
return __mingw_vsprintf(*sptr, fmt, argv);
|
||||
}
|
||||
|
||||
return wanted;
|
||||
}
|
||||
|
||||
//int asprintf(char **sptr, const char *fmt, ...)
|
||||
//{
|
||||
// int retval;
|
||||
// va_list argv;
|
||||
// va_start( argv, fmt );
|
||||
// retval = vasprintf(sptr, fmt, argv);
|
||||
// va_end(argv);
|
||||
// return retval;
|
||||
//}
|
||||
#endif
|
||||
|
||||
int bd_sprintf(std::string &str, const char *fmt, ...)
|
||||
{
|
||||
char *buffer;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
int retval = vasprintf(&buffer, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
str = buffer;
|
||||
free(buffer);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int bd_sprintf_append(std::string &str, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *ret;
|
||||
|
||||
va_start(ap, fmt);
|
||||
int retval = vasprintf(&ret, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
str.append(ret);
|
||||
free(ret);
|
||||
|
||||
return retval;
|
||||
}
|
|
@ -22,6 +22,8 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef WIN32
|
||||
// for proper handling of %ll
|
||||
#define bd_snprintf __mingw_snprintf
|
||||
|
@ -31,5 +33,7 @@
|
|||
#define bd_fprintf fprintf
|
||||
#endif
|
||||
|
||||
int bd_sprintf(std::string &str, const char *fmt, ...);
|
||||
int bd_sprintf_append(std::string &str, const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue