Deutsch English Français Italiano |
<v5nfh0$3i4n8$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Malcolm McLean <malcolm.arthur.mclean@gmail.com> Newsgroups: comp.lang.c Subject: Re: how copy file on linux? Date: Sat, 29 Jun 2024 00:04:00 +0100 Organization: A noiseless patient Spider Lines: 35 Message-ID: <v5nfh0$3i4n8$1@dont-email.me> References: <v5huk1$2anbd$1@dont-email.me> <v5mujo$3f10p$1@raubtier-asyl.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 29 Jun 2024 01:04:00 +0200 (CEST) Injection-Info: dont-email.me; posting-host="15fbe87ffc9d5dbfd6651f6740cf6176"; logging-data="3740392"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tAaagx0nBzw6yWV1hxaSMNIieX83rI/s=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:kJ4UXOedcr/oTpOyEOmLGAiPolU= In-Reply-To: <v5mujo$3f10p$1@raubtier-asyl.eternal-september.org> Content-Language: en-GB Bytes: 2439 On 28/06/2024 19:15, Bonita Montero wrote: > 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; > } So it claims the file opens, then won't read it? Check the call. Is 0 the success return? Then I must admit I'm stumped. "to" doesn't alias "from" I suppose? I'd also wonder if somehow the C++ compiler has invoked the on destruct code, and closed the file. -- Check out my hobby project. http://malcolmmclean.github.io/babyxrc