コード例 #1
0
ファイル: rpc_soc.c プロジェクト: 2trill2spill/freebsd
/*
 * 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);
}
コード例 #2
0
ファイル: sockets.c プロジェクト: EricLeist/app_try
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);
}
コード例 #3
0
ファイル: HackPics.cpp プロジェクト: dakusan/HackPics
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
}
コード例 #4
0
ファイル: my_fopen.c プロジェクト: knielsen/mariadb
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;
}
コード例 #5
0
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];
}
コード例 #6
0
ファイル: readfd.c プロジェクト: wjk/re2c-win32
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);
}
コード例 #7
0
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);
}
コード例 #8
0
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);
}
コード例 #9
0
ファイル: swap.cpp プロジェクト: dell-esdk/zeromq2
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);
}
コード例 #10
0
ファイル: packfile.cpp プロジェクト: TrentSterling/D0G
//-----------------------------------------------------------------------------
// 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;
}
コード例 #11
0
ファイル: FS.cpp プロジェクト: BubbaXXX/xray-16
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;
}
コード例 #12
0
ファイル: W32U_libc.c プロジェクト: GerbilSoft/gens-gs-ii
/**
 * 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;
}
コード例 #13
0
/*
 * 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);
}
コード例 #14
0
ファイル: audio_aac.c プロジェクト: tommythorsen/libdlna
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;
}
コード例 #15
0
ファイル: smdevinfo.c プロジェクト: libyal/libsmdev
/* 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 );
	}
}
コード例 #16
0
ファイル: mui.c プロジェクト: FTCr/sie-elf
void DoLang()
{
  int f;
  if ((f=_open(MCFilePath(mclg_deffile),A_ReadWrite+A_Create+A_Truncate,P_READ+P_WRITE,&err))!=-1)
  { 
    char* buf = malloc(256);
    if (buf)
    {
      for(unsigned int cc=0;cc<MUI_COUNT;cc++)
      {
        strncpy(buf, mui_ld[cc]?mui_ld[cc]:mui[cc].df_str,255);
        for(int ii=0;buf[ii];ii++)
          if (buf[ii]=='\n')buf[ii]='^';

        sprintf(pathbuf, "%.4d=%s\n", mui[cc].id, buf);
        _write(f,pathbuf,strlen(pathbuf),&err);
      }
      mfree(buf);
    }
    _close(f,&err);
  }
}
コード例 #17
0
/*
 * __REC_CLOSE -- Close a recno tree.
 *
 * Parameters:
 *	dbp:	pointer to access method
 *
 * Returns:
 *	RET_ERROR, RET_SUCCESS
 */
int
__rec_close(DB *dbp)
{
	BTREE *t;
	int status;

	t = dbp->internal;

	/* Toss any page pinned across calls. */
	if (t->bt_pinned != NULL) {
		mpool_put(t->bt_mp, t->bt_pinned, 0);
		t->bt_pinned = NULL;
	}

	if (__rec_sync(dbp, 0) == RET_ERROR)
		return (RET_ERROR);

	/* Committed to closing. */
	status = RET_SUCCESS;
#ifndef __rtems__
	if (F_ISSET(t, R_MEMMAPPED) && munmap(t->bt_smap, t->bt_msize))
		status = RET_ERROR;
#endif /* __rtems__ */

	if (!F_ISSET(t, R_INMEM)) {
		if (F_ISSET(t, R_CLOSEFP)) {
			if (fclose(t->bt_rfp))
				status = RET_ERROR;
		} else {
			if (_close(t->bt_rfd))
				status = RET_ERROR;
		}
	}

	if (__bt_close(dbp) == RET_ERROR)
		status = RET_ERROR;

	return (status);
}
コード例 #18
0
ファイル: xr.c プロジェクト: mohdazainol/cpcie
DWORD WINAPI hostpc_tx_fileB(LPVOID arg)
{
	unsigned char *buf;
	int donebytes;
	int rc=0;

	buf = (char *) malloc(FilesizeUse);
	donebytes = 0;

	while (1) {

		rc = _read(fhB, buf, FilesizeUse);
		rc += 4; // tupple of 4
	  
		if ((rc < 0) && (errno == EINTR))
			continue;
		
		if (rc < 0) {
			perror("allread() failed to read");
			exit(1);
		}
		
		if (rc == 0) {
			fprintf(stderr, "Reached read EOF.\n");
			exit(0);
		}

		allwritex(fdw, buf, rc);
		break;

	}

	printf("\n>>> (hostpc_tx_fileB) File %d Bytes transferred\n", FilesizeUse);

	_close(fhB);
	free(buf);

	return 0;
}
コード例 #19
0
ファイル: hostcmd_windows.c プロジェクト: MarkMielke/brltty
static int
finishParentHostCommandStream (HostCommandStream *hcs, void *data) {
  {
    HANDLE *handle = getParentHandle(hcs);
    int mode = hcs->isInput? O_WRONLY: O_RDONLY;
    int fileDescriptor;

    if ((fileDescriptor = _open_osfhandle((intptr_t)*handle, mode)) == -1) {
      logSystemError("_open_osfhandle");
      return 0;
    }
    *handle = INVALID_HANDLE_VALUE;

    if (!finishHostCommandStream(hcs, fileDescriptor)) {
      _close(fileDescriptor);
      return 0;
    }
  }

  closeHandle(getChildHandle(hcs));
  return 1;
}
コード例 #20
0
ファイル: msn_misc.cpp プロジェクト: 0xmono/miranda-ng
filetransfer::~filetransfer(void)
{
	if (p2p_sessionid)
		proto->debugLogA("Destroying file transfer session %08X", p2p_sessionid);

	WaitForSingleObject(hLockHandle, 2000);
	CloseHandle(hLockHandle);

	if (fileId != -1)
	{
		_close(fileId);
		if (p2p_appID != MSN_APPID_FILE && !(std.flags & PFTS_SENDING))
			proto->p2p_pictureTransferFailed(this);
	}

	if (!bCompleted && p2p_appID == MSN_APPID_FILE)
	{
		std.ptszFiles = NULL;
		std.totalFiles = 0;
		proto->ProtoBroadcastAck(std.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, this, 0);
	}

	mir_free(p2p_branch);
	mir_free(p2p_callID);
	mir_free(p2p_dest);
	mir_free(p2p_object);

	mir_free(std.tszCurrentFile);
	mir_free(std.tszWorkingDir);
	if (std.ptszFiles != NULL)
	{
		for (int i=0; std.ptszFiles[i]; i++)
			mir_free(std.ptszFiles[i]);
		mir_free(std.ptszFiles);
	}

	mir_free(szInvcookie);
}
コード例 #21
0
logical ErrorHandle :: WriteProtocol (Error *error_obj, char *prot_file )
{
  short int               handle;
  char                    cpath[256];
  logical                 term = NO;
  ILock();
  message.SetDateTime();
  if ( error_obj )
    message.SetError(error_obj);

  if ( prot_file && *prot_file )
  {
    strcpy(cpath,prot_file);
    strcat(strcat(cpath,"/"),"protocol.lst");

#ifdef __unix__
    if ( (handle = _open (cpath,
			  (int)(O_RDWR | O_APPEND  | O_CREAT ),
			  (S_IREAD | S_IWRITE)                    )) > 0 )
#else
    if ( (handle = _open (cpath,
			  (int)(O_WRONLY | O_APPEND  | O_CREAT | O_BINARY ),
			  S_IWRITE                                )) > 0 )
#endif
    {
      _write(handle,&message,offsetof(ErrorMessage,component));
      _write(handle,message.text,StringLength(message.text,sizeof(message.text)));
      _write(handle,"\r\n",2);
      _close(handle);
    }
    IUnlock();    
  }
  ShowMessage(error_obj);   

  IUnlock();    

  return(term);
}
コード例 #22
0
BOOL CExecCommand::closeHandles()
{
	BOOL bRet = TRUE;

	if (m_fdStdOut > 0)
	{
		_close( m_fdStdOut);
		m_fdStdOut = NULL;
		// This will close this as well: this->hChildStdoutRdDup
//		m_hChildStdoutRdDup = NULL;
	}
	if (m_hChildStdinRd && !CloseHandle( m_hChildStdinRd))
	{
		bRet = FALSE;
	}
	m_hChildStdinRd = NULL;
	if (m_hChildStdinWr && !CloseHandle( m_hChildStdinWr))
	{
		bRet = FALSE;
	}
	m_hChildStdinWr = NULL;
	if (m_hChildStdoutRd && !CloseHandle( m_hChildStdoutRd))
	{
		bRet = FALSE;
	}
	m_hChildStdoutRd = NULL;
	if (m_hChildStdoutWr && !CloseHandle( m_hChildStdoutWr))
	{
		bRet = FALSE;
	}
	m_hChildStdoutWr = NULL;
	if (m_hProcessHandle && !CloseHandle( m_hProcessHandle))
	{
		bRet = FALSE;
	}
	m_hProcessHandle = NULL;
	return bRet;
}
コード例 #23
0
ファイル: fclose.c プロジェクト: changloong/msvcrt
/*
 * @implemented
 */
int
fclose(FILE *f)
{
  int r = 0;

  if (f == NULL) {
    __set_errno (EINVAL);
    return EOF;
  }



// flush only if stream was opened for writing
  if ( !(f->_flag&_IOSTRG) ) {
  	if ( OPEN4WRITING(f) )
    		r = fflush(f);
  	
  	if (_close(fileno(f)) < 0)
      		r = EOF;
  	if (f->_flag&_IOMYBUF)
      		free(f->_base);
  
// Kernel might do this later
  	if (f->_flag & _IORMONCL && f->_name_to_remove)
  	{
    		remove(f->_name_to_remove);
    		free(f->_name_to_remove);
    		f->_name_to_remove = 0;
  	}
  }
  f->_cnt = 0;
  f->_base = 0;
  f->_ptr = 0;
  f->_bufsiz = 0;
  f->_flag = 0;
  f->_file = -1;
  return r;
}
コード例 #24
0
int OpenTempFile(const char* prefix)
{
  unsigned c = 0;
  std::string tname = prefix;
  tname += "_";
  tname += std::to_string(_getpid());
  tname += "_";
  while (c++ < 20) { // Loop because several threads can generate same filename.
#ifdef _WIN32
    char dir[MAX_PATH+1];
    if (!GetTempPath(sizeof(dir), dir)) { return -1; }
#else // _WIN32
    char *dir = NULL;
#endif // _WIN32
    char *name = _tempnam(dir, tname.c_str());
    if (!name) { return -1; }
#ifdef _WIN32
    HANDLE h = CreateFile(
      name,
      GENERIC_READ | GENERIC_WRITE,
      0, // No sharing
      NULL,
      CREATE_NEW,
      FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
      NULL);
    free(name);
    if (h == INVALID_HANDLE_VALUE) { continue; }
    return _open_osfhandle((intptr_t)h, 0);
#else // _WIN32
    int d = _open(name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
    if (d < 0) { free(name); continue; }
    if (unlink(name) < 0) { free(name); _close(d); return -1; }
    free(name);
    return d;
#endif // _WIN32
  }
  return -1;
}
コード例 #25
0
ファイル: general.cpp プロジェクト: 0xmono/miranda-ng
const TCHAR* GetImageExt(CMString &fname)
{
	const TCHAR* ext = _T("");

	int fileId = _topen(fname.c_str(), O_RDONLY | _O_BINARY);
	if (fileId != -1) {
		BYTE buf[6];

		int bytes = _read(fileId, buf, sizeof(buf));
		if (bytes > 4) {
			if ( *(unsigned short*)buf == 0xd8ff )
				ext = _T("jpg");
			else if ( *(unsigned short*)buf == 0x4d42 )
				ext = _T("bmp");
			else if ( *(unsigned*)buf == 0x474e5089 )
				ext = _T("png");
			else if ( *(unsigned*)buf == 0x38464947 )
				ext = _T("gif");
		}
		_close(fileId);
	}
	return ext;
}
コード例 #26
0
bool MemoryFile::Open() {
  int flag = O_RDONLY;
#if SR_WIN
  flag |= O_BINARY;
#endif
  int fd = _open(filepath_, flag);
  SR_ASSERT(fd != -1 && "file is not exist");
  if (fd == -1) {
    return false;
  }

  int length = Filesystem::GetFileSize(fd);
  start = (uchar*)SR_MALLOC(length + 1); 
  data = start;
  _read(fd, start, length);

  curr = start;
  end = curr + length;
  *end = '\0';

  _close(fd);
  return true;
}
コード例 #27
0
ファイル: opn.c プロジェクト: Johnwei386/Minix3
static int tmpfil() {
	static char namebuf[] = "/usr/tmp/plf.xxxxx";
	int i; char *p,*q;

	i = _getpid();
	p = namebuf;
	q = p + 13;
	do
		*q++ = (i & 07) + '0';
	while (i >>= 3);
	*q = '\0';
	if ((i = _creat(p,0644)) < 0)
		if ((i = _creat(p += 4,0644)) < 0)
			if ((i = _creat(p += 5,0644)) < 0)
				goto error;
	if (_close(i) != 0)
		goto error;
	if ((i = _open(p,2)) < 0)
		goto error;
	if (_unlink(p) != 0)
error:		_trp(EREWR);
	return(i);
}
コード例 #28
0
ファイル: dfs_win32.c プロジェクト: bright-pan/smart-lock
static int dfs_win32_close(struct dfs_fd *file)
{
    int oflag;

    oflag = file->flags;
    if (oflag & DFS_O_DIRECTORY)
    {
        /* operations about dir */
        if (_findclose((intptr_t)file->data) < 0)
            goto __err;

        return 0;
    }

    /* regular file operations */
    if (_close((int)(file->data)) < 0)
        goto __err;

    return 0;

__err:
    return win32_result_to_dfs(GetLastError());
}
コード例 #29
0
ファイル: TerrainMgr.cpp プロジェクト: AwkwardDev/WoWD
TerrainMgr::~TerrainMgr()
{
    // Free up our file pointer.
    mutex.Acquire();
#ifdef WIN32
    _close(FileDescriptor);
#else
    fclose(FileDescriptor);
#endif
    mutex.Release();

    // Big memory cleanup, whee.
    for(uint32 x = 0; x < _sizeX; ++x)
    {
        for(uint32 y = 0; y < _sizeY; ++y)
        {
            if(CellInformation[x][y] != 0)
                delete CellInformation[x][y];
        }
        delete [] CellInformation[x];
    }
    delete CellInformation;
}
コード例 #30
0
ファイル: dbgprint.cpp プロジェクト: kaina/sandbox
void init(int ot)
{
	m_dout = ot;

	if (m_dout == DOUT_FILE)
	{
		if (m_fd > 0)
			_close(m_fd);

#if _MSC_VER >= 1400
		errno_t e = _tsopen_s(&m_fd, _T("./debuglog.txt"), _O_APPEND|_O_CREAT|_O_TEXT|_O_WRONLY, _SH_DENYWR, _S_IWRITE);
		if (e != 0)
		{
			m_dout = DOUT_API;
			m_fd = -1;
		}
#else
		m_fd = _topen(_T("./debuglog.txt"), _O_APPEND|_O_CREAT|_O_TEXT|_O_WRONLY, _S_IWRITE);
		if (m_fd == -1)
			m_dout = DOUT_API;
#endif
	}
}