Article View: pl.comp.lang.c
Article #308591Re: Opcje fopen
From: Mateusz Viste
Date: Sun, 22 May 2016 17:53
Date: Sun, 22 May 2016 17:53
34 lines
1985 bytes
1985 bytes
On 22/05/2016 19:17, AK wrote:
> #include <stdio.h>
>
> char buffer[] = "xyz";
>
> int main()
> {
> FILE* f;
> f = fopen("z.txt", "rb+");
> fseek(f, 10, SEEK_SET);
> fwrite(buffer, sizeof(buffer[0]), sizeof(buffer), f);
> fflush(f);
> chsize(fileno(f), ftell(f) - 1);
> fclose(f);
> return 0;
> }
Niestety, podany kod się nie kompiluje.
mateusz:~> gcc ak.c -o ak
/tmp/cctGhGNg.o: In function `main':
t.c:(.text+0x80): undefined reference to `chsize'
collect2: error: ld returned 1 exit status
mateusz:~> uname -a
Linux 4.1.20-11 SMP Fri Mar 18 14:42:07 UTC 2016 x86_64 GNU/Linux
Widzę jednak, że na Windowsach coś takiego istnieje:
int _chsize(int fd, long size);
Ale OP pytał o coś co docelowa będzie działać na Linuksie. Do tego drugi
problem: mowa była o wielo-gigabajtowym pliku, a funkcja którą
proponujesz jest ograniczona do 2G-1.
Mateusz
Technical Details
Message-ID:
<5741f219$0$4573$426a34cc@news.free.fr>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!cleanfeed4-a.proxad.net!nnrp3-1.free.fr!not-for-mailReferences:
<nhpa0p$hiu$1@node1.news.atman.pl> <57403116$0$9698$426a74cc@news.free.fr> <nhpcfo$giu$1@node2.news.atman.pl> <nhspiv$2mt$1@node1.news.atman.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!cleanfeed4-a.proxad.net!nnrp3-1.free.fr!not-for-mail Subject: Re: Opcje fopen Newsgroups: pl.comp.lang.c References: <nhpa0p$hiu$1@node1.news.atman.pl> <57403116$0$9698$426a74cc@news.free.fr> <nhpcfo$giu$1@node2.news.atman.pl> <nhspiv$2mt$1@node1.news.atman.pl> From: Mateusz Viste <mateusz.viste@localhost> Date: Sun, 22 May 2016 19:53:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <nhspiv$2mt$1@node1.news.atman.pl> Lines: 34 Message-ID: <5741f219$0$4573$426a34cc@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 22 May 2016 19:53:29 CEST NNTP-Posting-Host: 62.147.137.104 X-Trace: 1463939609 news-4.free.fr 4573 62.147.137.104:55669 X-Complaints-To: abuse@proxad.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit