Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <v5mujo$3f10p$1@raubtier-asyl.eternal-september.org>
Deutsch   English   Français   Italiano  
<v5mujo$3f10p$1@raubtier-asyl.eternal-september.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: how copy file on linux?
Date: Fri, 28 Jun 2024 20:15:20 +0200
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <v5mujo$3f10p$1@raubtier-asyl.eternal-september.org>
References: <v5huk1$2anbd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 28 Jun 2024 20:15:20 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="f8388e8694381a01406bbb7a108535eb";
	logging-data="3638297"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX188v2ZzXx1crq0slAPiVU3o2LHWarAiV6I="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Pc4xNjP9Q6UsKyL0itfxoVBs28A=
Content-Language: de-DE
In-Reply-To: <v5huk1$2anbd$1@dont-email.me>
Bytes: 2607

I tried to implement that in C++. Unfortunately an error branch of the
code is taken. What Do I have to change ?

bool CopyFileA( char const *from, char const *to, bool overwrite )
{
	struct stat attrFrom, attrTo;
	if( stat( from, &attrFrom ) )
		return false;
	if( !overwrite && !stat( to, &attrTo ) && errno != ENOENT )
		return false;
	union ndi { char c; };
	vector<char> buf( attrFrom.st_size >= 0x100000 ? 0x100000 : 
attrFrom.st_size );
	int fromFile = open( from, O_RDONLY | O_NOATIME );
	if( !fromFile )
		return false;
	invoke_on_destruct closeFrom( [&] { close( fromFile ); } );
	int toFile = open( to, O_CREAT );
	if( !toFile )
		return false;
	invoke_on_destruct closeTo( [&] { close( toFile ); } );
	invoke_on_destruct delTo( [&] { unlink( to ); } );
	for( int64_t remaining = attrFrom.st_size; remaining > 0; remaining -= 
0x100000 )
	{
		size_t n = (size_t)(remaining >= 0x100000 ? 0x100000 : remaining);
		buf.resize( n );
		if( read( fromFile, buf.data(), n ) )
		{
			// this branch is taken
			cout << strerror( errno ) << endl;
			return false;
		}
		if( write( toFile, buf.data(), n ) )
			return false;
	}
	closeTo();
	utimbuf utb;
	utb.actime = attrFrom.st_atime;
	utb.modtime = attrFrom.st_mtime;
	if( utime( to, &utb ) )
		return false;
	if( chmod( to, attrFrom.st_mode ) )
		return false;
	if( chown( to, attrFrom.st_uid, attrFrom.st_gid ) && errno != EACCES )
		return false;
	delTo.disable();
	return to;
}

If everything works fine at last I'll make a C-rewrite.