⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strdup.cpp

📁 rtsp协议的主要实现代码.对开发流媒体
💻 CPP
字号:
/**********
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)

This library 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 Lesser General Public License for
more details.

You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
**********/
// Copyright (c) 1996-2003 Live Networks, Inc.  All rights reserved.
// A C++ equivalent to the standard C routine "strdup()".
// This generates a char* that can be deleted using "delete[]"
// Implementation
#include "StdAfx.h"
#include "strDup.hh"
#include "string.h"

char* strDup(char const* str) 
{
  if (str == NULL) return NULL;
  size_t len = strlen(str) + 1;
  char* copy = new char[len];

  if (copy != NULL) 
  {
    memcpy(copy, str, len);
  }
  return copy;
}

char* strDupSize(char const* str) 
{
  if (str == NULL) return NULL;
  size_t len = strlen(str) + 1;
  char* copy = new char[len];

  return copy;
}

unsigned our_inet_addr(char const* cp)
{
	return inet_addr(cp);
}

char * our_inet_ntoa(struct in_addr in)
{
#ifndef VXWORKS
	return inet_ntoa(in);
#else
	/* according the man pages of inet_ntoa :
	
	  NOTES
	  The return value from inet_ntoa() points to a  buffer  which
	  is  overwritten on each call.  This buffer is implemented as
	  thread-specific data in multithreaded applications.
	  
		the vxworks version of inet_ntoa allocates a buffer for each
		ip address string, and does not reuse the same buffer.
		
		  this is merely to simulate the same behaviour (not multithread
		  safe though):
	*/
	static char result[INET_ADDR_LEN];
	inet_ntoa_b(in, result);
	return(result);
#endif
}

int gettimeofday(struct timeval* tp, int* /*tz*/) 
{
#if defined(_WIN32_WCE)
	/* FILETIME of Jan 1 1970 00:00:00. */
	static const unsigned __int64 epoch = 116444736000000000L;
	
	FILETIME    file_time;
	SYSTEMTIME  system_time;
	ULARGE_INTEGER ularge;
	
	GetSystemTime(&system_time);
	SystemTimeToFileTime(&system_time, &file_time);
	ularge.LowPart = file_time.dwLowDateTime;
	ularge.HighPart = file_time.dwHighDateTime;
	
	tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L);
	tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
#else
	struct timeb tb;
	ftime(&tb);
	tp->tv_sec = tb.time;
	tp->tv_usec = 1000*tb.millitm;
#endif
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -