mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 22:31:12 +02:00
(truncate): Use "const char *" and "off_t" for parameters, per usual
definition of this function, rather than "char *" and "int". Use ftruncate instead of chsize. Check for error on final close.
This commit is contained in:
parent
f3dbe1aff3
commit
67227767f7
1 changed files with 19 additions and 5 deletions
|
@ -1422,18 +1422,32 @@ SCM_DEFINE (scm_seek, "seek", 3, 0, 0,
|
|||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
/* Mingw has ftruncate(), perhaps implemented above using chsize, but
|
||||
doesn't have the filename version truncate(), hence this code. */
|
||||
#if HAVE_FTRUNCATE && ! HAVE_TRUNCATE
|
||||
static int truncate (char *file, int length)
|
||||
static int
|
||||
truncate (const char *file, off_t length)
|
||||
{
|
||||
int ret = -1, fdes;
|
||||
if ((fdes = open (file, O_BINARY | O_WRONLY)) != -1)
|
||||
int ret, fdes;
|
||||
|
||||
fdes = open (file, O_BINARY | O_WRONLY);
|
||||
if (fdes == -1)
|
||||
return -1;
|
||||
|
||||
ret = ftruncate (fdes, length);
|
||||
if (ret == -1)
|
||||
{
|
||||
ret = chsize (fdes, length);
|
||||
int save_errno = errno;
|
||||
close (fdes);
|
||||
errno = save_errno;
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
|
||||
return close (fdes);
|
||||
}
|
||||
#endif /* HAVE_FTRUNCATE && ! HAVE_TRUNCATE */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue