Quellcode durchsuchen

harmonize identical code

Samuel Thibault vor 9 Jahren
Ursprung
Commit
dcde45156c
2 geänderte Dateien mit 7 neuen und 9 gelöschten Zeilen
  1. 2 2
      src/core/disk_ops/disk_stdio.c
  2. 5 7
      src/core/disk_ops/unistd/disk_unistd_global.c

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

@@ -55,7 +55,7 @@ static void *starpu_stdio_alloc(void *base, size_t size)
 	int id = -1;
 
 	/* create template for mkstemp */
-	char *tmp = "STARPU_XXXXXX";
+	const char *tmp = "STARPU_XXXXXX";
 	char *baseCpy = malloc(strlen(base)+1+strlen(tmp)+1);
 	STARPU_ASSERT(baseCpy != NULL);
 
@@ -68,8 +68,8 @@ static void *starpu_stdio_alloc(void *base, size_t size)
         id = open(baseCpy, O_RDWR | O_BINARY);
 #else
 	id = mkstemp(baseCpy);
-
 #endif
+
 	/* fail */
 	if (id < 0)
 	{

+ 5 - 7
src/core/disk_ops/unistd/disk_unistd_global.c

@@ -56,19 +56,17 @@
 void *starpu_unistd_global_alloc(struct starpu_unistd_global_obj *obj, void *base, size_t size)
 {
 	int id = -1;
-	const char *template = "STARPU_XXXXXX";
 
 	/* create template for mkstemp */
-	unsigned int sizeBase = strlen(base) + 1 + strlen(template)+1;
-
-	char *baseCpy = malloc(sizeBase*sizeof(char));
+	const char *tmp = "STARPU_XXXXXX";
+	char *baseCpy = malloc(strlen(base)+1+strlen(tmp)+1);
 	STARPU_ASSERT(baseCpy != NULL);
 
 	strcpy(baseCpy, (char *) base);
 	strcat(baseCpy,"/");
-	strcat(baseCpy,template);
+	strcat(baseCpy,tmp);
+
 #if defined(STARPU_HAVE_WINDOWS)
-	/* size in windows is a multiple of char */
 	_mktemp(baseCpy);
 	id = open(baseCpy, obj->flags);
 #elif defined (HAVE_MKOSTEMP)
@@ -82,8 +80,8 @@ void *starpu_unistd_global_alloc(struct starpu_unistd_global_obj *obj, void *bas
 	if (id < 0)
 	{
 		_STARPU_DISP("Could not create temporary file in directory '%s', mskostemp failed with error '%s'\n", (char*)base, strerror(errno));
-		free(baseCpy);
 		free(obj);
+		free(baseCpy);
 		return NULL;
 	}