mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 23:00:22 +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
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
#ifndef O_BINARY
|
||||||
|
#define O_BINARY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Mingw has ftruncate(), perhaps implemented above using chsize, but
|
/* Mingw has ftruncate(), perhaps implemented above using chsize, but
|
||||||
doesn't have the filename version truncate(), hence this code. */
|
doesn't have the filename version truncate(), hence this code. */
|
||||||
#if HAVE_FTRUNCATE && ! HAVE_TRUNCATE
|
#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;
|
int ret, fdes;
|
||||||
if ((fdes = open (file, O_BINARY | O_WRONLY)) != -1)
|
|
||||||
|
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);
|
close (fdes);
|
||||||
|
errno = save_errno;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
return close (fdes);
|
||||||
}
|
}
|
||||||
#endif /* HAVE_FTRUNCATE && ! HAVE_TRUNCATE */
|
#endif /* HAVE_FTRUNCATE && ! HAVE_TRUNCATE */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue