Commit 459852fd authored by Eric Cano's avatar Eric Cano
Browse files

Catching up with master branch.

parents 680ce2b4 d2a1e1c9
......@@ -244,6 +244,7 @@ set (CLIENT_LIB_SRC_FILES
stager/NsFileId.cpp
stager/BulkRequestResult.cpp
stager/FileResult.cpp
utils/SmartFd.cpp
utils/utils.cpp
vdqm/ClientIdentification.cpp
vdqm/TapeDrive.cpp
......
......@@ -27,8 +27,9 @@
#include "castor/exception/Internal.hpp"
#include "castor/exception/InvalidArgument.hpp"
#include "castor/tape/net/net.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "h/serrno.h"
#include "h/net.h"
......@@ -71,7 +72,7 @@ int castor::tape::net::createListenerSock(
}
// Create a socket
utils::SmartFd sock(socket(PF_INET, SOCK_STREAM, IPPROTO_TCP));
castor::utils::SmartFd sock(socket(PF_INET, SOCK_STREAM, IPPROTO_TCP));
if(sock.get() < 0) {
const int savedErrno = errno;
......@@ -393,7 +394,7 @@ void castor::tape::net::getSockHostName(
": " << gai_strerror(error));
}
utils::copyString(buf, len, hostName);
castor::utils::copyString(buf, len, hostName);
}
......@@ -486,7 +487,7 @@ void castor::tape::net::getPeerHostName(
": " << gai_strerror(rc));
}
utils::copyString(buf, len, hostName);
castor::utils::copyString(buf, len, hostName);
}
}
......@@ -720,7 +721,7 @@ int castor::tape::net::connectWithTimeout(
throw(castor::exception::TimeOut, castor::exception::Exception) {
// Create the socket for the new connection
utils::SmartFd smartSock(socket(sockDomain, sockType, sockProtocol));
castor::utils::SmartFd smartSock(socket(sockDomain, sockType, sockProtocol));
if(-1 == smartSock.get()) {
const int socketErrno = errno;
TAPE_THROW_CODE(errno,
......
......@@ -55,9 +55,9 @@
#include "castor/tape/tapegateway/FileToRecallStruct.hpp"
#include "castor/tape/tapegateway/NoMoreFiles.hpp"
#include "castor/tape/tapegateway/NotificationAcknowledge.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/SmartFdList.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "h/Ctape_constants.h"
#include "h/getconfent.h"
......@@ -131,7 +131,7 @@ castor::tape::tapebridge::BridgeProtocolEngine::BridgeProtocolEngine(
int castor::tape::tapebridge::BridgeProtocolEngine::acceptRtcpdConnection()
throw(castor::exception::Exception) {
utils::SmartFd connectedSock;
castor::utils::SmartFd connectedSock;
const int timeout = 5; // Seconds
bool connectionAccepted = false;
......@@ -716,7 +716,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Release the socket-descriptor from the catalogue
uint64_t tapebridgeTransId = 0;
utils::SmartFd catalogueSock(
castor::utils::SmartFd catalogueSock(
m_sockCatalogue.releaseClientMigrationReportSock(tapebridgeTransId));
// Check for a mismatch between the pending and catalogue socket-decriptors
......@@ -913,7 +913,7 @@ bool castor::tape::tapebridge::BridgeProtocolEngine::startMigrationSession()
m_tapebridgeTransactionCounter.next();
const uint64_t maxFiles = 1;
const uint64_t maxBytes = 1;
utils::SmartFd clientSock(m_clientProxy.sendFilesToMigrateListRequest(
castor::utils::SmartFd clientSock(m_clientProxy.sendFilesToMigrateListRequest(
tapebridgeTransId, maxFiles, maxBytes));
// Receive the reply
......@@ -1028,11 +1028,11 @@ bool castor::tape::tapebridge::BridgeProtocolEngine::startMigrationSession()
// Give volume to rtcpd
legacymsg::RtcpTapeRqstErrMsgBody rtcpVolume;
utils::setBytes(rtcpVolume, '\0');
utils::copyString(rtcpVolume.vid , m_volume.vid().c_str() );
utils::copyString(rtcpVolume.vsn , EMPTYVSN );
utils::copyString(rtcpVolume.label , m_volume.label().c_str() );
utils::copyString(rtcpVolume.density, m_volume.density().c_str());
utils::copyString(rtcpVolume.unit , m_jobRequest.driveUnit );
castor::utils::copyString(rtcpVolume.vid , m_volume.vid().c_str() );
castor::utils::copyString(rtcpVolume.vsn , EMPTYVSN );
castor::utils::copyString(rtcpVolume.label , m_volume.label().c_str() );
castor::utils::copyString(rtcpVolume.density, m_volume.density().c_str());
castor::utils::copyString(rtcpVolume.unit , m_jobRequest.driveUnit );
rtcpVolume.volReqId = m_jobRequest.volReqId;
rtcpVolume.mode = WRITE_ENABLE;
rtcpVolume.tStartRequest = time(NULL);
......@@ -1093,7 +1093,7 @@ bool castor::tape::tapebridge::BridgeProtocolEngine::startMigrationSession()
unsigned char blockId[4];
utils::setBytes(blockId, '\0');
char nshost[CA_MAXHOSTNAMELEN+1];
utils::copyString(nshost, firstFileToMigrate->nshost().c_str());
castor::utils::copyString(nshost, firstFileToMigrate->nshost().c_str());
RtcpTxRx::giveFileToRtcpd(
m_cuuid,
......@@ -1139,11 +1139,11 @@ void castor::tape::tapebridge::BridgeProtocolEngine::startRecallSession()
// Give volume to rtcpd
legacymsg::RtcpTapeRqstErrMsgBody rtcpVolume;
utils::setBytes(rtcpVolume, '\0');
utils::copyString(rtcpVolume.vid , m_volume.vid().c_str() );
utils::copyString(rtcpVolume.vsn , EMPTYVSN );
utils::copyString(rtcpVolume.label , m_volume.label().c_str() );
utils::copyString(rtcpVolume.density, m_volume.density().c_str());
utils::copyString(rtcpVolume.unit , m_jobRequest.driveUnit );
castor::utils::copyString(rtcpVolume.vid , m_volume.vid().c_str() );
castor::utils::copyString(rtcpVolume.vsn , EMPTYVSN );
castor::utils::copyString(rtcpVolume.label , m_volume.label().c_str() );
castor::utils::copyString(rtcpVolume.density, m_volume.density().c_str());
castor::utils::copyString(rtcpVolume.unit , m_jobRequest.driveUnit );
rtcpVolume.volReqId = m_jobRequest.volReqId;
rtcpVolume.mode = WRITE_DISABLE;
rtcpVolume.tStartRequest = time(NULL);
......@@ -1176,11 +1176,11 @@ void castor::tape::tapebridge::BridgeProtocolEngine::startDumpSession()
// Give volume to rtcpd
legacymsg::RtcpTapeRqstErrMsgBody rtcpVolume;
utils::setBytes(rtcpVolume, '\0');
utils::copyString(rtcpVolume.vid , m_volume.vid().c_str() );
utils::copyString(rtcpVolume.vsn , EMPTYVSN );
utils::copyString(rtcpVolume.label , m_volume.label().c_str() );
utils::copyString(rtcpVolume.density, m_volume.density().c_str());
utils::copyString(rtcpVolume.unit , m_jobRequest.driveUnit );
castor::utils::copyString(rtcpVolume.vid , m_volume.vid().c_str() );
castor::utils::copyString(rtcpVolume.vsn , EMPTYVSN );
castor::utils::copyString(rtcpVolume.label , m_volume.label().c_str() );
castor::utils::copyString(rtcpVolume.density, m_volume.density().c_str());
castor::utils::copyString(rtcpVolume.unit , m_jobRequest.driveUnit );
rtcpVolume.volReqId = m_jobRequest.volReqId;
rtcpVolume.mode = WRITE_DISABLE;
rtcpVolume.tStartRequest = time(NULL);
......@@ -1692,7 +1692,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
tapegateway::TAPE_GATEWAY == m_volume.clientType() ?
m_bulkRequestConfigParams.getBulkRequestMigrationMaxBytes().getValue() :
1;
utils::SmartFd clientSock(m_clientProxy.sendFilesToMigrateListRequest(
castor::utils::SmartFd clientSock(m_clientProxy.sendFilesToMigrateListRequest(
tapebridgeTransId, maxFiles, maxBytes));
try {
......@@ -1792,7 +1792,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
tapegateway::TAPE_GATEWAY == m_volume.clientType() ?
m_bulkRequestConfigParams.getBulkRequestRecallMaxBytes().getValue() :
1;
utils::SmartFd clientSock(m_clientProxy.sendFilesToRecallListRequest(
castor::utils::SmartFd clientSock(m_clientProxy.sendFilesToRecallListRequest(
tapebridgeTransId, maxFiles, maxBytes));
{
castor::dlf::Param params[] = {
......@@ -1894,7 +1894,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::sendFileToRecallToRtcpd(
fileToRecall.blockId2,
fileToRecall.blockId3};
char nshost[CA_MAXHOSTNAMELEN+1];
utils::copyString(nshost, fileToRecall.nsHost.c_str());
castor::utils::copyString(nshost, fileToRecall.nsHost.c_str());
// The file size is not specified when recalling
const uint64_t fileSize = 0;
......@@ -2340,7 +2340,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Send the report to the client
timeval connectDuration = {0, 0};
utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(report,
castor::utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(report,
connectDuration));
{
const double connectDurationDouble =
......@@ -2797,7 +2797,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Send the report message to the client (the tapegewayd daemon or the
// writetp command-line tool
timeval connectDuration = {0, 0};
utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(report,
castor::utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(report,
connectDuration));
{
const double connectDurationDouble =
......@@ -3038,7 +3038,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::sendFileToMigrateToRtcpd(
unsigned char blockId[4];
utils::setBytes(blockId, '\0');
char nshost[CA_MAXHOSTNAMELEN+1];
utils::copyString(nshost, fileToMigrate.nsHost.c_str());
castor::utils::copyString(nshost, fileToMigrate.nsHost.c_str());
RtcpTxRx::giveFileToRtcpd(
m_cuuid,
......@@ -3583,7 +3583,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Send the report to the client and receive the reply
timeval connectDuration = {0, 0};
utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(
castor::utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(
listReport, connectDuration));
try {
m_clientProxy.receiveNotificationReplyAndClose(
......@@ -3658,7 +3658,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::
// Send the report to the client and receive the reply
timeval connectDuration = {0, 0};
utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(
castor::utils::SmartFd clientSock(m_clientProxy.connectAndSendMessage(
listReport, connectDuration));
try {
m_clientProxy.receiveNotificationReplyAndClose(tapebridgeTransId,
......
......@@ -24,8 +24,8 @@
#include "castor/tape/net/net.hpp"
#include "castor/tape/tapebridge/ClientAddressLocal.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include <errno.h>
......@@ -95,7 +95,7 @@ int castor::tape::tapebridge::ClientAddressLocal::connectToClient(
timeval connectEndTime = {0, 0};
utils::getTimeOfDay(&connectStartTime, NULL);
utils::SmartFd smartConnectSock;
castor::utils::SmartFd smartConnectSock;
try {
smartConnectSock.reset(net::connectWithTimeout(
PF_LOCAL,
......
......@@ -41,8 +41,8 @@
#include "castor/tape/tapegateway/PingNotification.hpp"
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/tapegateway/VolumeRequest.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include <memory>
......@@ -259,7 +259,7 @@ int castor::tape::tapebridge::ClientProxy::sendFilesToMigrateListRequest(
request.setMaxBytes(maxBytes);
// Send the request and return the socket-descriptor of the connection
utils::SmartFd clientSock;
castor::utils::SmartFd clientSock;
timeval connectDuration = {0, 0};
try {
clientSock.reset(connectAndSendMessage(request, connectDuration));
......
......@@ -32,6 +32,7 @@
#include "castor/tape/net/net.hpp"
#include "castor/tape/tapegateway/NoMoreFiles.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/utils.hpp"
#include "h/common.h"
#include "h/Ctape_constants.h"
#include "h/rtcp.h"
......@@ -570,9 +571,9 @@ void castor::tape::tapebridge::RtcpTxRx::askRtcpdToRequestMoreWork(
utils::setBytes(msgBody, '\0');
utils::copyString(msgBody.rqst.recfm_noLongerUsed, "F");
castor::utils::copyString(msgBody.rqst.recfm_noLongerUsed, "F");
utils::copyString(msgBody.rqst.tapePath, tapePath);
castor::utils::copyString(msgBody.rqst.tapePath, tapePath);
msgBody.rqst.volReqId = volReqId;
msgBody.rqst.jobId = -1;
msgBody.rqst.stageSubReqId = -1;
......@@ -666,10 +667,10 @@ void castor::tape::tapebridge::RtcpTxRx::giveFileToRtcpd(
// Give file information to RTCPD
utils::setBytes(msgBody, '\0');
utils::copyString(msgBody.rqst.filePath, filePath );
utils::copyString(msgBody.rqst.tapePath, tapePath );
utils::copyString(msgBody.rqst.recfm_noLongerUsed, "F");
utils::copyString(msgBody.rqst.fid , tapeFileId );
castor::utils::copyString(msgBody.rqst.filePath, filePath );
castor::utils::copyString(msgBody.rqst.tapePath, tapePath );
castor::utils::copyString(msgBody.rqst.recfm_noLongerUsed, "F");
castor::utils::copyString(msgBody.rqst.fid , tapeFileId );
msgBody.rqst.volReqId = volReqId;
msgBody.rqst.jobId = -1;
......@@ -693,7 +694,7 @@ void castor::tape::tapebridge::RtcpTxRx::giveFileToRtcpd(
msgBody.rqst.blockId[2] = blockId[2];
msgBody.rqst.blockId[3] = blockId[3];
msgBody.rqst.bytesIn = fileSize;
utils::copyString(msgBody.rqst.segAttr.nameServerHostName,
castor::utils::copyString(msgBody.rqst.segAttr.nameServerHostName,
nameServerHostName);
msgBody.rqst.segAttr.castorFileId = castorFileId;
msgBody.err.severity = RTCP_OK;
......
......@@ -46,9 +46,10 @@
#include "castor/tape/tapegateway/FileErrorReportStruct.hpp"
#include "castor/tape/tapegateway/VolumeRequest.hpp"
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/tape/utils/SmartFdList.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "h/common.h"
#include "h/Ctape_constants.h"
#include "h/rtcp_constants.h"
......@@ -128,7 +129,7 @@ void castor::tape::tapebridge::VdqmRequestHandler::run(void *param)
// Wrap the VDQM connection socket within a smart file-descriptor. When the
// smart file-descriptor goes out of scope it will close file-descriptor of
// the socket.
utils::SmartFd vdqmSock;
castor::utils::SmartFd vdqmSock;
{
castor::io::ServerSocket *tmpServerSocket =
(castor::io::ServerSocket*)param;
......@@ -245,8 +246,8 @@ void castor::tape::tapebridge::VdqmRequestHandler::run(void *param)
const unsigned short highPort = utils::getPortFromConfig(
"TAPEBRIDGE", "RTCPDHIGHPORT", TAPEBRIDGE_RTCPDHIGHPORT);
unsigned short chosenPort = 0;
utils::SmartFd listenSock(net::createListenerSock("127.0.0.1", lowPort,
highPort, chosenPort));
castor::utils::SmartFd listenSock(net::createListenerSock("127.0.0.1",
lowPort, highPort, chosenPort));
// Get and log the IP, host name, port and socket file-descriptor of the
// callback socket
......@@ -400,11 +401,13 @@ castor::tape::legacymsg::RtcpJobReplyMsgBody
clientInfoMsgBody.maxFilesBeforeFlush = 1;
}
utils::copyString(clientInfoMsgBody.bridgeHost, bridgeCallbackHost);
utils::copyString(clientInfoMsgBody.bridgeClientHost, jobRequest.clientHost);
utils::copyString(clientInfoMsgBody.dgn, jobRequest.dgn);
utils::copyString(clientInfoMsgBody.drive, jobRequest.driveUnit);
utils::copyString(clientInfoMsgBody.clientName, jobRequest.clientUserName);
castor::utils::copyString(clientInfoMsgBody.bridgeHost, bridgeCallbackHost);
castor::utils::copyString(clientInfoMsgBody.bridgeClientHost,
jobRequest.clientHost);
castor::utils::copyString(clientInfoMsgBody.dgn, jobRequest.dgn);
castor::utils::copyString(clientInfoMsgBody.drive, jobRequest.driveUnit);
castor::utils::copyString(clientInfoMsgBody.clientName,
jobRequest.clientUserName);
try {
castor::tape::tapebridge::BridgeClientInfo2Sender::send(
......@@ -436,8 +439,8 @@ void castor::tape::tapebridge::VdqmRequestHandler::exceptionThrowingRun(
// Accept the initial incoming RTCPD callback connection.
// Wrap the socket file descriptor in a smart file descriptor so that it is
// guaranteed to be closed if it goes out of scope.
utils::SmartFd rtcpdInitialSock(net::acceptConnection(bridgeCallbackSockFd,
RTCPDCALLBACKTIMEOUT));
castor::utils::SmartFd rtcpdInitialSock(
net::acceptConnection(bridgeCallbackSockFd, RTCPDCALLBACKTIMEOUT));
// Log the initial callback connection from RTCPD
try {
......
......@@ -59,7 +59,7 @@ void castor::tape::tapebridge::VmgrTxRx::getTapeInfoFromVmgr(
char *p = NULL;
if((p = getenv("VMGR_HOST")) || (p = getconfent("VMGR", "HOST", 0))) {
utils::copyString(vmgrHost, p);
castor::utils::copyString(vmgrHost, p);
} else {
castor::exception::Exception ex(EVMGRNOHOST);
......@@ -110,7 +110,7 @@ void castor::tape::tapebridge::VmgrTxRx::getTapeInfoFromVmgr(
utils::setBytes(request, '\0');
request.uid = uid;
request.gid = gid;
utils::copyString(request.vid, vid);
castor::utils::copyString(request.vid, vid);
request.side = 0; // HARDCODED side
// Marshal the request
......
......@@ -137,7 +137,7 @@ void castor::tape::tpcp::DumpTpCommand::parseCommandLine(const int argc,
case 's':
m_cmdLine.serverSet = true;
try {
utils::copyString(m_cmdLine.server, optarg);
castor::utils::copyString(m_cmdLine.server, optarg);
} catch(castor::exception::Exception &ex) {
TAPE_THROW_EX(castor::exception::Internal,
": Failed to copy the argument of the server command-line option"
......@@ -321,7 +321,7 @@ void castor::tape::tpcp::DumpTpCommand::parseCommandLine(const int argc,
// Parse the VID command-line argument
try {
utils::copyString(m_cmdLine.vid, argv[optind]);
castor::utils::copyString(m_cmdLine.vid, argv[optind]);
} catch(castor::exception::Exception &ex) {
TAPE_THROW_EX(castor::exception::Internal,
": Failed to copy VID comand-line argument into the internal data"
......
......@@ -148,7 +148,7 @@ void castor::tape::tpcp::ReadTpCommand::parseCommandLine(const int argc,
case 's':
m_cmdLine.serverSet = true;
try {
utils::copyString(m_cmdLine.server, optarg);
castor::utils::copyString(m_cmdLine.server, optarg);
} catch(castor::exception::Exception &ex) {
TAPE_THROW_EX(castor::exception::Internal,
": Failed to copy the argument of the server command-line option"
......@@ -266,7 +266,7 @@ void castor::tape::tpcp::ReadTpCommand::parseCommandLine(const int argc,
// Parse the VID command-line argument
try {
utils::copyString(m_cmdLine.vid, argv[optind]);
castor::utils::copyString(m_cmdLine.vid, argv[optind]);
} catch(castor::exception::Exception &ex) {
TAPE_THROW_EX(castor::exception::Internal,
": Failed to copy VID comand-line argument into the internal data"
......
......@@ -136,7 +136,7 @@ void castor::tape::tpcp::WriteTpCommand::parseCommandLine(const int argc,
case 's':
m_cmdLine.serverSet = true;
try {
utils::copyString(m_cmdLine.server, optarg);
castor::utils::copyString(m_cmdLine.server, optarg);
} catch(castor::exception::Exception &ex) {
TAPE_THROW_EX(castor::exception::Internal,
": Failed to copy the argument of the server command-line option"
......@@ -222,7 +222,7 @@ void castor::tape::tpcp::WriteTpCommand::parseCommandLine(const int argc,
// Parse the VID command-line argument
try {
utils::copyString(m_cmdLine.vid, argv[optind]);
castor::utils::copyString(m_cmdLine.vid, argv[optind]);
} catch(castor::exception::Exception &ex) {
TAPE_THROW_EX(castor::exception::Internal,
": Failed to copy VID comand-line argument into the internal data"
......
......@@ -30,7 +30,6 @@ set (TAPE_UTILS_LIB_SRC_FILES
ShutdownBoolFunctor.cpp
ScopedLock.cpp
SmartFILEPtr.cpp
SmartFd.cpp
SmartFdList.cpp
Timer.cpp
utils.cpp)
......
......@@ -144,46 +144,6 @@ void castor::tape::utils::toHex(const uint64_t i, char *dst,
dst[nbDigits] = '\0';
}
//-----------------------------------------------------------------------------
// copyString
//-----------------------------------------------------------------------------
void castor::tape::utils::copyString(char *const dst, const size_t dstSize,
const char *const src) throw(castor::exception::Exception) {
if(dst == NULL) {
castor::exception::Exception ex(EINVAL);
ex.getMessage() << __FUNCTION__
<< ": Pointer to destination string is NULL";
throw ex;
}
if(src == NULL) {
castor::exception::Exception ex(EINVAL);
ex.getMessage() << __FUNCTION__
<< ": Pointer to source string is NULL";
throw ex;
}
const size_t srcLen = strlen(src);
if(srcLen >= dstSize) {
castor::exception::Exception ex(EINVAL);
ex.getMessage() << __FUNCTION__
<< ": Source string is longer than destination. Source length: "
<< srcLen << " Max destination length: " << (dstSize - 1);
throw ex;
}
strncpy(dst, src, dstSize);
*(dst + dstSize -1) = '\0'; // Ensure destination string is null terminated
}
//-----------------------------------------------------------------------------
// writeStrings
//-----------------------------------------------------------------------------
......
......@@ -178,33 +178,6 @@ template<typename T> void setBytes(T &object, const int c) throw() {
memset(&object, c, sizeof(object));
}
/**
* Safely copies source string into destination string. The destination
* will always be null terminated if this function is successful.
*
* @param dst Destination string.
* @param dstSize The size of the destination string including the terminating
* null character.
* @param src Source string.
* destination.
*/
void copyString(char *const dst, const size_t dstSize, const char *const src)
throw(castor::exception::Exception);
/**
* Safely copies source string into destination string. The destination
* will always be null terminated if this function is successful.
*
* @param dst Destination string.
* @param src Source string.
*/
template<size_t dstSize> void copyString(char (&dst)[dstSize],
const char *const src)
throw(castor::exception::Exception) {
copyString(dst, dstSize, src);
}
/**
* Writes the specified array of strings to the specified output stream as a
* list of strings separated by the specified separator.
......
/******************************************************************************
* castor/tape/utils/SmartFd.cpp
* castor/utils/SmartFd.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
......@@ -23,41 +23,37 @@
* @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/utils/SmartFd.hpp"
#include "castor/utils/SmartFd.hpp"
#include <errno.h>
#include <unistd.h>
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::tape::utils::SmartFd::SmartFd() throw():
castor::utils::SmartFd::SmartFd() throw():
m_fd(-1), m_closedCallback(NULL) {
}
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::tape::utils::SmartFd::SmartFd(const int fd) throw():
castor::utils::SmartFd::SmartFd(const int fd) throw():
m_fd(fd), m_closedCallback(NULL) {
}
//-----------------------------------------------------------------------------
// setClosedCallback
//-----------------------------------------------------------------------------
void castor::tape::utils::SmartFd::setClosedCallback
(const int, ClosedCallback closedCallback) throw() {
void castor::utils::SmartFd::setClosedCallback(ClosedCallback closedCallback)
throw() {
m_closedCallback = closedCallback;
}
//-----------------------------------------------------------------------------
// reset
//-----------------------------------------------------------------------------
void castor::tape::utils::SmartFd::reset(const int fd = -1) throw() {
void castor::utils::SmartFd::reset(const int fd = -1) throw() {
// If the new file descriptor is not the one already owned
if(fd != m_fd) {
......@@ -80,50 +76,38 @@ void castor::tape::utils::SmartFd::reset(const int fd = -1) throw() {
}
}
//-----------------------------------------------------------------------------
// SmartFd assignment operator
//-----------------------------------------------------------------------------
castor::tape::utils::SmartFd
&castor::tape::utils::SmartFd::operator=(SmartFd& obj) throw() {
castor::utils::SmartFd &castor::utils::SmartFd::operator=(SmartFd& obj)
throw() {
reset(obj.release());
return *this;
}
//-----------------------------------------------------------------------------