コード例 #1
0
ファイル: MainDlg.cpp プロジェクト: 623442733/CEFBrowser-1
LRESULT CMainDlg::OnDownload(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
	WCHAR wcPath[MAX_PATH] = { 0 }, wcData[MAX_PATH] = { 0 };
	int itype = lParam;
	if (itype)
	{
		//下载文件
		if (m_hDownload != NULL)
		{
			::PostMessage(m_hDownload, WM_DOWNLOAD, wParam, lParam);
		}
	}
	else
	{
		std::string *precv = (std::string *)wParam;
		std::string str;
		int is = precv->find_last_of('/');
		str.append(*precv, is + 1, precv->size());
		c2w(wcData, MAX_PATH, str.c_str());
		CFileDialog savedlg(FALSE, NULL, wcData, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, L"文件 (*.jpg; *.bmp; *.png)", m_hWnd);
		if (IDOK == savedlg.DoModal(*this))
		{
			memset(wcData, 0, MAX_PATH);
			c2w(wcData, MAX_PATH, precv->c_str());
			wcscpy(wcPath, savedlg.m_szFileName);
			URLDownloadToFile(0, wcData, wcPath, 0, NULL);
		}
		delete precv;
	}
	return 0;
}
コード例 #2
0
ファイル: stdafx.cpp プロジェクト: 623442733/CEFBrowser-1
bool readINI(char* option, char* key, int& value, char* path)
{
	WCHAR wcOption[MAX_PATH] = { 0 }, wcKey[MAX_PATH] = { 0 }, wcPath[MAX_PATH] = { 0 };
	c2w(wcOption, MAX_PATH, option);
	c2w(wcKey, MAX_PATH, key);
	c2w(wcPath, MAX_PATH, path);
	value = GetPrivateProfileInt(wcOption, wcKey, 0, wcPath);
	return true;
}
コード例 #3
0
ファイル: stdafx.cpp プロジェクト: 623442733/CEFBrowser-1
bool readINI(char* option, char* key, char* value, char* path)
{
	WCHAR wcOption[MAX_PATH] = { 0 }, wcKey[MAX_PATH] = { 0 }, wcValue[MAX_PATH] = { 0 }, wcPath[MAX_PATH] = { 0 };
	c2w(wcOption, MAX_PATH, option);
	c2w(wcKey, MAX_PATH, key);
	c2w(wcPath, MAX_PATH, path);
	bool rs = GetPrivateProfileString(wcOption, wcKey, wcValue, wcValue, MAX_PATH, wcPath);
	strcpy(value, w2c(wcValue));
	return rs;
}
コード例 #4
0
ファイル: stdafx.cpp プロジェクト: 623442733/CEFBrowser-1
bool readINI(char* option, char* key, int& value)
{
	WCHAR czPath[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, czPath);
	wcscat(czPath, L"\\config.ini");

	WCHAR wcOption[MAX_PATH] = { 0 }, wcKey[MAX_PATH] = { 0 };
	c2w(wcOption, MAX_PATH, option);
	c2w(wcKey, MAX_PATH, key);
	value = GetPrivateProfileInt(wcOption, wcKey, 0, czPath);
	return true;
}
コード例 #5
0
ファイル: stdafx.cpp プロジェクト: 623442733/CEFBrowser-1
bool writeINI(char* option, char* key, int value)
{
	WCHAR czPath[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, czPath);
	wcscat(czPath, L"\\config.ini");

	WCHAR wcOption[MAX_PATH] = { 0 }, wcKey[MAX_PATH] = { 0 }, wcValue[MAX_PATH] = { 0 };
	c2w(wcOption, MAX_PATH, option);
	c2w(wcKey, MAX_PATH, key);
	swprintf(wcValue, L"%d", value);
	bool rs = ::WritePrivateProfileString(wcOption, wcKey, wcValue, czPath);
	return rs;
}
コード例 #6
0
ファイル: stdafx.cpp プロジェクト: 623442733/CEFBrowser-1
bool readINI(char* option, char* key, char* value)
{
	WCHAR czPath[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, czPath);
	wcscat(czPath, L"\\config.ini");

	WCHAR wcOption[MAX_PATH] = { 0 }, wcKey[MAX_PATH] = { 0 }, wcValue[MAX_PATH] = { 0 };
	c2w(wcOption, MAX_PATH, option);
	c2w(wcKey, MAX_PATH, key);
	bool rs = GetPrivateProfileString(wcOption, wcKey, wcValue, wcValue, MAX_PATH, czPath);
	strcpy(value, w2c(wcValue));
	return rs;
}
コード例 #7
0
ファイル: MainDlg.cpp プロジェクト: 623442733/CEFBrowser-1
void CMainDlg::ShowLog(std::string strUrl, int idty)
{
	std::string str;
	WCHAR wc[MAX_PATH], wlog[MAX_PATH];
	if (strUrl.size() >= 100)
	{
		str.append(strUrl.c_str(), 100);
	}
	else
	{
		str = strUrl;
	}
	c2w(wc, MAX_PATH, str.c_str());
	switch (idty)
	{
	case 1:
		swprintf(wlog, L"正在连接网页:%s 中", wc);
		break;
	case 2:
		swprintf(wlog, L"打开网页:%s 成功", wc);
		break;
	case 3:
		swprintf(wlog, L"打开网页:%s 失败", wc);
		break;
	default:
		break;
	}
}
コード例 #8
0
ファイル: perspective.cpp プロジェクト: Drooids/pbrt-v3
void PerspectiveCamera::Pdf_We(const Ray &ray, Float *pdfPos,
                               Float *pdfDir) const {
    // Interpolate camera matrix and fail if $\w{}$ is not forward-facing
    Transform c2w;
    CameraToWorld.Interpolate(ray.time, &c2w);
    Float cosTheta = Dot(ray.d, c2w(Vector3f(0, 0, 1)));
    if (cosTheta <= 0) {
        *pdfPos = *pdfDir = 0;
        return;
    }

    // Map ray $(\p{}, \w{})$ onto the raster grid
    Point3f pFocus = ray((lensRadius > 0 ? focalDistance : 1) / cosTheta);
    Point3f pRaster = Inverse(RasterToCamera)(Inverse(c2w)(pFocus));

    // Return zero probability for out of bounds points
    Bounds2i sampleBounds = film->GetSampleBounds();
    if (pRaster.x < sampleBounds.pMin.x || pRaster.x >= sampleBounds.pMax.x ||
        pRaster.y < sampleBounds.pMin.y || pRaster.y >= sampleBounds.pMax.y) {
        *pdfPos = *pdfDir = 0;
        return;
    }

    // Compute lens area of perspective camera
    Float lensArea = lensRadius != 0 ? (Pi * lensRadius * lensRadius) : 1;
    *pdfPos = 1 / lensArea;
    *pdfDir = 1 / (A * cosTheta * cosTheta * cosTheta);
}
コード例 #9
0
ファイル: opennurbs_wstring.cpp プロジェクト: ckvk/opennurbs
void ON_wString::SetAt( int i, char c )
{
  if ( i >= 0 && i < Header()->string_length ) {
	  CopyArray();
	  m_s[i] = c2w(c);
  }
}
コード例 #10
0
/**
 * Get 64-bit file size and store it into given 64-bit integer.
 *
 * @param path file path
 * @param pSize pointer to a 64-bit integer to store file size into
 */
void win32_set_filesize64(const char* path, uint64_t *pSize)
{
	int try_no;
	for(try_no = 0; try_no < 2; try_no++) {
		HANDLE hFile;
		DWORD fileSizeLow, fileSizeHigh;

		wchar_t* wpath = c2w(path, try_no);
		if(wpath == NULL) continue;
		hFile = CreateFileW(wpath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		free(wpath);
		if(hFile == INVALID_HANDLE_VALUE) {
			UINT error = GetLastError();
			if(error != ERROR_FILE_NOT_FOUND && error != ERROR_PATH_NOT_FOUND) break;
		} else {
			fileSizeLow = GetFileSize(hFile, &fileSizeHigh);

			/* it is strange but the correct method to check for error */
			if(fileSizeLow == 0xffffffff && GetLastError() != 0) {
				/* printf("error code = %u: %s\n", GetLastError(), filepath); */
			} else {
				*pSize = fileSizeLow + ( (uint64_t)fileSizeHigh << 32 );
			}
			CloseHandle(hFile);
			break;
		}
	}
}
コード例 #11
0
ファイル: perspective.cpp プロジェクト: fseraph/pbrt-v3
Spectrum PerspectiveCamera::We(const Interaction &p0, const Vector3f &w,
                               Point2f *pRasterPtr) const {
    // Interpolate camera matrix and check if _w_ is forward-facing
    Transform c2w;
    CameraToWorld.Interpolate(p0.time, &c2w);
    Float cosTheta = Dot(w, c2w(Vector3f(0, 0, 1)));
    if (cosTheta <= 0) return 0;

    // Map direction _w_ onto the raster grid
    Point3f pFocus = p0.p + w / cosTheta * (lensRadius > 0 ? focalDistance : 1);
    Point3f pRaster = Inverse(RasterToCamera)(Inverse(c2w)(pFocus));

    // Return raster position if requested
    if (pRasterPtr) *pRasterPtr = Point2f(pRaster.x, pRaster.y);

    // Return zero importance for out of bounds points
    Bounds2i sampleBounds = film->GetSampleBounds();
    if (pRaster.x < sampleBounds.pMin.x || pRaster.x >= sampleBounds.pMax.x ||
        pRaster.y < sampleBounds.pMin.y || pRaster.y >= sampleBounds.pMax.y)
        return 0;

    // Compute lens area of perspective camera
    Float lensArea = lensRadius != 0 ? (Pi * lensRadius * lensRadius) : 1;

    // Return importance for point on image plane
    Float cos2Theta = cosTheta * cosTheta;
    return Spectrum(1 / (A * lensArea * cos2Theta * cos2Theta));
}
コード例 #12
0
ファイル: opennurbs_wstring.cpp プロジェクト: ckvk/opennurbs
void ON_wString::AppendToArray( int size, const char* s )
{
  if ( size > 0 && s && s[0] ) {
	  ReserveArray(size + Header()->string_length );
    Header()->string_length += c2w( size, s, Header()->string_capacity-Header()->string_length, &m_s[Header()->string_length] );
    m_s[Header()->string_length] = 0;
  }
}
コード例 #13
0
ファイル: win_utils.c プロジェクト: 0-wiz-0/RHash
/**
 * Open directory iterator for reading the directory content.
 *
 * @param dir_path directory path
 * @return pointer to directory stream. On error, NULL is returned,
 *         and errno is set appropriately.
 */
WIN_DIR* win_opendir(const char* dir_path)
{
	WIN_DIR* d;
	wchar_t* wpath;

	/* append '\*' to the dir_path */
	size_t len = strlen(dir_path);
	char *path = (char*)malloc(len + 3);
	if(!path) return NULL; /* failed, malloc also set errno = ENOMEM */
	strcpy(path, dir_path);
	strcpy(path + len, "\\*");

	d = (WIN_DIR*)malloc(sizeof(WIN_DIR));
	if(!d) {
		free(path);
		return NULL;
	}
	memset(d, 0, sizeof(WIN_DIR));

	wpath = c2w(path, 0);
	d->hFind = (wpath != NULL ?
		FindFirstFileW(wpath, &d->findFileData) : INVALID_HANDLE_VALUE);
	free(wpath);

	if(d->hFind == INVALID_HANDLE_VALUE && GetLastError() != ERROR_ACCESS_DENIED) {
		wpath = c2w(path, 1); /* try to use secondary codepage */
		if(wpath) {
			d->hFind = FindFirstFileW(wpath, &d->findFileData);
			free(wpath);
		}
	}
	free(path);

	if(d->hFind == INVALID_HANDLE_VALUE && GetLastError() == ERROR_ACCESS_DENIED) {
		free(d);
		errno = EACCES;
		return NULL;
	}
	set_errno_from_last_file_error();

	d->state = (d->hFind == INVALID_HANDLE_VALUE ? -1 : 0);
	d->dir.d_name = NULL;
	return d;
}
コード例 #14
0
ファイル: common_func.c プロジェクト: anonymlol/RHash
/**
 * Fill file information in the file_t structure.
 *
 * @param file the file information
 * @param use_lstat nonzero if lstat() shall be used
 * @return 0 on success, -1 on error
 */
int file_stat2(file_t* file, int use_lstat)
{
#ifdef _WIN32
	int i;
	(void)use_lstat; /* ignore on windows */

	file->mtime = 0;
	if (file->wpath) {
		free(file->wpath);
		file->wpath = NULL;
	}

	for (i = 0; i < 2; i++) {
		file->wpath = c2w(file->path, i);
		if (file->wpath == NULL) continue;

		/* return on success */
		if (file_statw(file) == 0) return 0;

		free(file->wpath);
		file->wpath = NULL;
	}
	/* NB: usually errno is set by the rsh_file_statw() call */
	if (!errno) errno = EINVAL;
	return -1;
#else
	struct stat st;
	int res = 0;
	file->mode &= FILE_OPT_DONT_FREE_PATH;

	do {
		if (use_lstat) {
			/* check for symlink */
			if (lstat(file->path, &st) < 0) return -1;
			if (!S_ISLNK(st.st_mode)) break;

			/* it's a symlink */
			file->mode |= FILE_IFLNK;
		}

		res = stat(file->path, &st);
	} while (0);

	file->size  = st.st_size;
	file->mtime = st.st_mtime;

	if (S_ISDIR(st.st_mode)) {
		file->mode |= FILE_IFDIR;
	} else if (S_ISREG(st.st_mode)) {
		/* it's a regular file or a symlink pointing to a regular file */
		file->mode |= FILE_IFREG;
	}

	return res;
#endif /* _WIN32 */
}
コード例 #15
0
/**
 * stat() a file with encoding support.
 *
 * @param path the file path
 * @param buffer pointer to the buffer to store file properties to
 * @return 0 on success, -1 on error
 */
int win_stat(const char* path, struct rsh_stat_struct *buffer)
{
	int i, res = -1;
	for(i = 0; i < 2; i++) {
		wchar_t* wpath = c2w(path, i);
		if(wpath == NULL) continue;
		res = clib_wstat(wpath, buffer);
		free(wpath);
		if(res == 0 || errno != ENOENT) break;
	}
	return res;
}
コード例 #16
0
/**
 * Convert given C-string from encoding specified by
 * command line options to utf8.
 *
 * @param str the string to convert
 * @return converted string on success, NULL on fail
 */
char* win_to_utf8(const char* str)
{
	char* res;
	wchar_t* buf;

	assert((opt.flags & (OPT_UTF8 | OPT_OEM | OPT_ANSI)) != 0);
	if(opt.flags & OPT_UTF8) return rsh_strdup(str);

	if((buf = c2w(str, 0)) == NULL) return NULL;
	res = wchar_to_cstr(buf, CP_UTF8, NULL);
	free(buf);
	return res;
}
コード例 #17
0
//===============================================ShellExicute==========================================================//
bool shellExecute(const char * file, const char *params){

	   wchar_t * Wfile = c2w(file);
	   wchar_t * Wparams = c2w(params);

	   SHELLEXECUTEINFO ShellInfo;        
       memset(&ShellInfo, 0, sizeof(ShellInfo));
       ShellInfo.cbSize = sizeof(ShellInfo);
       ShellInfo.hwnd = NULL;
       ShellInfo.lpVerb = NULL;
       ShellInfo.lpFile = Wfile; // L"VisualSFM.exe"  L前缀将常量char 转化成 wchar
	   ShellInfo.lpParameters = Wparams;
       ShellInfo.nShow = SW_HIDE;
       ShellInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
     
       if( ShellExecuteEx(&ShellInfo)) {
	     WaitForSingleObject(ShellInfo.hProcess,INFINITE);
		 return true;
	   }
	   else{
		   return false;
	   }

}
コード例 #18
0
/**
 * Check if given file can be opened with exclusive write access.
 *
 * @param path path to the file
 * @return 1 if file can be opened, 0 otherwise
 */
int can_open_exclusive(const char* path)
{
	int i, res = 0;
	for(i = 0; i < 2 && res == 0; i++) {
		int fd;
		wchar_t* wpath = c2w(path, i);
		if(wpath == NULL) continue;
		fd = _wsopen(wpath, _O_RDONLY | _O_BINARY, _SH_DENYWR, 0);
		if(fd >= 0) {
			res = 1;
			_close(fd);
		}
		free(wpath);
	}
	return res;
}
コード例 #19
0
ファイル: opennurbs_wstring.cpp プロジェクト: ckvk/opennurbs
void ON_wString::CopyToArray( int size, const char* s )
{
  if ( size > 0 && s && s[0] ) {
	  ReserveArray(size);
    Header()->string_length = c2w( size, s, Header()->string_capacity, m_s );
    m_s[Header()->string_length] = 0;
  }
  else {
    if ( Header()->ref_count > 1 )
      Destroy();
    else {
      Header()->string_length = 0;
      m_s[0] = 0;
    }
  }
}
コード例 #20
0
ファイル: opennurbs_wstring.cpp プロジェクト: ckvk/opennurbs
int ON_wString::Find( const char* s ) const
{
  int rc = -1;
  if ( s && s[0] && !IsEmpty() ) {
    const int s_count = (int)strlen(s); // the (int) is for 64 bit size_t conversion
    wchar_t* w = (wchar_t*)onmalloc( (s_count+2)*sizeof(w[0]) );
    c2w( s_count, s, s_count+1, w );
    const wchar_t* p;
    p = wcsstr( m_s, w );
    if ( p )
    {
      rc = ((int)(p-m_s)); // the (int) cast is for 64 bit compilers
    }
    onfree( w );
  }
  return rc;
}
コード例 #21
0
/**
 * Open file path given in the current encoding, using desired shared access.
 *
 * @param path file path
 * @param mode string specifying file opening mode
 * @param exclusive non-zero to prohibit write access to the file
 * @return file descriptor on success, NULL on error
 */
FILE* win_fopen_ex(const char* path, const char* mode, int exclusive)
{
	FILE* fd = 0;
	int i;
	wchar_t* wmode = utf8_to_wchar(mode);
	assert(wmode != NULL);

	/* try two code pages */
	for(i = 0; i < 2; i++) {
		wchar_t* wpath = c2w(path, i);
		if(wpath == NULL) continue;
		fd = _wfsopen(wpath, wmode, (exclusive ? _SH_DENYWR : _SH_DENYNO));
		free(wpath);
		if(fd || errno != ENOENT) break;
	}
	free(wmode);
	return fd;
}
コード例 #22
0
ファイル: TextureClass.cpp プロジェクト: denghc/danmugame
bool TextureClass::Initialize(ID3D11Device* device, char* filename)
{
	

	HRESULT result;
	// Load the texture in.
	WCHAR fn[200];
	c2w(fn, 200, filename);
	memcpy(m_textureFileName, filename, 200);


	result = D3DX11CreateShaderResourceViewFromFile(device, fn, NULL, NULL, &m_texture, NULL);
	if(FAILED(result))
	{
		return false;
	}
	
	return true;
}
コード例 #23
0
ファイル: perspective.cpp プロジェクト: fseraph/pbrt-v3
Float PerspectiveCamera::Pdf_We(const Interaction &p0,
                                const Vector3f &w) const {
    // Interpolate camera matrix and check if _w_ is forward-facing
    Transform c2w;
    CameraToWorld.Interpolate(p0.time, &c2w);
    Float cosTheta = Dot(w, c2w(Vector3f(0, 0, 1)));
    if (cosTheta <= 0) return 0;

    // Map direction _w_ onto the raster grid
    Point3f pFocus = p0.p + w / cosTheta * (lensRadius > 0 ? focalDistance : 1);
    Point3f pRaster = Inverse(RasterToCamera)(Inverse(c2w)(pFocus));

    // Return zero importance for out of bounds points
    Bounds2i sampleBounds = film->GetSampleBounds();
    if (pRaster.x < sampleBounds.pMin.x || pRaster.x >= sampleBounds.pMax.x ||
        pRaster.y < sampleBounds.pMin.y || pRaster.y >= sampleBounds.pMax.y)
        return 0;
    return 1 / (A * cosTheta * cosTheta * cosTheta);
}
コード例 #24
0
ファイル: common_func.c プロジェクト: SBasalaev/RHash
/**
 * Fill file information in the file_t structure.
 *
 * @param file the file information
 * @param use_lstat nonzero if lstat() shall be used
 * @return 0 on success, -1 on error
 */
int rsh_file_stat2(file_t* file, int use_lstat)
{
	struct rsh_stat_struct st;
	int res = -1;

#ifdef _WIN32
	int i;
	(void)use_lstat; /* ignore on windows */

	if(file->wpath) {
		free(file->wpath);
		file->wpath = NULL;
	}

	for(i = 0; i < 2; i++) {
		wchar_t* wpath = c2w(file->path, i);
		if(wpath == NULL) continue;
		res = clib_wstat(wpath, &st);
		if(res == 0 || errno != ENOENT) {
			file->wpath = wpath;
			file->size  = st.st_size;

			/* set correct filesize for large files under win32 */
			win32_set_filesize64(file->path, &file->size);
			break;
		}
		free(wpath);
	}
#else
	res = (use_lstat ? lstat(file->path, &st) :
		rsh_stat(file->path, &st));
	file->size  = st.st_size;
#endif /* _WIN32 */

	file->mtime = st.st_mtime;
	return res;
}
コード例 #25
0
ファイル: opennurbs_wstring.cpp プロジェクト: ckvk/opennurbs
int ON_wString::ReverseFind( char c ) const
{
  wchar_t w = c2w(c);
  return ReverseFind( w );
}
コード例 #26
0
ファイル: opennurbs_wstring.cpp プロジェクト: ckvk/opennurbs
int ON_wString::ReverseFind( unsigned char c ) const
{
  wchar_t w = c2w((char)c);
  return ReverseFind( w );
}
コード例 #27
0
ファイル: py.c プロジェクト: robertotang/pyq
K py(K f, K x, K lib)
{
    int argc; char **argv;
    char *error, *p, *buf;
    void *h;
    K r;
#ifdef PY3K
    char *oldloc;
#endif
    h = dlopen((const char *)kG(lib), RTLD_NOW|RTLD_GLOBAL);
    if (!h)
        R krr(dlerror());
    dlerror();    /* Clear any existing error */
    Py_Main = dlsym(h, "Py_Main");
    P((error = dlerror()),krr(error));
    P(xt, krr("argv type"));
        I m = 0;     /* buf length */
    DO(xn,
       K y;
       P((y = kK(x)[i])->t!=KC, krr("arg type"));
       m += y->n+1);
    argc = xn+1;
    argv = malloc(sizeof(char*) * argc);
    P(!argv, krr("memory"));
        buf = malloc(m);
    P(!buf,(free(argv),krr("memory")));
    argv[0] = f->s;
    p = buf;
    DO(xn,
       K y = kK(x)[i];
       argv[i+1] = memcpy(p, kG(y), y->n);
       p += y->n; *p++ = '\0');
#ifdef PY3K
    dlerror();    /* Clear any existing error */
#if PY3K < 35
    c2w = dlsym(h, "_Py_char2wchar");
#else
    c2w = dlsym(h, "Py_DecodeLocale");
#endif
    P((error = dlerror()),krr(error));
    dlerror();    /* Clear any existing error */
#if PY3K < 34
    PyMem_Free = dlsym(h, "PyMem_Free");
#else
    PyMem_Free = dlsym(h, "PyMem_RawFree");
#endif
    P((error = dlerror()),krr(error));
    wchar_t **wargv = malloc(sizeof(wchar_t*)*(argc+1));
    wchar_t **wargv_copy = malloc(sizeof(wchar_t*)*(argc+1));
    oldloc = strdup(setlocale(LC_ALL, NULL));
    setlocale(LC_ALL, "");
    DO(argc,P(!(wargv[i]=c2w(argv[i],NULL)),krr("decode")));
        memcpy(wargv_copy, wargv, sizeof(wchar_t*)*argc);
    setlocale(LC_ALL, oldloc);
    free(oldloc);
    wargv[argc] = wargv_copy[argc] = NULL;
    r = ki(Py_Main(argc, wargv));
    DO(argc,PyMem_Free(wargv_copy[i]));
    free(wargv_copy);
    free(wargv);
#else
    r = ki(Py_Main(argc, argv));
#endif
    dlclose(h);
    free(argv);
    free(buf);
    R r;
}