[easytag/wip/core-refactoring: 3/7] Use _chsize() on Windows
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/core-refactoring: 3/7] Use _chsize() on Windows
- Date: Tue, 9 Feb 2016 20:05:09 +0000 (UTC)
commit a733b5d9ecbe90a6b3c10ae1fbfc491456ba2a26
Author: David King <amigadave amigadave com>
Date: Tue Jan 26 11:50:21 2016 +0000
Use _chsize() on Windows
Avoid the internal ftruncate() wrapper, which was only used in a single
location.
configure.ac | 5 -----
src/tags/libapetag/apetaglib.c | 19 ++++++++++++++++---
src/win32/win32dep.c | 23 -----------------------
src/win32/win32dep.h | 11 +++--------
4 files changed, 19 insertions(+), 39 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1dae65c..b8e13aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -357,11 +357,6 @@ AX_IS_RELEASE([git-directory])
AX_COMPILER_FLAGS([WARN_CFLAGS], [WARN_LDFLAGS],
[$ax_is_release])
-dnl -------------------------------
-dnl Checks for library functions.
-dnl -------------------------------
-AC_CHECK_FUNCS([truncate])
-
GLIB_GSETTINGS
AC_CONFIG_FILES([ Makefile
diff --git a/src/tags/libapetag/apetaglib.c b/src/tags/libapetag/apetaglib.c
index 17074fc..8b94e48 100644
--- a/src/tags/libapetag/apetaglib.c
+++ b/src/tags/libapetag/apetaglib.c
@@ -1017,6 +1017,7 @@ apetag_save (const char *filename, apetag *mem_cnt, int flag)
size_t fileSize;
size_t newFileSize;
size_t writedBytes;
+ int fd;
fseek (fp, 0, SEEK_END);
fileSize = ftell (fp);
@@ -1037,12 +1038,24 @@ apetag_save (const char *filename, apetag *mem_cnt, int flag)
newFileSize = (fileSize - skipBytes);
}
fflush (fp);
- fclose (fp);
- /* ftruncate don't work */
- if (truncate (filename, newFileSize) == -1)
+
+ if ((fd = fileno (fp)) == -1)
+ {
+ PRINT_ERR ("FATAL_ERROR->libapetag->apetag_save::fileno [file not truncated]");
+ fclose (fp);
+ return ATL_FWRITE;
+ }
+
+#ifdef G_OS_WIN32
+ if (_chsize (fd, newFileSize) == -1)
+#else
+ if (ftruncate (fd, newFileSize) == -1)
+#endif
{
PRINT_ERR ("FATAL_ERROR->libapetag->apetag_save::fwrite [file not truncated]");
}
+
+ fclose (fp);
} else { /* !!SAVE_FAKE_SAVE */
libapetag_print_mem_cnt (mem_cnt);
}
diff --git a/src/win32/win32dep.c b/src/win32/win32dep.c
index 3e96dd7..4ee529d 100644
--- a/src/win32/win32dep.c
+++ b/src/win32/win32dep.c
@@ -108,27 +108,4 @@ weasytag_locale_dir (void)
return locale_dir;
}
-/* Miscellaneous */
-#ifndef HAVE_TRUNCATE
-gint
-et_w32_truncate (const gchar *path, off_t length)
-{
- HANDLE h;
- gint ret;
-
- h = CreateFile (path, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
-
- if (h == INVALID_HANDLE_VALUE)
- {
- /* errno = map_errno (GetLastError ()); */
- return -1;
- }
-
- ret = chsize ((gint)h, length);
- CloseHandle (h);
-
- return ret;
-}
-#endif /* !HAVE_TRUNCATE */
-
#endif /* G_OS_WIN32 */
diff --git a/src/win32/win32dep.h b/src/win32/win32dep.h
index a2cd069..4ca2895 100644
--- a/src/win32/win32dep.h
+++ b/src/win32/win32dep.h
@@ -20,8 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
-#ifndef _WIN32DEP_H_
-#define _WIN32DEP_H_
+#ifndef ET_WIN32DEP_H_
+#define ET_WIN32DEP_H_
#include <glib.h> /* Needed for G_OS_WIN32. */
@@ -48,11 +48,6 @@ G_BEGIN_DECLS
/* Determine EasyTAG paths */
const gchar * weasytag_locale_dir (void);
-#ifndef HAVE_TRUNCATE
-#define et_w32_truncate truncate
-extern gint et_w32_truncate (const gchar *path, off_t length);
-#endif /* !HAVE_TRUNCATE */
-
/*
* MACROS
*/
@@ -67,4 +62,4 @@ G_END_DECLS
#endif /* G_OS_WIN32 */
-#endif /* _WIN32DEP_H_ */
+#endif /* ET_WIN32DEP_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]