当前位置: 首页>>代码示例>>C++>>正文


C++ _close函数代码示例

本文整理汇总了C++中_close函数的典型用法代码示例。如果您正苦于以下问题:C++ _close函数的具体用法?C++ _close怎么用?C++ _close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: clntunix_create

/*
 * Create a client handle for a unix connection. Obsoleted by clnt_vc_create()
 */
CLIENT *
clntunix_create(struct sockaddr_un *raddr, u_long prog, u_long vers, int *sockp,
    u_int sendsz, u_int recvsz)
{
	struct netbuf *svcaddr;
	CLIENT *cl;
	int len;

	cl = NULL;
	svcaddr = NULL;
	if ((raddr->sun_len == 0) ||
	   ((svcaddr = malloc(sizeof(struct netbuf))) == NULL ) ||
	   ((svcaddr->buf = malloc(sizeof(struct sockaddr_un))) == NULL)) {
		free(svcaddr);
		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
		rpc_createerr.cf_error.re_errno = errno;
		return(cl);
	}
	if (*sockp < 0) {
		*sockp = _socket(AF_LOCAL, SOCK_STREAM, 0);
		len = raddr->sun_len = SUN_LEN(raddr);
		if ((*sockp < 0) || (_connect(*sockp,
		    (struct sockaddr *)raddr, len) < 0)) {
			rpc_createerr.cf_stat = RPC_SYSTEMERROR;
			rpc_createerr.cf_error.re_errno = errno;
			if (*sockp != -1)
				(void)_close(*sockp);
			goto done;
		}
	}
	svcaddr->buf = raddr;
	svcaddr->len = raddr->sun_len;
	svcaddr->maxlen = sizeof (struct sockaddr_un);
	cl = clnt_vc_create(*sockp, svcaddr, prog,
	    vers, sendsz, recvsz);
done:
	free(svcaddr->buf);
	free(svcaddr);
	return(cl);
}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:43,代码来源:rpc_soc.c

示例2: close_fd_maybe_socket

static int
close_fd_maybe_socket (const struct fd_hook *remaining_list,
                       gl_close_fn primary,
                       int fd)
{
  /* Note about multithread-safety: There is a race condition where, between
     our calls to closesocket() and the primary close(), some other thread
     could make system calls that allocate precisely the same HANDLE value
     as sock; then the primary close() would call CloseHandle() on it.  */
  SOCKET sock;
  WSANETWORKEVENTS ev;

  /* Test whether fd refers to a socket.  */
  sock = FD_TO_SOCKET (fd);
  ev.lNetworkEvents = 0xDEADBEEF;
  WSAEnumNetworkEvents (sock, NULL, &ev);
  if (ev.lNetworkEvents != 0xDEADBEEF)
    {
      /* fd refers to a socket.  */
      /* FIXME: other applications, like squid, use an undocumented
         _free_osfhnd free function.  But this is not enough: The 'osfile'
         flags for fd also needs to be cleared, but it is hard to access it.
         Instead, here we just close twice the file descriptor.  */
      if (closesocket (sock))
        {
          set_winsock_errno ();
          return -1;
        }
      else
        {
          /* This call frees the file descriptor and does a
             CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails.  */
          _close (fd);
          return 0;
        }
    }
  else
    /* Some other type of file descriptor.  */
    return execute_close_hooks (remaining_list, primary, fd);
}
开发者ID:EricLeist,项目名称:app_try,代码行数:40,代码来源:sockets.c

示例3: LoadRawFromDataFile

DWORD LoadRawFromDataFile(CompressedFile *TheFileNode, BYTE *UncompressedBuffer, int FileNum, BYTE *CompressedBuffer)
{
	//Load up temporary data if not passed in
	bool TempBuffer=false, TempFile=false;
	const int TenMegs=10*1024*1024;
	if(!CompressedBuffer)
	{
		TempBuffer=true;
		CompressedBuffer=new BYTE[TenMegs];
	}
	if(!FileNum)
	{
		TempFile=true;
		FileNum=_open(DataFileName, _O_RDONLY|_O_BINARY);
	}

	//Read in compressed data
	_lseek(FileNum, TheFileNode->FileStart, SEEK_SET);
	_read(FileNum, CompressedBuffer, TheFileNode->FileSize);

	//Close temporary file
	if(TempFile)
		_close(FileNum);

	//Uncompress data
	z_stream TheStream={CompressedBuffer, TheFileNode->FileSize, 0, UncompressedBuffer, TenMegs, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL};
	if(inflateInit2_(&TheStream, -MAX_WBITS, (const char*)"1.2.1", sizeof(TheStream)) || inflate(&TheStream, Z_FINISH)!=1)
	{
		if(CompressedBuffer)
			delete[] CompressedBuffer;
		return 0;
	}
	inflateEnd(&TheStream);

	//Delete temporary buffer
	if(TempBuffer)
		delete[] CompressedBuffer;

	return TheStream.total_out; //Return uncompressed data size
}
开发者ID:dakusan,项目名称:HackPics,代码行数:40,代码来源:HackPics.cpp

示例4: _fileno

static FILE *my_win_freopen(const char *path, const char *mode, FILE *stream)
{
  int handle_fd, fd= _fileno(stream);
  HANDLE osfh;

  DBUG_ASSERT(path && stream);

  /* Services don't have stdout/stderr on Windows, so _fileno returns -1. */
  if (fd < 0)
  {
    if (!freopen(path, mode, stream))
      return NULL;

    fd= _fileno(stream);
  }

  if ((osfh= CreateFile(path, GENERIC_READ | GENERIC_WRITE,
                        FILE_SHARE_READ | FILE_SHARE_WRITE |
                        FILE_SHARE_DELETE, NULL,
                        OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,
                        NULL)) == INVALID_HANDLE_VALUE)
    return NULL;

  if ((handle_fd= _open_osfhandle((intptr_t)osfh,
                                  _O_APPEND | _O_TEXT)) == -1)
  {
    CloseHandle(osfh);
    return NULL;
  }

  if (_dup2(handle_fd, fd) < 0)
  {
    CloseHandle(osfh);
    return NULL;
  }

  _close(handle_fd);

  return stream;
}
开发者ID:knielsen,项目名称:mariadb,代码行数:40,代码来源:my_fopen.c

示例5: mir_free

const char *TemplateHTMLBuilder::getFlashAvatar(const TCHAR *file, int index)
{
	if (time(NULL) - flashAvatarsTime[index] > 600 || flashAvatars[index] == NULL) {
		if (flashAvatars[index] != NULL) {
			mir_free(flashAvatars[index]);
			flashAvatars[index] = NULL;
		}
		flashAvatarsTime[index] = time(NULL);
		int src = _topen(file, _O_BINARY | _O_RDONLY);
		if (src != -1) {
			char pBuf[2048];
			char *urlBuf;
			_read(src, pBuf, 2048);
			_close(src);
			urlBuf = strstr(pBuf, "<URL>");
			if(urlBuf) {
				flashAvatars[index] = mir_strdup(strtok(urlBuf + 5, "<\t\n\r"));
			}
		}
	}
	return flashAvatars[index];
}
开发者ID:0xmono,项目名称:miranda-ng,代码行数:22,代码来源:TemplateHTMLBuilder.cpp

示例6: readfd_open

scanstate* readfd_open(const char *path, size_t bufsiz)
{
    scanstate *ss;
    int fd;

	// _open() is marked as deprecated due to security concerns; however,
	// using the suggested function, _sopen_s(), is overkill for my needs here.
	// Thus, I suppress the deprecation warning for this statement only.
#pragma warning(suppress: 4996)
    fd = _open(path, O_RDONLY);
    if(fd < 0) {
        return NULL;
    }

    ss = dynscan_create(bufsiz);
    if(!ss) {
        _close(fd);
        return NULL;
    }

    return readfd_attach(ss, fd);
}
开发者ID:wjk,项目名称:re2c-win32,代码行数:22,代码来源:readfd.c

示例7: _mongoc_stream_file_close

static int
_mongoc_stream_file_close (mongoc_stream_t *stream)
{
   mongoc_stream_file_t *file = (mongoc_stream_file_t *)stream;
   int ret;

   ENTRY;

   BSON_ASSERT (file);

   if (file->fd != -1) {
#ifdef _WIN32
      ret = _close (file->fd);
#else
      ret = close (file->fd);
#endif
      file->fd = -1;
      RETURN (ret);
   }

   RETURN (0);
}
开发者ID:Machyne,项目名称:mongo-c-driver,代码行数:22,代码来源:mongoc-stream-file.c

示例8: _mongoc_stream_file_close

static int
_mongoc_stream_file_close (mongoc_stream_t *stream)
{
   mongoc_stream_file_t *file = (mongoc_stream_file_t *)stream;
   int ret;

   ENTRY;

   bson_return_val_if_fail (file, -1);

   if (file->fd != -1) {
#ifdef _WIN32
      ret = _close (file->fd);
#else
      ret = close (file->fd);
#endif
      file->fd = -1;
      RETURN (ret);
   }

   RETURN (0);
}
开发者ID:aherlihy,项目名称:mongo-c-driver,代码行数:22,代码来源:mongoc-stream-file.c

示例9: _close

zmq::swap_t::~swap_t ()
{
    delete [] buf1;
    delete [] buf2;

    if (fd == -1)
        return;

#ifdef ZMQ_HAVE_WINDOWS
    int rc = _close (fd);
#else
    int rc = close (fd);
#endif
    errno_assert (rc == 0);

#ifdef ZMQ_HAVE_WINDOWS
    rc = _unlink (filename.c_str ());
#else
    rc = unlink (filename.c_str ());
#endif
    errno_assert (rc == 0);
}
开发者ID:dell-esdk,项目名称:zeromq2,代码行数:22,代码来源:swap.cpp

示例10: Pack_AppendFile

//-----------------------------------------------------------------------------
// Purpose: Appends a single file to the pak file
//-----------------------------------------------------------------------------
bool Pack_AppendFile(const char *pakfile, const char *file)
{
	if (!Pack_StartAppendingFile(pakfile, file))
		return false;

	assert(Pack_Validate(pakfile));

	// read in the file
	int hFile = _open(file, _O_RDONLY | _O_BINARY);
	if (hFile == -1)
	{
		printf("Couldn't find resource file '%s'\n", file);
		return false;
	}

	// start copying
	char *tempBuf = (char *)malloc(1024 * 1024);
	int64 iFileRemaining = _filelengthi64(hFile);
	while (iFileRemaining > 0)
	{
		int bytesToCopy = (int)min(iFileRemaining, (1024 * 1024));
		iFileRemaining -= bytesToCopy;

		// read
		int bytes = _read(hFile, tempBuf, bytesToCopy);
		bytes;
		assert(bytes == bytesToCopy);

		Pack_AppendChunkToFile(tempBuf, bytesToCopy);
	}

	free(tempBuf);
	_close(hFile);

	Pack_FinishAppendingFile();

	assert(Pack_Validate(pakfile));
	return true;
}
开发者ID:TrentSterling,项目名称:D0G,代码行数:42,代码来源:packfile.cpp

示例11: FileDecompress

void* FileDecompress(const char* fn, const char* sign, u32* size)
{
    MARK M, F;
    mk_mark(M, sign);

    int H = open(fn, O_BINARY | O_RDONLY);
    R_ASSERT2(H > 0, fn);
    _read(H, &F, 8);
    if (strncmp(M, F, 8) != 0)
    {
        F[8] = 0;
        Msg("FATAL: signatures doesn't match, file(%s) / requested(%s)", F, sign);
    }
    R_ASSERT(strncmp(M, F, 8) == 0);

    void* ptr = 0;
    u32 SZ;
    SZ = _readLZ(H, ptr, filelength(H) - 8);
    _close(H);
    if (size) *size = SZ;
    return ptr;
}
开发者ID:BubbaXXX,项目名称:xray-16,代码行数:22,代码来源:FS.cpp

示例12: W32U_wstati64

/**
 * Internal implementation of _wstati64().
 * MSVCRT's _wstati64() fails if the filename contains '?' or '*',
 * which breaks long filename support, e.g. \\?\.
 * @param pathname Pathname.
 * @param buf Stat buffer.
 * @return 0 on success; -1 on error.
 */
static int W32U_wstati64(const wchar_t *pathname, struct _stati64 *buffer)
{
	int fd, ret;

	if (!pathname || !buffer) {
		errno = EINVAL;
		return -1;
	}

	// _fstati64() can obtain all the information.
	// We just need to open the file first.
	// FIXME: Use FindFirstFileW() instead to avoid having to open the file?
	fd = _wopen(pathname, _O_RDONLY, 0);
	if (fd < 0) {
		// Error opening the file.
		return fd;
	}

	ret = _fstati64(fd, buffer);
	_close(fd);
	return ret;
}
开发者ID:GerbilSoft,项目名称:gens-gs-ii,代码行数:30,代码来源:W32U_libc.c

示例13: svc_com_create

/*
 * A common server create routine
 */
static SVCXPRT *
svc_com_create(int fd, u_int sendsize, u_int recvsize, char *netid)
{
	struct netconfig *nconf;
	SVCXPRT *svc;
	int madefd = FALSE;
	int port;
	struct sockaddr_in sin;

	if ((nconf = __rpc_getconfip(netid)) == NULL) {
		(void) syslog(LOG_ERR, "Could not get %s transport", netid);
		return (NULL);
	}
	if (fd == RPC_ANYSOCK) {
		fd = __rpc_nconf2fd(nconf);
		if (fd == -1) {
			(void) freenetconfigent(nconf);
			(void) syslog(LOG_ERR,
			"svc%s_create: could not open connection", netid);
			return (NULL);
		}
		madefd = TRUE;
	}

	memset(&sin, 0, sizeof sin);
	sin.sin_family = AF_INET;
	bindresvport(fd, &sin);
	_listen(fd, SOMAXCONN);
	svc = svc_tli_create(fd, nconf, NULL, sendsize, recvsize);
	(void) freenetconfigent(nconf);
	if (svc == NULL) {
		if (madefd)
			(void)_close(fd);
		return (NULL);
	}
	port = (((struct sockaddr_in *)svc->xp_ltaddr.buf)->sin_port);
	svc->xp_port = ntohs(port);
	return (svc);
}
开发者ID:cemeyer,项目名称:freebsd-base-graphics,代码行数:42,代码来源:rpc_soc.c

示例14: aac_adts_object_type_get

static aac_object_type_t
aac_adts_object_type_get (AVFormatContext *ctx)
{
    int fd;
    unsigned char buf[4];
    uint8_t t = AAC_INVALID;
    ssize_t count;

    if (!ctx)
        return t;

    fd = _open (ctx->filename, O_RDONLY);
    count = _read (fd, buf, sizeof (buf) - 1);
    t = (buf[2] & 0xC0) >> 6;
    _close (fd);

#ifdef HAVE_DEBUG
    fprintf (stderr, "AAC Object Type: %d\n", t);
#endif /* HAVE_DEBUG */

    return t;
}
开发者ID:tommythorsen,项目名称:libdlna,代码行数:22,代码来源:audio_aac.c

示例15: smdevinfo_signal_handler

/* Signal handler for smdevinfo
 */
void smdevinfo_signal_handler(
      smdevtools_signal_t signal SMDEVTOOLS_ATTRIBUTE_UNUSED )
{
	libcerror_error_t *error = NULL;
	static char *function    = "smdevinfo_signal_handler";

	SMDEVTOOLS_UNREFERENCED_PARAMETER( signal )

	smdevinfo_abort = 1;

	if( ( smdevinfo_info_handle != NULL )
	 && ( info_handle_signal_abort(
	       smdevinfo_info_handle,
	       &error ) != 1 ) )
	{
		libcnotify_printf(
		 "%s: unable to signal info handle to abort.\n",
		 function );

		libcnotify_print_error_backtrace(
		 error );
		libcerror_error_free(
		 &error );
	}
	/* Force stdin to close otherwise any function reading it will remain blocked
	 */
#if defined( WINAPI ) && !defined( __CYGWIN__ )
	if( _close(
	     0 ) != 0 )
#else
	if( close(
	     0 ) != 0 )
#endif
	{
		libcnotify_printf(
		 "%s: unable to close stdin.\n",
		 function );
	}
}
开发者ID:libyal,项目名称:libsmdev,代码行数:41,代码来源:smdevinfo.c


注:本文中的_close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。