Parcourir la source

fix confusion between _starpu_ftruncate and ftruncate by introducing _starpu_fftruncate which takes a FILE*

Samuel Thibault il y a 9 ans
Parent
commit
9095dde87f

+ 8 - 1
src/common/utils.c

@@ -164,8 +164,10 @@ char *_starpu_mktemp(const char *directory, int flags, int *fd)
 	/* fail */
 	if (*fd < 0)
 	{
+		int err = errno;
 		_STARPU_DISP("Could not create temporary file in directory '%s', mskostemp failed with error '%s'\n", directory, strerror(errno));
 		free(baseCpy);
+		errno = err;
 		return NULL;
 	}
 
@@ -233,7 +235,12 @@ void _starpu_rmtemp_many(char *path, int depth)
 	}
 }
 
-int _starpu_ftruncate(FILE *file, size_t length)
+int _starpu_ftruncate(int fd, size_t length)
+{
+	return ftruncate(fd, length);
+}
+
+int _starpu_fftruncate(FILE *file, size_t length)
 {
 	return ftruncate(fileno(file), length);
 }

+ 2 - 1
src/common/utils.h

@@ -129,7 +129,8 @@ 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, size_t length);
+int _starpu_fftruncate(FILE *file, size_t length);
+int _starpu_ftruncate(int fd, size_t length);
 int _starpu_frdlock(FILE *file);
 int _starpu_frdunlock(FILE *file);
 int _starpu_fwrlock(FILE *file);

+ 2 - 4
src/core/disk_ops/disk_stdio.c

@@ -135,7 +135,7 @@ static void *starpu_stdio_alloc(void *base, size_t size)
 	if (!baseCpy)
 		return NULL;
 
-	int val = ftruncate(id,size);
+	int val = _starpu_ftruncate(id,size);
 	/* fail */
 	if (val < 0)
 	{
@@ -289,16 +289,14 @@ static int starpu_stdio_full_write(void *base STARPU_ATTRIBUTE_UNUSED, void *obj
 {
 	struct starpu_stdio_obj *tmp = (struct starpu_stdio_obj *) obj;
 	FILE *f = tmp->file;
-	int fd;
 
 	if (!f)
 		f = _starpu_stdio_reopen(obj);
-	fd = fileno(f);
 
 	/* update file size to realise the next good full_read */
 	if(size != tmp->size)
 	{
-		int val = ftruncate(fd,size);
+		int val = _starpu_fftruncate(f,size);
 		STARPU_ASSERT(val == 0);
 
 		tmp->size = size;

+ 2 - 2
src/core/disk_ops/unistd/disk_unistd_global.c

@@ -127,7 +127,7 @@ void *starpu_unistd_global_alloc(struct starpu_unistd_global_obj *obj, void *bas
 		return NULL;
 	}
 
-	int val = ftruncate(id,size);
+	int val = _starpu_ftruncate(id,size);
 	/* fail */
 	if (val < 0)
 	{
@@ -351,7 +351,7 @@ int starpu_unistd_global_full_write(void *base STARPU_ATTRIBUTE_UNUSED, void *ob
 
 		if (fd < 0)
 			fd = _starpu_unistd_reopen(obj);
-		int val = ftruncate(fd,size);
+		int val = _starpu_ftruncate(fd,size);
 		if (tmp->descriptor < 0)
 			_starpu_unistd_reclose(fd);
 		STARPU_ASSERT(val == 0);

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

@@ -1124,7 +1124,7 @@ static void write_bus_latency_file_content(void)
 		STARPU_ABORT();
 	}
 	_starpu_fwrlock(f);
-	_starpu_ftruncate(f, 0);
+	_starpu_fftruncate(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, 0);
+	_starpu_fftruncate(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, 0);
+	_starpu_fftruncate(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, 0);
+	_starpu_fftruncate(f, 0);
 
 	fprintf(f,
 "<?xml version='1.0'?>\n"

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

@@ -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, 0);
+	_starpu_fftruncate(f, 0);
 	dump_model_file(f, model);
 	_starpu_fwrunlock(f);