summaryrefslogtreecommitdiff
path: root/gl/tests/ftruncate.c
blob: ae1e85890c23956f2aab5a2362665599b8fdea5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* ftruncate emulations for native Windows.
   This file is in the public domain.  */

#include <config.h>

/* Specification.  */
#include <unistd.h>

#if HAVE_CHSIZE

# include <errno.h>
# include <io.h>

# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
#  include "msvc-inval.h"
static inline int
chsize_nothrow (int fd, long length)
{
  int result;

  TRY_MSVC_INVAL
    {
      result = chsize (fd, length);
    }
  CATCH_MSVC_INVAL
    {
      result = -1;
      errno = EBADF;
    }
  DONE_MSVC_INVAL;

  return result;
}
#  define chsize chsize_nothrow
# endif

int
ftruncate (int fd, off_t length)
{
  return chsize (fd, length);
}

#endif