announce-gen: use Digest::SHA when possible
[gnulib.git] / lib / ftruncate.c
1 /* ftruncate emulations for native Windows.
2    This file is in the public domain.  */
3
4 #include <config.h>
5
6 /* Specification.  */
7 #include <unistd.h>
8
9 #if HAVE_CHSIZE
10
11 # include <errno.h>
12 # include <io.h>
13
14 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
15 #  include "msvc-inval.h"
16 static inline int
17 chsize_nothrow (int fd, long length)
18 {
19   int result;
20
21   TRY_MSVC_INVAL
22     {
23       result = chsize (fd, length);
24     }
25   CATCH_MSVC_INVAL
26     {
27       result = -1;
28       errno = EBADF;
29     }
30   DONE_MSVC_INVAL;
31
32   return result;
33 }
34 #  define chsize chsize_nothrow
35 # endif
36
37 int
38 ftruncate (int fd, off_t length)
39 {
40   return chsize (fd, length);
41 }
42
43 #endif