Parcourir la source

factorize ftruncate portability to windows

Samuel Thibault il y a 9 ans
Parent
commit
bdfcc6404e

+ 2 - 2
src/common/utils.c

@@ -233,9 +233,9 @@ void _starpu_rmtemp_many(char *path, int depth)
 	}
 }
 
-int _starpu_ftruncate(FILE *file)
+int _starpu_ftruncate(FILE *file, size_t length)
 {
-	return ftruncate(fileno(file), 0);
+	return ftruncate(fileno(file), length);
 }
 
 int _starpu_frdlock(FILE *file)

+ 1 - 1
src/common/utils.h

@@ -129,7 +129,7 @@ char *_starpu_mktemp(const char *directory, int flags, int *fd);
  * creating a lot of temporary files to be stored in the same place */
 char *_starpu_mktemp_many(const char *directory, int depth, int flags, int *fd);
 void _starpu_rmtemp_many(char *path, int depth);
-int _starpu_ftruncate(FILE *file);
+int _starpu_ftruncate(FILE *file, size_t length);
 int _starpu_frdlock(FILE *file);
 int _starpu_frdunlock(FILE *file);
 int _starpu_fwrlock(FILE *file);

+ 0 - 12
src/core/disk_ops/disk_stdio.c

@@ -135,19 +135,11 @@ static void *starpu_stdio_alloc(void *base, size_t size)
 	if (!baseCpy)
 		return NULL;
 
-#ifdef STARPU_HAVE_WINDOWS
-	int val = _chsize(id, size);
-#else
 	int val = ftruncate(id,size);
-#endif
 	/* fail */
 	if (val < 0)
 	{
-#ifdef STARPU_HAVE_WINDOWS
-		_STARPU_DISP("Could not truncate file, _chsize failed with error '%s'\n", strerror(errno));
-#else
 		_STARPU_DISP("Could not truncate file, ftruncate failed with error '%s'\n", strerror(errno));
-#endif
 		close(id);
 		unlink(baseCpy);
 		free(baseCpy);
@@ -306,11 +298,7 @@ static int starpu_stdio_full_write(void *base STARPU_ATTRIBUTE_UNUSED, void *obj
 	/* update file size to realise the next good full_read */
 	if(size != tmp->size)
 	{
-#ifdef STARPU_HAVE_WINDOWS
-		int val = _chsize(fd, size);
-#else
 		int val = ftruncate(fd,size);
-#endif
 		STARPU_ASSERT(val == 0);
 
 		tmp->size = size;

+ 0 - 12
src/core/disk_ops/unistd/disk_unistd_global.c

@@ -127,19 +127,11 @@ void *starpu_unistd_global_alloc(struct starpu_unistd_global_obj *obj, void *bas
 		return NULL;
 	}
 
-#ifdef STARPU_HAVE_WINDOWS
-	int val = _chsize(id, size);
-#else
 	int val = ftruncate(id,size);
-#endif
 	/* fail */
 	if (val < 0)
 	{
-#ifdef STARPU_HAVE_WINDOWS
-		_STARPU_DISP("Could not truncate file, _chsize failed with error '%s'\n", strerror(errno));
-#else
 		_STARPU_DISP("Could not truncate file, ftruncate failed with error '%s'\n", strerror(errno));
-#endif
 		close(id);
 		unlink(baseCpy);
 		free(baseCpy);
@@ -359,11 +351,7 @@ int starpu_unistd_global_full_write(void *base STARPU_ATTRIBUTE_UNUSED, void *ob
 
 		if (fd < 0)
 			fd = _starpu_unistd_reopen(obj);
-#ifdef STARPU_HAVE_WINDOWS
-		int val = _chsize(fd, size);
-#else
 		int val = ftruncate(fd,size);
-#endif
 		if (tmp->descriptor < 0)
 			_starpu_unistd_reclose(fd);
 		STARPU_ASSERT(val == 0);

+ 5 - 5
src/core/perfmodel/perfmodel_bus.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2015  Université de Bordeaux
+ * Copyright (C) 2009-2016  Université de Bordeaux
  * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016  CNRS
  * Copyright (C) 2013 Corentin Salingue
  *
@@ -1124,7 +1124,7 @@ static void write_bus_latency_file_content(void)
 		STARPU_ABORT();
 	}
 	_starpu_fwrlock(f);
-	_starpu_ftruncate(f);
+	_starpu_ftruncate(f, 0);
 
 	fprintf(f, "# ");
 	for (dst = 0; dst < STARPU_MAXNODES; dst++)
@@ -1341,7 +1341,7 @@ static void write_bus_bandwidth_file_content(void)
 	STARPU_ASSERT(f);
 
 	_starpu_fwrlock(f);
-	_starpu_ftruncate(f);
+	_starpu_ftruncate(f, 0);
 
 	fprintf(f, "# ");
 	for (dst = 0; dst < STARPU_MAXNODES; dst++)
@@ -1650,7 +1650,7 @@ static void write_bus_config_file_content(void)
         f = fopen(path, "w+");
 	STARPU_ASSERT(f);
 	_starpu_fwrlock(f);
-	_starpu_ftruncate(f);
+	_starpu_ftruncate(f, 0);
 
         fprintf(f, "# Current configuration\n");
         fprintf(f, "%u # Number of CPUs\n", ncpus);
@@ -2119,7 +2119,7 @@ static void write_bus_platform_file_content(void)
 		STARPU_ABORT();
 	}
 	_starpu_fwrlock(f);
-	_starpu_ftruncate(f);
+	_starpu_ftruncate(f, 0);
 
 	fprintf(f,
 "<?xml version='1.0'?>\n"

+ 2 - 2
src/core/perfmodel/perfmodel_history.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2015  Université de Bordeaux
+ * Copyright (C) 2009-2016  Université de Bordeaux
  * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  *
@@ -772,7 +772,7 @@ static void save_history_based_model(struct starpu_perfmodel *model)
 	STARPU_ASSERT_MSG(f, "Could not save performance model %s\n", path);
 
 	_starpu_fwrlock(f);
-	_starpu_ftruncate(f);
+	_starpu_ftruncate(f, 0);
 	dump_model_file(f, model);
 	_starpu_fwrunlock(f);