🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #308590

Re: Opcje fopen

#308590
From: M.M.
Date: Sun, 22 May 2016 08:12
28 lines
2782 bytes
On Sunday, May 22, 2016 at 8:33:26 AM UTC+2, Borneq wrote:
> W dniu 22.05.2016 o 08:22, Borneq pisze:
> > Ale błąd bo OpenFile() chce podawać HFILE a nie HANDLE, natomiast
> > pozostałe funkcje chcą HANDLE.
> 
> powinno być
> HANDLE hFile = CreateFileA(path,GENERIC_WRITE, 
> 0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

Może to ze stacka będzie bardziej przenośne?

http://stackoverflow.com/questions/873454/how-to-truncate-a-file-in-c

[
If you want to preserve the previous contents of the file up to some length (a length bigger than zero, which other answers provide), then POSIX provides the truncate() and ftruncate() functions for the job.

#include <unistd.h>
int ftruncate(int fildes, off_t length);
int truncate(const char *path, off_t length);

The name indicates the primary purpose - shortening a file. But if the specified length is longer than the previous length, the file grows (zero padding) to the new size. Note that ftruncate() works on a file descriptor, not a FILE *; you could use:

if (ftruncate(fileno(fp), new_length) != 0) ...error handling...

However, you should be aware that mixing file stream (FILE *) and file descriptor (int) access to a single file is apt to lead to confusion — see the comments for some of the issues. This should be a last resort.

It is likely, though, that for your purposes, truncate on open is all you need, and for that, the options given by others will be sufficient.
]
Technical Details
Message-ID: <38fa676c-5d05-4d54-87a3-c7141f041e98@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!11no5580088qgt.0!news-out.google.com!k10ni2484igv.0!nntp.google.com!q6no213544igz.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
References: <nhpa0p$hiu$1@node1.news.atman.pl> <57403116$0$9698$426a74cc@news.free.fr> <nhpcfo$giu$1@node2.news.atman.pl> <nhrj79$qv6$1@node1.news.atman.pl> <nhrjrl$ri4$1@node1.news.atman.pl>

Show Full Headers
Complete Article Headers
X-Received: by 10.140.104.233 with SMTP id a96mr3832801qgf.15.1463904768708;        Sun, 22 May 2016 01:12:48 -0700 (PDT)
X-Received: by 10.50.90.5 with SMTP id bs5mr146170igb.5.1463904768660; Sun, 22 May 2016 01:12:48 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!11no5580088qgt.0!news-out.google.com!k10ni2484igv.0!nntp.google.com!q6no213544igz.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.c
Date: Sun, 22 May 2016 01:12:47 -0700 (PDT)
In-Reply-To: <nhrjrl$ri4$1@node1.news.atman.pl>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=178.37.232.66; posting-account=xjvq9QoAAAATMPC2X3btlHd_LkaJo_rj
NNTP-Posting-Host: 178.37.232.66
References: <nhpa0p$hiu$1@node1.news.atman.pl> <57403116$0$9698$426a74cc@news.free.fr> <nhpcfo$giu$1@node2.news.atman.pl> <nhrj79$qv6$1@node1.news.atman.pl> <nhrjrl$ri4$1@node1.news.atman.pl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <38fa676c-5d05-4d54-87a3-c7141f041e98@googlegroups.com>
Subject: Re: Opcje fopen
From: "M.M." <mmarszik@gmail.com>
Injection-Date: Sun, 22 May 2016 08:12:48 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit