]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool: move tool_ftruncate64 to tool_util.c
authorDaniel Stenberg <daniel@haxx.se>
Wed, 24 Apr 2024 08:35:45 +0000 (10:35 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 25 Apr 2024 07:20:38 +0000 (09:20 +0200)
... and the prototype to tool_setup.h, to make them both available more
widely and accurately.

Follow-up to 00bef95946d3511

Fixes #13458
Closes #13459

src/tool_cb_see.c
src/tool_cb_see.h
src/tool_setup.h
src/tool_util.c

index bce57bb281fe9381c4953f341cf94684da692088..643a38cd9a427370f66ef0a8684b086078d3c1bf 100644 (file)
@@ -90,32 +90,3 @@ int tool_seek_cb(void *userdata, curl_off_t offset, int whence)
 
   return CURL_SEEKFUNC_OK;
 }
-
-#ifdef USE_TOOL_FTRUNCATE
-
-#ifdef _WIN32_WCE
-/* 64-bit lseek-like function unavailable */
-#  undef _lseeki64
-#  define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
-#  undef _get_osfhandle
-#  define _get_osfhandle(fd) (fd)
-#endif
-
-/*
- * Truncate a file handle at a 64-bit position 'where'.
- */
-
-int tool_ftruncate64(int fd, curl_off_t where)
-{
-  intptr_t handle = _get_osfhandle(fd);
-
-  if(_lseeki64(fd, where, SEEK_SET) < 0)
-    return -1;
-
-  if(!SetEndOfFile((HANDLE)handle))
-    return -1;
-
-  return 0;
-}
-
-#endif /* USE_TOOL_FTRUNCATE */
index b5d7bf985ecd77f44de8a2784251c4bac2fb365e..e7b30a765dc203b7af842e83156c1229e53f8a85 100644 (file)
  ***************************************************************************/
 #include "tool_setup.h"
 
-#if defined(_WIN32) && !defined(HAVE_FTRUNCATE)
-
-int tool_ftruncate64(int fd, curl_off_t where);
-
-#undef  ftruncate
-#define ftruncate(fd,where) tool_ftruncate64(fd,where)
-
-#define HAVE_FTRUNCATE 1
-#define USE_TOOL_FTRUNCATE 1
-
-#endif /* _WIN32 && ! HAVE_FTRUNCATE */
-
 /*
 ** callback for CURLOPT_SEEKFUNCTION
 */
index c69859ea64c22536d9b952c1e45d7cb0f059ba84..07cba7da2e8f5cc1dafbcd8bf4f158da8f6509a2 100644 (file)
@@ -74,4 +74,17 @@ extern bool tool_isVistaOrGreater;
 extern bool tool_term_has_bold;
 #endif
 
+#if defined(_WIN32) && !defined(HAVE_FTRUNCATE)
+
+int tool_ftruncate64(int fd, curl_off_t where);
+
+#undef  ftruncate
+#define ftruncate(fd,where) tool_ftruncate64(fd,where)
+
+#define HAVE_FTRUNCATE 1
+#define USE_TOOL_FTRUNCATE 1
+
+#endif /* _WIN32 && ! HAVE_FTRUNCATE */
+
+
 #endif /* HEADER_CURL_TOOL_SETUP_H */
index 812a689d03dcc8d182e007bfdf6f8d7b8e349589..b5a6b40d12d859a7594ce86e1d81a3377b969775 100644 (file)
@@ -159,3 +159,32 @@ int struplocompare4sort(const void *p1, const void *p2)
 {
   return struplocompare(* (char * const *) p1, * (char * const *) p2);
 }
+
+#ifdef USE_TOOL_FTRUNCATE
+
+#ifdef _WIN32_WCE
+/* 64-bit lseek-like function unavailable */
+#  undef _lseeki64
+#  define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
+#  undef _get_osfhandle
+#  define _get_osfhandle(fd) (fd)
+#endif
+
+/*
+ * Truncate a file handle at a 64-bit position 'where'.
+ */
+
+int tool_ftruncate64(int fd, curl_off_t where)
+{
+  intptr_t handle = _get_osfhandle(fd);
+
+  if(_lseeki64(fd, where, SEEK_SET) < 0)
+    return -1;
+
+  if(!SetEndOfFile((HANDLE)handle))
+    return -1;
+
+  return 0;
+}
+
+#endif /* USE_TOOL_FTRUNCATE */