- file->compiled = talloc_strdup(ctx, tempnam("/tmp", "ccanlint"));
- talloc_set_destructor(file->compiled, cleanup_testfile);
-
- return run_command(m, "cc " CFLAGS " %s -o %s %s %s %s",
- fail ? "-DFAIL" : "",
- file->compiled, file->name,
- obj_list(m, link_with_module), lib_list(m));
+ char *errmsg;
+
+ file->compiled = maybe_temp_file(ctx, "", keep, file->fullname);
+ errmsg = compile_and_link(ctx, file->fullname, ccan_dir,
+ obj_list(m, link_with_module),
+ fail ? "-DFAIL" : "",
+ lib_list(m), file->compiled);
+ if (errmsg) {
+ talloc_free(file->compiled);
+ return errmsg;
+ }
+ return NULL;